首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用分页从所有类别中获取所有帖子

使用分页从所有类别中获取所有帖子
EN

Stack Overflow用户
提问于 2013-09-30 18:52:50
回答 1查看 562关注 0票数 0

我有50个类别,每个类别有100个帖子。我有一个页面模板,在这个页面上,我想显示5-5个帖子的类别,但在分页。我已经使用了下面的代码,但没有任何分页和任何帖子发现只有类别名称。

代码语言:javascript
运行
复制
$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();
EN

回答 1

Stack Overflow用户

发布于 2013-09-30 19:44:48

使用并参考来自的答案

代码语言:javascript
运行
复制
<?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;?>

或者试试这个

代码语言:javascript
运行
复制
<?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();

          ?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19092389

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档