Php 使用分页从所有类别获取所有帖子
我有50个类别,每个类别有100个职位。我有一个页面模板,在这个页面上我想显示5-5篇文章,但分页类别。 我使用了下面的代码,但没有任何分页,也没有任何帖子发现只有类别名称出现Php 使用分页从所有类别获取所有帖子,php,wordpress,Php,Wordpress,我有50个类别,每个类别有100个职位。我有一个页面模板,在这个页面上我想显示5-5篇文章,但分页类别。 我使用了下面的代码,但没有任何分页,也没有任何帖子发现只有类别名称出现 $args = array( 'type' => 'post', 'child_of' => 0, 'parent' => '', 'orderby' =>
$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();
$args=array(
'type'=>'post',
'child_of'=>0,
'父'=>'',
'orderby'=>'ID',
“订单”=>“ASC”,
“hide_empty”=>1,
“层次结构”=>1,
'排除'=>'',
'包括'=>'',
'编号'=>'',
“分类法”=>“类别”,
“pad_计数”=>错误
);
$categories=get_categories($args);
foreach($categories as$category){$catId[]=$category->term_id;}
$catId_逗号_分隔=内爆(“,”,$catId);
$myposts=get_posts(数组('numberposts'=>5,'offset'=>0,'cat'=>catId_逗号分隔,'post_status'=>publish,'order'=>ASC');
查询帖子(“cat=$catId\u逗号分隔”);
while(have_posts()):the_post();
回音“”;
_title();
回音“ ”;
结束时;
//重置查询
wp_reset_query();
自定义分页();
使用并参考
<?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();
?>
谢谢。我的自定义分页可以与其他代码配合使用。但不能与此代码配合使用。请离开分页主题。请告诉我如何仅显示具有类别名称的所有帖子。谢谢..您想显示所有类别或任何特定类别的所有帖子吗?是的,我想显示所有类别的所有帖子。离开分页。但是一个页面只有一个类别和它的所有帖子。