フォーラム

[解決済み] 記事のカテゴリーIDを得たい (3 件の投稿)

  1. masashi
    メンバー
    2 ヶ月前の投稿 #

    index.php内で以下のように記述して、
    ブログ内の記事の最新10件を表示しています。

    $aboutPage = new WP_Query();
    $aboutPage->query('page_id=' . gi_get_ID_by_page_name('about'));
    query_posts('showposts=10');
    while ($aboutPage->have_posts()) : $aboutPage->the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <p class="date"><?php the_time('Y-m-d') ?></p>
    <?php echo var_dump($cat) ?>
    <h2><?php the_title(); ?></h2>

    <div class="entry">
    " rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
    <?php the_excerpt(); ?>

    </div>

    <br class="clear" />

    </div>

    <?php endwhile; ?>

    これにそれぞれの記事のカテゴリーを表示したいと思うのですが
    何方か方法をご存知でしたらごご教示お願いいたします。

  2. jim912
    メンバー
    2 ヶ月前の投稿 #

    masashiさん、こんにちは。

    the categoryを使えば表示できると思います。

  3. masashi
    メンバー
    2 ヶ月前の投稿 #

    jimさんどうもありがとうございます。
    the_categoryでカテゴリー名を得る事が出来ましたがカテゴリーIDを得ることはできませんでしたので
    自分でちょっと調べて解決しました。
    ループの中で

    $cat=get_object_term_cache( $post->ID, 'category' );
    foreach($cat as $key => $value){
    }
    echo $cat[$key]->term_id;

返信

ログイン しなければ投稿できません。

About this Topic

Tags

タグ はまだありません。