• Resolved petermackinnon

    (@petermackinnon)


    Hi

    I am trying to organize the content on a website using categories in wordpress.

    The setup that I have is like this:

    – Dan Brown <- Main Category

    – Angels and Demons <- Sub Category

    – Angels and Demons Review <- Post in Angels and Demons category

    – The Davinci Code <- Sub Category

    – The Davinci Code Review <- Post in The Davinci Code category

    So right now the page (a custom template) will list Dan Brown. I get the category list like this:

    Code:

    <?php wp_list_categories(‘title_li=&sort_column=name&depth=1&hide_empty=0’); ?>

    When I click Dan Brown I want to see another page that lists Angels and Demons and The Davinci Code…

    Then I want to click the name of the book to see the review…

    Right now Clicking Dan Brown shows the review ??

    How do I change the target of the link on the initial page?

    Thanks!!

Viewing 6 replies - 1 through 6 (of 6 total)
  • When I click Dan Brown I want to see another page that lists Angels and Demons and The Davinci Code…

    That would mean you want your Category Template to use another instance of the template tag, wp_list_categories(), with the child_of argument. Something like:

    <?php
    if ( is_category() ) {
    $cat = get_query_var('cat');
    $args = array(
      'title_li' => '',
    	'echo' => 0,
    	'child_of' => $cat
    	)
    $child_cats=wp_list_categories($args);
    if ($child_cats) {
    echo $chld_cats;
    } else {
    //do whatever if no child cats
    }
    ?>
    Thread Starter petermackinnon

    (@petermackinnon)

    Thanks so much for the response!

    I was not aware that categories used the templates that way, this is great…

    but the code example you posted breaks here: $child_cats=wp_list_categories($args);

    Parse error: syntax error, unexpected T_VARIABLE

    I am wondering if it is an issue with the array?

    does it matter what I am passing to this category page from my page template?

    Helps to actually test this stuff sometimes ??

    <?php
    if ( is_category() ) {
    $cat = get_query_var('cat');
    $args = array(
      'title_li' => '',
    	'echo' => 0,
    	'child_of' => $cat
    	);
    $child_cats=wp_list_categories($args);
    if ($child_cats) {
    echo $child_cats;
    } else {
    //do whatever if no child cats
    }
    }
    ?>

    This code does belong in a category template, not a page template.

    Thread Starter petermackinnon

    (@petermackinnon)

    Awesome thanks!

    this does work…

    but…

    on my category page I am not getting the links for the posts within the sub-category. So the category.php template now displays the sub-categories perfectly, so in my above example I see Angels and Demons and The Davinci Code but the links are trying to load another category, which does not exist…

    So now I need to make an adjustment so that the links produced by this code are to the posts in the sub category…

    Using this as category.php with the WordPress Default Theme, only categories that have NO children will have their posts displayed:

    https://wordpress.pastebin.ca/1402162

    Note:
    By WordPress standards, ANY category that has been designated a Parent category is not meant to be checked in the category hierarchy when writing posts. Meaning, only the latest generation category should be checked. Think of it like this, only the youngest generation gets the action.

    Thread Starter petermackinnon

    (@petermackinnon)

    Thanks!

    I was able to use that code and make this work exactly the way I want…

    I really appreciate your help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Need help managing categories…’ is closed to new replies.