WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Pages are in the default Category? (3 posts)

  1. zoo1023
    Member
    Posted 4 years ago #

    I'm using WP as a CMS for a site that's not terribly bloggish, so far, everything's more than I could hope for. However:

    My navigation menu's links have an "active" state that displays when you're in/on whatever category/page of the site.

    All's working well as far as triggering the active class EXCEPT for the fact that the News link (links to a category archive) still gets an active class when you're on one of the two pages (About/Contact), meaning two links at once have the active class. A different category's link (which I've not included in the code below because it's way messier to look at) works just fine, and the News category link doesn't go "active" when you're in it.

    I have a feeling that it's because I'm using the default category for News (I renamed Uncategorized to News). The Pages are somehow in the default category (category #1), which is why the conditional statement for News is true even when in the pages?

    How can I make it stop?? I really don't want to make News the non-default category. The user I'll be handing this off to is highly unlikely to remember to select a category when posting new News items.

    <div id="sidebar">
    <ul>
    	<li><a href="<?php echo get_option('home'); ?>" class="nav"><img src="./images/main.jpg" alt="Main" /></a></li>
    	<li><a href="./news/"  class="nav<?php if (in_category('1')){echo ' active';} ?>"><img src="./images/news.jpg" alt="News" /></a></li>
    	<li><a href="./about/" class="nav<?php if (is_page('about')){echo ' active';} ?>"><img src="./images/about.jpg" alt="About" /></a></li>
    	<li><a href="./contact/" class="nav<?php if (is_page('contact')){echo ' active';} ?>"><img src="./images/contact.jpg" alt="Contact" /></a></li>
    </ul>
    </div>

    Is there another way I can call the active class for the News/default category so that it's not affected by pages? I'd like for it to be active regardless of whether it's the archive or a single page in the News category, or I'd switch to that more specific call.

    Has anyone come across this before?

  2. zoo1023
    Member
    Posted 4 years ago #

    In case anyone else runs into this issue, I figured out a solution!

    I ended up digging into my WordPress mySQL database in phpMyAdmin. Depending on your level of comfort with MySQL, though, you may not like it, and you can seriously screw up your blog if you touch the wrong thing. Plus, you'd have to do this for each and every page you create, even in the future...I'm lucky in that I don't plan on having to mess with this again after I hand it off (and I doubt anyone else will either).

    Create a new category in WordPress, note the category ID number.

    Now, browse the wp_posts table and find the page in question. Note the ID.

    Next, browse the wp_term_relationships table and find the object_id that matches the ID you found in wp_posts. Edit this row.

    Update the "1" in the term_taxonomy_id field to the category ID number you just created in WordPress. Save, exit.

    Tada!

    Someone out there must be able to make a plugin that will reset your page to the non-default category fairly easily. It's probably not very necessary except in my situation anyway, since a category on a page is kind of useless anyway, as far as WordPress goes.

  3. zoo1023
    Member
    Posted 4 years ago #

    Of note: if you have a static page set as your main page, it appears to apply the Uncategorized category no matter what you do in your mySQL database. I got around this by updating the News link to the following:

    <li><a href="./news/" class="nav<?php if (is_front_page()) { } else { if (in_category('1')){echo ' active';}} ?>"><img src="./images/news.jpg" alt="News" /></a></li>

Topic Closed

This topic has been closed to new replies.

About this Topic