2016-05-21 5 views
0

私は多くのWordPres投稿とページを作成しようとしています。私は様々なカテゴリーに投稿とページを含める。各カテゴリーでは、投稿とページの両方を追加します。このような状況では、特定のカテゴリの下に投稿とページを表示する必要があります。カテゴリの下で昇順または降順に投稿とページを並べ替える必要があります。私はこの目的をPHPコーディングする必要があります。私に助けてください。私はcategory.phpをコードで作成しました。WordPressを表示するにはカテゴリー内の投稿とページ

<div class="cate-top "> 
        <h1 class="cat-page-title"><?php printf(__(' Your are Browsing: %s', 'twentythirteen'), single_cat_title('', false)); ?></h1> 

        <?php if (category_description()) : // Show an optional category description ?> 
        <div class="archive-meta"><?php echo category_description(); ?></div> 
        <?php endif; ?> 

        <?php while(have_posts()): the_post();?> 


       </div> 
      <div class="category-page"> 
       <div class="cate-inn "> 
         <h2><a href="<?php the_permalink();?>"> <?php the_title();?></a></h2> 

         <div class="cat-image fix"> 
          <a href="<?php the_permalink();?>"> <?php the_post_thumbnail();?></a> 
         </div> 
         <div class="cat-read-more fix"> 
          <?php read_more(0);?><a href="<?php the_permalink();?>">Read More</a> 
         </div> 
       </div> 




        <?php endwhile;?> 

答えて

1

あなたはあなたがしている場合の例

<?php $args = array(
'posts_per_page' => 5, 
'offset'   => 0, 
'category'   => '', 
'category_name' => '', 
'orderby'   => 'date', 
'order'   => 'DESC', 
'include'   => '', 
'exclude'   => '', 
'meta_key'   => '', 
'meta_value'  => '', 
'post_type'  => 'post', 
'post_mime_type' => '', 
'post_parent'  => '', 
'author'  => '', 
'post_status'  => 'publish', 
'suppress_filters' => true 
); 
$posts_array = get_posts($args); ?> 

のためにあなただけの、引数に

をお使いのカテゴリ名を変更することができ、ページを取得し、ご希望のカテゴリに投稿するget_postsまたはWP_Queryを使用することができますデフォルトのカテゴリの代わりにカスタム分類を使用すると、次のコードを使用できます。

$custom_terms = get_terms('custom_taxonomy'); 

foreach($custom_terms as $custom_term) { 
wp_reset_query(); 
$args = array('post_type' => 'custom_post_type', 
    'tax_query' => array(
     array(
      'taxonomy' => 'custom_taxonomy', 
      'field' => 'slug', 
      'terms' => $custom_term->slug, 
     ), 
    ), 
); 

$loop = new WP_Query($args); 
if($loop->have_posts()) { 
    echo '<h2>'.$custom_term->name.'</h2>'; 

    while($loop->have_posts()) : $loop->the_post(); 
     echo '<a href="'.get_permalink().'">'.get_the_title().'</a>'; 
    endwhile; 
} 
} 

助けてVISIT、get_postのためにVISIT

関連する問題