• I want to show the post number of the post (not total number of posts)?

    For example –
    for 5ths post – should display post no. 5.

    I am trying following methods : (https://www.ads-software.com/support/topic/show-post-number).

    Problem – But 1st post is repeating two times in each page.
    URL – https://www.makemoneyfreemoney.com/

    I did following things :

    a) In function.php
    function Get_Post_Number($postID){
    $temp_query = $wp_query;
    $postNumberQuery = new WP_Query(‘orderby=date&order=ASC&posts_per_page=-1’);
    $counter = 1;
    $postCount = 0;
    if($postNumberQuery->have_posts()) :
    while ($postNumberQuery->have_posts()) : $postNumberQuery->the_post();
    if ($postID == get_the_ID()){
    $postCount = $counter;
    } else {
    $counter++;
    }
    endwhile; endif;
    wp_reset_query();
    $wp_query = $temp_query;
    return $postCount;
    }

    b) In default.php (index.php)
    $currentID = get_the_ID();
    $currentNumber = Get_Post_Number($currentID); ?>
    <?php echo $currentNumber; ?>

    So, please give me proper suggestion for fix the issue.

  • The topic ‘Show post number (Not Total Number of Posts)’ is closed to new replies.