メニュー 閉じる

カテゴリー一覧ページをカテゴリーごとに作成

「archive.php」にカテゴリーごとの分岐を記述

<?php
if (is_category('topics_news')) {
include(TEMPLATEPATH . '/archive-infom.php');
} elseif(is_category('anime_works')){
include(TEMPLATEPATH . '/archive-anime_works.php');
}else {
include(TEMPLATEPATH . '/archive-purchase_results.php');
}
?>

カテゴリー一覧ページの例(archive-anime_works.php

<?php
get_header(); ?>

<div class="bg_fles02">
<div class="content-inner">
<section>

<h2 class="h2_wppur box_c mt90">買取品目</h2>
<h3 class="h3_first box_c">こちらに掲載の無いアイテムも<br />お気軽にお問い合わせください!</h3>

<div class="purchase_record">

<?php
$wp_query = new WP_Query();
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$my_posts = array(
'post_type' => 'post',
'category_name' => 'anime_works', //スラッグ
'posts_per_page'=> '12',
'paged' => $paged,
'orderby' => 'date', // 表示順の基準
    'order' => 'ASC' // 昇順・降順asc DESC
);

$wp_query->query( $my_posts );
if( $wp_query->have_posts() ): while( $wp_query->have_posts() ) : $wp_query->the_post(); 
$pur_price_title = post_custom('買取価格品目名');
$metk_price = post_custom('METK価格');
$tking_price = post_custom('T-KING価格');
$product_condition = post_custom('買取金額');
$gazou = wp_get_attachment_image_src(post_custom('作品別画像'),'full' );
?>

<div class="purchase_record_item">
<a href="<?php the_permalink(); ?>">

<div class="purchase_record_item_r">
<img class="purchaselist_thumbnail150" src="<?php echo $gazou[0]; ?>" alt="<?php the_title(); ?>;" />
</div>

<div class="purchase_record_item_l">
<div class="purchase_record_name">
<?php
/* 通常のタイトル表示はこちら
the_title();
*/

//74文字でまるめて表示する
if(mb_strlen($post->post_title)>74) {
    $pur_price_title= mb_substr($post->post_title,0,74) ;
    echo $pur_price_title . '...';
    } else {
    echo $post->post_title;
    }
?>
</div>
/div>
</a>
</div>
<?php endwhile; endif;//ループ終わり ?>
</div> 

 </section>
 </div> 
 </div> 
 
 
<!-- pegenation -->
<div class="pagination">
<?php
$para="#fff";
    $big = 9999999999;
    $arg = array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'current' => max( 1, get_query_var('paged') ),
        'total' => $wp_query->max_num_pages,
        'type'    => 'list',
'add_fragment'    => '#topianchor'//URLにアンカー用ハッシュタグを付与
    );
    echo paginate_links($arg);
?>
</div>

<div class="cate_list">
<ul>
<?php
    $cats = get_categories(array(
        'child_of' => '3459',//※特定親のカテゴリーID
        'title_li' => '',//見出しをなしに
        'orderby' => 'ID',//ソート規則
    ));

foreach($cats as $category) :
 
$cat_id = $category->cat_ID;
$post_id = 'category_'.$cat_id; 


$slugname = $category->slug;//子カテゴリーのスラッグ名を取得(URLの末尾につける)


$catimg = get_field('category_image',$post_id);
$img = wp_get_attachment_image_src($catimg, 'full');
?>
<li>


<!-- 子カテゴリーシンクは手書きのURLの後ろに「$slugname;」を繋げる -->
<a href="/archives/category/leal-mccoys/<?php echo $slugname;?>">
<div class="cat_img"><img src="<?php echo $img[0]; ?>" alt="<?php echo $category->cat_name; ?>" /></div>
<span><?php echo $category->cat_name; ?></span>
</a>
</li>
<?php endforeach; ?>
</ul>

</div>


<?php
get_footer();