开发者

I'm retrieving and showing 20 posts offset by 5, but can I get total amount of posts using wp_query?

this is the query im using currently

new WP_Query("cat=&showposts=20&offset=$offset");

What I need to do is get the total number of posts so I can setup some sort of pagination function. Offseting as the person selects the next p开发者_如何学Goosts.


you can use wp_count_posts - see http://codex.wordpress.org/Function_Reference/wp_count_posts


You can't get the total number of posts using wp_query , but you can use $wpdb class to find it out .

Makes good practice to try to build you're own pluggin but since there are a ton of them out there ... WP-Paginate .

And another good practice would be to set the number of posts per page from wp-admin , and not hardcoded in you're theme .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜