• Hi all, hope someone can help – this should be easy for anyone who knows PHP – unfortunately I dont have a clue!

    I have a two level menu with categories and sub categories. I want the sub categories to be displayed when the main category is active.

    I adapted the following code from another source except it was set up for pages so I am not sure if it is correct. At present the correct sub categories display but won’t disappear when you move to another category.

    By the way Category 4 is the category I want to display the sub categories from

    <?php

    $thiscategory = $wp_query->post;

    if($thiscategory->post_parent!=0)

    {

    wswwpx_fold_category_list(“title_li=&child_of=”.$thiscategory->post_parent);

    }

    else {
    wp_list_categories(“title_li=&child_of=4”);

    }

    ?>

Viewing 9 replies - 1 through 9 (of 9 total)
  • The same plugin author from where you got your Pages code… has a plugin for categories:
    https://www.webspaceworks.com/resources/wordpress/31/

    Thread Starter shooter1

    (@shooter1)

    Thanks, yeah I knew about this – but he doesn’t have anything similar for categories – I can’t find anything to help. I just don’t understand what all this means:

    $thiscategory = $wp_query->post;

    if($thiscategory->post_parent!=0)

    {

    wswwpx_fold_category_list(“title_li=&child_of=”.$thiscategory->post_parent);

    but he doesn’t have anything similar for categories

    I hate when people talk back without clicking on the resources I offered. The link I gave you above is for collapsable categories!

    Thread Starter shooter1

    (@shooter1)

    Hi Moshu,

    I did check the link but it doesn’t solve my problem, I am already using that plug in but the site is pretty low on details about how to implement it, particularly in an IF statement. As mentioned before I have no clue about PHP and just need to try and understand this code I have.

    If no clue about PHP – you shouldn’t mess with the code.

    Why do you need an IF statement, why doesn’t the plugin work for you as is?
    You don’t “implement” a plugin. You upload, activate and use it: in this case replace WP’s category template tag with the one suggested in the readme. Done.
    What is so complicated?

    Thread Starter shooter1

    (@shooter1)

    There is no readme with the zip. I need the IF statement to make the menu work, just like the one based on pages needed an IF statement the one for the categories does too surely?

    None of them needs any IF statement.

    There is a detailed instruction for Usage on the plugin’s page. WHY do you need the IF…? I still don’t get it. (maybe I am not the only one)

    Thread Starter shooter1

    (@shooter1)

    Hi Moshu

    Perhaps I wasn’t clear – it’s just I have navigation with both pages and categories running side by side.

    Currently the sub categories display but wont go away when I move away from that category

    i.e. Category
    Sub 1
    Sub 2

    Page
    Sub Page 1
    Sub Page 2
    Sub 1
    Sub 2

    Both subs appear when they shouldn’t, it’s just the lack of complaince between pages and categories which forces me to use the IF.

    I just need a way to exclude the sub categories when the parent is not active

    Pretty sure the problem lies in this line here:

    wswwpx_fold_category_list(“title_li=&child_of=”.$thiscategory->post_parent);

    Hi,

    Did you contact me (the author of the plugin)? I don’t recall seeing anything in my mail… there’s an email address in the header of the plugin…

    Anyway… I’m a little confused by what you mean by all this… You also seem to be mixing categories and pages/posts and I’m not sure the if… else (which afterall was created for handling pages) is doing what you think it is doing.

    If the tested value is non-zero then the plugin will show the (sub-)categories of whatever that value is. If the tested value is zero it will display for catregory ‘4’.

    I suspect that you are getting non-zero values where you expect to have zero, and maybe even zero where you expect to have non-zero.

    Regards

    Rob

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Sub category not displaying properly’ is closed to new replies.