• Hey all!

    I’m using Blix in one page I’m building.
    If you’re not familiar with this template, it uses (for example):

    <li<?php if (is_home()) echo " class="selected""; ?>><a href="<?php bloginfo('url'); ?>">Bloco</a></li>

    …to display a top navigation link called ‘Home’ and it uses the class ‘selected’ if you’re in the home page. Something like that, hope you get the idea.

    What I’m trying to do is doing the same with categories, but I’ve failed…

    I’m using the following code:

    <li<?php if ( in_category('2') ) echo " class="selected""; ?>><a href="https://www.example.com/category/forum/">fórum</a></li>

    Any suggestions?
    Thanks in advance ??

    edit:
    I’ve tried this too:

    <?php if ( in_category('2') ) : ?>
    <li class="selected"><a href="https://www.example.com/category/forum/">fórum</a></li>
    <?php else : ?>
    <li><a href="https://www.example.com/category/forum/">fórum</a></li>
    <?php endif; ?>

    No luck.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The in_category Template_Tag can only be used in The Loop. Not too sure why you need the if in category…

    Thread Starter keoshi

    (@keoshi)

    I want to a have a nav link that is ‘selected’ (read: class="selected") when I’m on that category.

    And I’ve read that the in_category template tag is also usable outside of the_loop

    “And I’ve read that the in_category template tag is also usable outside of the_loop”

    keoshi;
    Thanks for pointing that out–here’s an example:
    Template_Tags/in_category#Use_OUTSIDE_The_Loop

    Thread Starter keoshi

    (@keoshi)

    OK, thanks! So now I have:

    <li<?php
    $post = $wp_query->post;
    if ( in_category('2') ) {
    echo " class=\"selected\"";
    } else {
    echo " class=\"deselected\"";
    }
    ?>><a href="https://www.example.com/category/forum/">fórum</a></li>

    But still no luck…
    Maybe the problem is in $post = $wp_query->post;
    I really can’t figure this one out… =\

    Thread Starter keoshi

    (@keoshi)

    *bump*

    Hi

    Just wondering if a solution to this was found?

    I’ve been trying to add a menu item which points to a category page using blix

    thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding category link in Blix’s top navigation’ is closed to new replies.