• Ok first off I am very much a noob when it comes to php so forgive me if this is a silly question but I am totally stuck!

    Here is the extract of the code in question:

    <div class=”navigation”>
    <?php posts_nav_link(”, ‘<span style=”background:#3182B7; padding:10px; color:#fff; font-size:15px;line-height:40px;”>« Go Back</span>’, ‘<span style=”background:#3182B7; padding:10px; color:#fff; font-size:15px;line-height:40px;”>Read more Articles from this Category »</span>’); ?>
    </div>

    It is a section of code that displays the navigation buttons at the bottom of each of my category pages.

    I will post the code again with what I am trying to do highlighted:

    <div class=”navigation”>
    <?php posts_nav_link(”, ‘<span style=”background:#3182B7; padding:10px; color:#fff; font-size:15px;line-height:40px;”>« Go Back</span>’, ‘<span style=”background:#3182B7; padding:10px; color:#fff; font-size:15px;line-height:40px;”>Read more Articles from this <?php single_cat_title(); ?> »</span>’); ?>
    </div>

    I want the category name to appear so that whichever category I am browsing the ‘next’ navigation will read “Read more Articles from this ‘category'”.

    I know the way I am attempting to code this as illustrated above is incorrect. My notion is that I should try and turn “single_cat_title();” into a variable perhaps?

    Many thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • I think you’re really close. It may be the quotes that are causing you a problem.

    Try this:

    <div class="navigation">
    <?php posts_nav_link('', '<span style="background:#3182B7; padding:10px; color:#fff; font-size:15px;line-height:40px;">« Go Back</span>', '<span style="background:#3182B7; padding:10px; color:#fff; font-size:15px;line-height:40px;">Read more Articles from ' . single_cat_title() . ' »</span>'); ?>
    </div>

    Thread Starter jt1986

    (@jt1986)

    Hiya, I tried this method, very good. But not quite there. It might be something to do with the template I am using (wp-sublime – by Solostream). I know WordPress itself tends to differ slightly from normal php/html.

    The category appears but it slots in before the rest of the text and is not part of the span style that I created with the blue box. I really need it to read: “Read more Articles from ‘category here'”.

    As I said I am no expert but I thought perhaps I put a reference to what I want (*)(with php coding method) then put the bulk of the code outside?

    I think you need to use one of the options for the single_cat_title function to get what you want. Try this:

    <div class="navigation">
    <?php posts_nav_link('', '<span style="background:#3182B7; padding:10px; color:#fff; font-size:15px;line-height:40px;">« Go Back</span>', '<span style="background:#3182B7; padding:10px; color:#fff; font-size:15px;line-height:40px;">Read more Articles from ' . single_cat_title('', false) . ' »</span>'); ?>
    </div>

    If you look at the Codex Article, it says that setting the display parameter to “false” will just return the category title, which is what you want, instead of displaying it, which was probably what was knocking it out of your span tags.

    Thread Starter jt1986

    (@jt1986)

    Yep, thats perfect! Thanks so much. 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘category navigation Questions’ is closed to new replies.