web-dev-qa-db-ja.com

ワードプレスでカテゴリのすべての記事を表示する方法?

カスタム投稿タイププラグインを使用してカテゴリを作成しました。現在、カテゴリの最新の投稿が5件のみ表示されています。
私が欲しいのは、そのカテゴリーのすべての投稿を表示することです。
たとえば、映画のカテゴリがあるとします。そのカテゴリ内のすべての映画が必要です。
どのコードをどこで使用すればよいですか。
私はワードプレスについてはあまり知りませんので、段階的なプロセスを踏み出すことを感謝します。

8
saurabh
   <?php
    $args = array( 'category' => 7, 'post_type' =>  'post' ); 
    $postslist = get_posts( $args );    
    foreach ($postslist as $post) :  setup_postdata($post); 
    ?>  
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
    <?php the_excerpt(); ?>  
    <?php endforeach; ?> 

カテゴリID(番号7)を変更し、プラグインに含まれていたpost_typeを変更するだけです。

post_typeの詳細については、link http://codex.wordpress.org/Custom_Post_Types を参照してください。

7
arnold

ワードプレスでそれをするのはとても簡単です。あなたはポストが通常「ループ」の中に表示されることを理解しなければなりません。それはそれ自身を繰り返す小さなコードです。あなたはそれをするために一つを使わなければなりません。

<?php 
 $catPost = get_posts(get_cat_ID("NameOfTheCategory")); //change this
   foreach ($catPost as $post) : setup_postdata($post); ?>
       <div>
             <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
             <p><?php the_content(); ?></p>
       </div>
<?php  endforeach;?>

あなたはあなたのニーズに合うものに出力を変えるべきです

2
Alexcp

このコードを使用して特定のカテゴリのすべての投稿にアクセスできます。あなたのcategory.phpページでコードのspinetを使ってください

$current_category = get_queried_object(); ////getting current category
$args = array(
        'post_type' => 'our-services',// your post type,
        'orderby' => 'post_date',
        'order' => 'DESC',
        'cat' => $current_category->cat_ID // current category ID
);
$the_query = new WP_Query($args);
if($the_query->have_posts()):
   while($the_query->have_posts()): $the_query->the_post();
    echo "<h2>".the_title()."</h2>";
    echo "<p>".the_content()."</p>";
endwhile;
endif;
0
Dani

これは、他の誰かが書いたコードを元にしています。そして、私がそれがどこから来たのかを知るために長すぎる恩恵を受けました。それはあなたの要求のために働きます:

<?php
$catPost = get_posts('cat=888&posts_per_page=-1000');
   foreach ($catPost as $post) : setup_postdata($post); ?>
  <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
    <?php the_post_thumbnail('name of your thumbnail'); ?>
  </a>

<h4>
  <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
    <?php the_title(); ?>
  </a>
</h4>
<hr/ style="clear:both;">
<?php  endforeach;?>
0
Justin Munce