• Resolved danpacey

    (@danpacey)


    Hi all, hope someone can help with this issue.

    I am using a whole bunch of

    if(in_category('x')

    statements to setup menu classes depending on which Page/Category i am viewing.

    I am finding I have a problem on certain Pages, whereby a submenu is in its highlighted “on” state. This submenu on state is for posts in Cat 3 – which leads me to think these pages have been allocated to Cat 3.

    Is there any way I can change the Category for these Pages?

    I’ve had a good look through the database using phpmysql, but whatever changes I made didn’t solve the problem.

    Many thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Pages don’t use categories. Only posts do.

    Generally menus set a “current-page” class on the currently displayed page. Then special CSS styling is applied to that page.

    You are through some method creating a correlation between a category of posts and a specific page. Make sure you have the right category applying to the right page.

    How are you making these category-to-page correlations? Through custom page templates, or through PHP code in the page template? Double check how you have it set up.

    Thread Starter danpacey

    (@danpacey)

    I am using PHP to define CSS classes, based on if statements:

    main header menu code

    <a href="?page_id=4"
    <?php if(is_page('4')){
    echo 'class="menu3_on"';
    }
    else {
    echo 'class="menu3"';
    } ?>>Group</a>
    <a href="?page_id=5"
    <?php if(is_page('5')){
    echo 'class="menu4_on"';
    }
    else {
    echo 'class="menu4"';
    } ?>>Contact</a>

    problematic submenu code:

    <li <?php if(in_category('3') ){
    echo 'class="sub1_on"';}
    else
    {echo 'class="sub1"';} ?>>
    <a href="?cat=3" (etc)

    I honestly cannot see anything in there that would cause it. I thought all pages were assigned to whatever the default Category is on creation? All of which leads me to think these Pages are assigned to Cat 3.

    thanks for your help this far!

    Thread Starter danpacey

    (@danpacey)

    Also: if I change the submenu code to

    ‘if(in_category(‘2′)’

    for example, the correct class is called. Therefore.. the Page MUST be in Cat 3. It’s the only explanation.

    Hi
    Again, pages do not have categories assigned to them. Are you displaying other blog posts on these pages, or the contents of the page you set up in the WP editor. When blog posts are displayed on a page then they can have categories assigned.

    I’m not sure whether it will help you here, but there is a debugging plugin called AskApache What Is This that when activated displays whether what it is looking at is a page, a category, a single post, etc. If its appropriate it might help you debug what is going on.

    You can also add some debugging echo statements into your PHP to print out when a branch of the code is being executed, to help you track down what may be up.

    Thread Starter danpacey

    (@danpacey)

    I’ll have a look at that, thanks for your help!

    The pages i have this problem with are template files, but they aren’t pulling in anything with query_posts. I’m quite baffled by this one!

    thanks again!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Changing the Category of a Page’ is closed to new replies.