Forums

Next Page Title for Archives and Index (6 posts)

  1. emil2k
    Member
    Posted 2 years ago #

    On archive and index parts at the botton there is the Next and Previous entries links they lead to pages with URL like ...

    domain.com/page/2/

    ... but they have the same title as the domain.com page, the title doesn't change at all from page to page, how could I append a "Page #" to the front of the regular title?

    Thanks

  2. emil2k
    Member
    Posted 2 years ago #

    Anybody?

  3. Kafkaesqui
    Moderator
    Posted 2 years ago #

    1. Plugin solution (though not quite what you ask for):

    http://lesterchan.net/wordpress/readme/wp-pagenavi.html

    2. Hand-coded solution:

    We can collect the current page # this way:

    <?php
    $pagenum = (get_query_var('paged'));
    ?>

    However, this will be empty in certain cases, such as on the home page. But we can use an old trick of mine to set a proper page number no matter what:

    <?php
    $pagenum = (get_query_var('paged')) ? get_query_var('paged') : 1;
    ?>

    Still not useful yet. So let's add a bit to it:

    <?php
    $pagenum = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $nextnum = $pagenum + 1;
    $prevnum = $pagenum - 1;
    ?>

    See where we're going with this? Finally, let's make this into something you can implement by merging it with the posts_nav_link() template tag:

    <?php
    $pagenum = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $prevnum = $pagenum - 1;
    $nextnum = $pagenum + 1;
    posts_nav_link(' | ', '&laquo; Page ' . $prevnum, 'Page ' . $nextnum . ' &raquo;');
    ?>
  4. emil2k
    Member
    Posted 2 years ago #

    Thanks for the tip, is there a query like get_query_var('paged') for the search query string?

  5. Kafkaesqui
    Moderator
    Posted 2 years ago #

    get_query_var('s')

  6. stenspect
    Member
    Posted 1 year ago #

    I just used the following in my title tags (thanks to http://efficienttips.com/wordpress-seo-title-description-tag). Note that I also wrote a Condition Statement that prints the title differently depending on the home page or single post, etc. Paste the below code just before the </title>.

    function pageGetPageNo()
    {
    if (get_query_var('paged'))
    {
    print ' - Page ' . get_query_var('paged');
    }
    }

Topic Closed

This topic has been closed to new replies.

About this Topic