global $post;
$cat1=get_cat_ID('test1');
$cat2=get_cat_ID('test2');
$myrecentposts = get_posts(array('post_not_in' => get_option('sticky_posts'), 'cat' => "-$cat1,-$cat2",'showposts' => 5));
$myrecentposts2 = get_posts(array('post_not_in' => get_option('sticky_posts'), 'cat' => "-$cat1,-$cat2"));
$myrecentpostscount = count($myrecentposts2);
echo $myrecentpostscount;
Run Code Online (Sandbox Code Playgroud)
echo的值为5(正确的值应为9).我可以让它返回正确的后计数值的唯一方法是更改$ myrecentposts2计算,如下所示...
$myrecentposts2 = get_posts(array('post_not_in' => get_option('sticky_posts'), 'cat' => "-$cat1,-$cat2",'showposts' => 999));
Run Code Online (Sandbox Code Playgroud)
小智 7
查看get_posts()Codex上的文档,您可以看到有关要显示的帖子数量的参数:
参数是:'posts_per_page'
用法:'posts_per_page'=> -1 // for removing the limit.这将获取所有帖子.
更新:'nopaging' => true这是更新版本的方式
| 归档时间: |
|
| 查看次数: |
7942 次 |
| 最近记录: |