开发者

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

开发者 https://www.devze.com 2023-02-04 04:27 出处:网络
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.

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

精彩评论

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