Lightningテーマ archive.php 改造記録@ワードプレス教室

WP-Tilesプラグイン埋め込み(do_shortcode)

<?php get_header(); ?>
/*2018.9.13*/
<?php get_template_part( ‘child’,’module_pageTit’ ); ?>
<?php get_template_part( ‘module_panList’ ); ?>

<div class=”section siteContent”>
<div class=”container”>
<div class=”row”>

<div class=”col-md-8 mainSection” id=”main” role=”main”>
<!–2018/8/6 追加–>

<?php
/*検索対象になったカテゴリを取得*/
$categry_select = explode(‘/’, $_SERVER[“REQUEST_URI”]);

if ($categry_select[1]==”category”)
{
/*カスタムカテゴリではない*/
/*wp-tilesを動かして表示する*/
echo do_shortcode(‘[wp-tiles category=”‘ .$categry_select[2] .'”]’ );
}else if($categry_select[1]==”mansion” or $categry_select[1]==”kodate”){
/*カスタムカテゴリの場合*/

/*変数を初期化*/
$home_type='<div class=”home_type”>お住まいタイプ:’;
$i=0;
$tax_term=””;
$category_list_html = ‘<ol class=”breadcrumb”>’;

/*お住まいタイプを確認*/
if($categry_select[1]==”mansion”) {$home_type=$home_type.”マンション”;}
elseif($categry_select[1]==”kodate”) {$home_type=$home_type.”戸建て”;}
$home_type=$home_type.'</div>’;

/*タームを取得*/
$tax_term_string = explode(‘,’, $categry_select[2]);

/*タームが存在する間、shortcodeのプロパティと選択したカテゴリリストを作成*/
while($tax_term_string[$i]!=””){
/*最初のタームはそのまま格納*/
if ($i == 0){
$tax_term='”‘.$tax_term_string[$i];
}else{
/*最初ではない場合はスペースとカンマをいれる*/
$tax_term=$tax_term.’, ‘.$tax_term_string[$i];
}

/*選択したカテゴリをリスト作成*/
$args=array(
‘orderby’ => ‘name’,
‘order’ => ‘ASC’,
‘taxonomy’ => $categry_select[1] );
$categories=get_categories($args);
foreach($categories as $category) {
// echo “カテゴリスラッグ”.$category->slug.$tax_term_string[$i] .”<br>”;
if($category->slug ==$tax_term_string[$i]){
// echo “一覧のスラッグ”.$category->slug .”と現在のスラッグ”.$tax_term_string[$i].”<br>”;
$category_list_html=$category_list_html.'<li><a href=”‘ . get_category_link( $category->term_id ) . ‘” title=”‘ . sprintf( __( “View all posts in %s” ), $category->name ) . ‘” ‘ . ‘>’ . $category->name.'</a> </li> ‘;
}
}

$i=$i+1;
}
/*末尾にダブルコーテーションを追加*/
$tax_term=$tax_term.'”‘ ;
$category_list_html=$category_list_html.”</ol>”;

/*お住まいタイプを表示する*/
echo $home_type;

/*選択したカテゴリを表示する*/
echo $category_list_html;

/*wp-tilesを動かして表示する*/
echo do_shortcode(‘[wp-tiles taxonomy=”‘.$categry_select[1].'” tax_term=’.$tax_term.’]’ );

}else{
/*検索結果画面ではない場合は既存の動き*/
?>

<!–2018/8/6 追加–>

<?php

/*——————————————-*/
/* Archive title
/*——————————————-*/
$page_for_posts = lightning_get_page_for_posts();
// Use post top page( Archive title wrap to div )
if ( $page_for_posts[‘post_top_use’] || get_post_type() != ‘post’ ) {
if ( is_year() || is_month() || is_day() || is_tag() || is_author() || is_tax() || is_category() ) {
$archiveTitle = get_the_archive_title();
$archiveTitle_html = ‘<header class=”archive-header”><h1>’ . $archiveTitle . ‘</h1></header>’;
echo apply_filters( ‘lightning_mainSection_archiveTitle’, $archiveTitle_html );
}
}

/*——————————————-*/
/* Archive description
/*——————————————-*/
if ( is_category() || is_tax() || is_tag() ) {
$category_description = term_description();
$page = get_query_var( ‘paged’, 0 );
if ( ! empty( $category_description ) && $page == 0 ) {
$archiveDescription_html = ‘<div class=”archive-meta”>’ . $category_description . ‘</div>’;
echo apply_filters( ‘lightning_mainSection_archiveDescription’, $archiveDescription_html );
}
}

$postType = lightning_get_post_type();

do_action( ‘lightning_loop_before’ );
?>

<div class=”postList”>

<?php if ( have_posts() ) : ?>

<?php if ( apply_filters( ‘is_lightning_extend_loop’, false ) ) : ?>

<?php do_action( ‘lightning_extend_loop’ ); ?>

<?php elseif ( file_exists( get_stylesheet_directory() . ‘/module_loop_’ . $postType[‘slug’] . ‘.php’ ) && $postType != ‘post’ ) : ?>

<?php
while ( have_posts() ) :
the_post();
?>
<?php get_template_part( ‘module_loop_’ . $postType[‘slug’] ); ?>
<?php endwhile; ?>

<?php else : ?>

<?php
while ( have_posts() ) :
the_post();
?&gt;
<?php get_template_part( ‘module_loop_post’ ); ?>
<?php endwhile; ?>

<?php endif; // loop() ?>

<?php
the_posts_pagination(
array(
‘mid_size’ => 1,
‘prev_text’ => ‘«’,
‘next_text’ => ‘»’,
‘type’ => ‘list’,
‘before_page_number’ => ‘<span class=”meta-nav screen-reader-text”>’ . __( ‘Page’, ‘lightning’ ) . ‘ </span>’,
)
);
?>

<?php else : // hove_posts() ?>

<div class=”well”><p><?php _e( ‘No posts.’, ‘lightning’ ); ?></p></div>

<?php endif; // have_post() ?>

</div><!– [ /.postList ] –>

<?php do_action( ‘lightning_loop_after’ ); ?>

<!–2018/8/6 追加–>
<!-if文終わり–>
<?php } ?>
<!–2018/8/6 追加–>

</div><!– [ /.mainSection ] –>

<div class=”col-md-3 col-md-offset-1 subSection sideSection”>
<?php get_sidebar( get_post_type() ); ?>
</div><!– [ /.subSection ] –>

</div><!– [ /.row ] –>
</div><!– [ /.container ] –>
</div><!– [ /.siteContent ] –>
<?php get_footer(); ?>

About the author: 横浜WordPressスクール 鎌田裕二