[英]get all posts from all categories with pagination
我有50個類別,每個類別都有100個帖子。 我有一個頁面模板,在此頁面上我想顯示具有5-5個帖子的類別,但要使用分頁。 我已經使用了下面的代碼,但是沒有任何分頁,也沒有找到任何帖子,只有類別名稱出現了。
$args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'ID',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'taxonomy' => 'category',
'pad_counts' => false
);
$categories = get_categories($args);
foreach($categories as $category){ $catId[] = $category->term_id; }
$catId_comma_separated = implode(",", $catId);
$myposts = get_posts(array('numberposts' => 5, 'offset' => 0, 'cat' => $catId_comma_separated, 'post_status'=>'publish', 'order'=>'ASC' ));
query_posts( "cat = $catId_comma_separated");
while ( have_posts() ) : the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;
// Reset Query
wp_reset_query();
custom_pagination();
使用paginate_link並從這個問題中引用這個答案
<?php
$catPost = get_posts('cat=3&posts_per_page=-1'); //change this
foreach ($catPost as $post) : setup_postdata($post); ?>
<h1><a>"><?php the_title(); ?></a></h1>
<?php the_excerpt(); ?>
<p class="postinfo">Written by: <?php the_author_posts_link(); ?>
Posted on: <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>
Categories: <?php the_category(', '); ?></p>
<hr />
<?php endforeach;?>
或嘗試一下
<?php
// The Query
query_posts( array ( 'category_name' => 'your_category_name', 'posts_per_page' => -1 ) );
// The Loop
while ( have_posts() ) : the_post();
echo '<h1>';
the_title();
echo '</h1>';
the_excerpt();
echo ' <p class="postinfo">Written by: ';
the_author_posts_link();
echo 'Posted on '
the_date();
echo 'Categories: '
the_category(', ');
echo '</p>';
endwhile; ?>
<?php
// Reset Query
wp_reset_query();
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.