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

ワードプレス 特定カテゴリーデータの表示

<!-- これはタグの有無で処理。カテゴリーにするなら[cat=カテゴリーID] -->
<?php if (have_posts()) : ?>
<?php query_posts("tag=no1&showposts=1"); ?>
<!-- 投稿ループ -->
<?php while (have_posts()) : the_post(); ?>

<div class="item-img"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a></div>
<div class="item-date"><?php the_time(__('Y-m-d')) ?></div>
<div class="item-title" id="post-<?php the_ID(); ?>"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>

<?php endwhile; ?>
<!-- / 投稿ループ -->

<!-- 投稿がない場合 -->
<?php else: ?> 
<p>No Post.</p>
<?php endif; ?>
<!-- / 投稿がない場合 -->
※ポストの順番を変えるプラグインとか使ってるときには注意が必要。そいつが維持張って順番を固定にしてしまってることがある。
 
※並び替え orederby=name&order=”ASC” (アセンディング 小->大) とか orederby=name&order=”DESC” (ディセンディング 大->小)を付加。
<?php query_posts("tag=no1&showposts=1&orederby=name&order=ASC"); ?>

 
※指定した post id 順にだしたければ、get_post をつかってひとつづつ処理するとか考えること。
$id_stk=mb_split(',',$id_list);
foreach( $id_stk as $postid){
    query_posts('&p='.$postid);
    if (have_posts()){
        while (have_posts()) {
            global $post;
            the_post();
            $work= strip_tags($post-> post_content); // split_tags は、 < ~ > をとっぱらってくれる
              :
              :
        }
    }
}
 
 

スポンサーリンク

関連記事

スポンサーリンク

カテゴリー