WordPress.org

Ready to get started?Download WordPress

Forums

Using category name with next_posts_link (3 posts)

  1. eggroup
    Member
    Posted 3 years ago #

    Hi,

    I'm trying to echo the category name with the next_posts_link but I can't find out how.

    My current code looks like this :
    next_posts_link('More Posts » ');
    I want it to be more like
    next_posts_link('More "Category Name" Posts » ');

    Looking forward to your help.

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    if you are using it in category.php,
    try:

    <?php
    $cat = get_category(get_query_var('cat'))->name;
    next_posts_link('More "'.$cat.'" Posts &raquo; ');
    ?>

    else, if you are using it in index.php or archive.php,
    try:

    <?php if( is_category() ) { $cat = get_category(get_query_var('cat'))->name; next_posts_link('More "'.$cat.'" Posts &raquo; '); } else { next_posts_link('More Posts &raquo; '); ?>

  3. eggroup
    Member
    Posted 3 years ago #

    Thank you so much!

    It's work. :)

Topic Closed

This topic has been closed to new replies.

About this Topic