HTML,CSS,PHP,ワードプレスカスタマイズ 技術情報資料

特定カテゴリーのリスト

<?php
$posts = get_posts('category=カテゴリー番号&numberposts=0');
global $post;
?>
<h2><?php echo get_the_category_by_ID(カテゴリー番号) ?></h2>
<ul>
<?php if($posts): foreach($posts as $post): setup_postdata($post); ?>
<li><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; else : ?>
<li>Not Found</li>
<?php endif;?>
</ul>
<?php wp_reset_postdata(); ?>
nbsp;
分解するとだね
<?php
$posts = get_posts('category=カテゴリー番号&numberposts=0');
global $post;
?>
<h2><?php echo get_the_category_by_ID(カテゴリー番号) ?></h2>
<ul>
<?php
if($posts){
    foreach($posts as $post){
        setup_postdata($post);
?>
            <!-- post body -->
            <li>
                <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">
                <?php the_title(); ?></a>
            </li>
            <!--/post body -->
<?php     
    } 
}else{
?> 
    <li>Not Found</li>
<?php
}
?>
</ul>
<?php wp_reset_postdata(); ?>

スポンサーリンク

関連記事

スポンサーリンク

カテゴリー