简体   繁体   中英

Wordpress show number of posts within the serie and loop?

I am not sure how to describe my request, which means that I have had a hard time Googling it. Anyway what I am looking for is the following:

Lets say I have a archive with 15 posts. The archive page is restricted to 10 posts per page. Now I would like to show on the first page post 1-10 and on the second page post 11-15 . I tried to google it but with no luck. All I did find was a general wp_query post count:

<?php
echo $wp_query->post_count;
?>

I guess it shouldn't be too hard to accomplish correct? Anyone who can help me out here? Thanks

the thing that you wanted is so easy, wordpress query do this default for you, install wp-pagenavi plugin its show a pagination non the footer and only thing you need to do is set the post limits on 10 in wordpress general setting section.

if this is not what you wanted, so please explain with an example.

********** i found out what you mean of this ***********

first you have to get posts_per_page , you can get that value whit usin one of these codes

$default_posts_per_page = get_option( 'posts_per_page' );

or

global $wp_query;
$total_posts = $wp_query->post_count;

after that you need to know witch page your in , so you can use this code to get that

$current = intval(get_query_var('paged'));

now we need a simple calculate to make the numbers you needed,

<?php 

    $ppp = intval(get_option( 'posts_per_page' ));
    $current = intval(get_query_var('paged'));
    $last = $ppp * $current;

    echo 'post from : ' . ( ($last+1) - $ppp). ' to : '.$last;
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM