Display sub-subcategories on subcatgory results page


  • Janak
    Super Guru 1,283 points
    August 27, 2015 at 8:22 am

    When you click on a category you get the listings for that category and also it’s subcategories at the top that you can click on to go to the subcategory.
    On the subcategory page though, you don’t get the sub-subcategories listed. By this I mean the subcategories (3rd level) within the subcategories (2nd level). I want the user to have the option to click on a sub-subcategory and go down to the next level and get more specific results.

    Does anyone know if it’s possible to list the sub-subcategories on the subcategories listing page or has anyone found a way round it?

    Any advice appreciated.


  • Janak
    Super Guru 1,283 points
    August 27, 2015 at 10:59 am

    Just to add I’ve managed to do it but only by modifying a core file so could do with finding another solution.

    I modified the function gallerypage_results_before in class_layout.php file.

    I haven’t set up a child theme yet as I’m just playing around with the RT theme before new version comes out. I believe you can include functions in child themes so does anyone know if it’s possible to include this change in a child theme?


  • Janak
    Super Guru 1,283 points
    September 2, 2015 at 6:42 am

    Can anyone confirm I can do this in a child theme (see above).
    @Mark, if you are around could you please confirm.


  • Joel
    Newbie 1 points
    September 4, 2015 at 8:26 pm

    Dear Janak

    You could give me the section of code that you modified, because I require to do the same.

    best regards

  • Hemanta Chakladar
    Hemanta Chakladar
    Super Guru 1,710 points
    September 4, 2015 at 9:15 pm

    Yes, it can be added from funtions.php by hooks/filter

    Give me the code, you modified, so I will try to add it in functions.php


  • Janak
    Super Guru 1,283 points
    September 4, 2015 at 10:02 pm

    @Joel, @Hemanta

    Here is the procedure in class_layout.php

    [code title=””]function gallerypage_results_before(){ global $CORE, $category, $canShowExtras;

    // PRINT OUR CATEGORY DESCRIPTION
    if(isset($category->description) && strlen($category->description) > 1 && $GLOBALS[‘CORE_THEME’][‘category_descrition’] == 1){
    echo “<div class=’category_desc’>”.nl2br(do_shortcode($category->description)).”</div>”;
    }

    // print out sub categories
    if($GLOBALS[‘CORE_THEME’][‘subcategories’] == ‘1’ && $canShowExtras && !isset($_GET[‘s’]) ){
    $term = get_term_by( ‘slug’, get_query_var( ‘term’ ), get_query_var( ‘taxonomy’ ) );
    //JM if ($term->parent == 0) {
    $cats = wp_list_categories(‘echo=0&taxonomy=’.THEME_TAXONOMY.’&depth=1&hide_count=0&hide_empty=0&title_li=&child_of=’ . $term->term_id);
    echo ‘<div id=”wlt_core_subcategories”>’.str_replace(“<li”,”<span”,str_replace(““,”</span>”,$cats)).'<div class=”clearfix”></div></div>’;
    //JM }
    }
    }[/code]

    I have just commented out the If statement.
    It does mean when you go to a category with no subcategories you now get the text No Categories – it’s not a big deal but I’ll probably look at getting rid of this but I’m waiting for the new version first.

  • Richard
    Richard
    Super Guru 968 points
    September 6, 2015 at 7:52 pm

    Hi,

    Only downside to modding your core code is that when an update comes out, you’ll lose all you changes.

    Make a backup 😉


  • Janak
    Super Guru 1,283 points
    September 6, 2015 at 9:11 pm

    Yeah Richard, I know. That’s why I’m clarifying that I can put the modified function in a child theme!

  • Richard
    Richard
    Super Guru 968 points
    September 6, 2015 at 9:57 pm

    @ Januk,

    That’ll teach me to read the thread more carefully 😉

  • Mark
    Mark
    Titan 733 points
    September 7, 2015 at 12:27 pm

    You can’t override the class_layout.ph but as the function gallerypage_results_before is only called in the search.php file, you can do the following:

    1) Add the modified function to your child theme functions.php file and name it ‘gallerypage_results_before_new’ – or something similar
    2) Copy the file search.php to your child theme
    3) Edit the search.php in your child theme and replace the
    $LAYOUT->gallerypage_results_before();
    with your new function:
    gallerypage_results_before_new();

    Mark


  • Janak
    Super Guru 1,283 points
    September 8, 2015 at 11:01 am

    @Richard, no problem.

    @Mark, thanks for that, that’s definitely a better option than changing core file.
    One question – as you say I can’t override class_layout.php in child theme but can’t I override the function gallerypage_results_before by adding a modified copy with the same name to my child theme?

  • Hemanta Chakladar
    Hemanta Chakladar
    Super Guru 1,710 points
    September 8, 2015 at 12:10 pm

    FYI search.php doesn’t work from child theme. You have to edit and kkeep search file in parent theme.


  • Janak
    Super Guru 1,283 points
    September 8, 2015 at 1:01 pm

    Thanks Hemanta. That’s not really a problem for me as I’m really wanting to override the function gallerypage_results_before() in a child theme. In your earlier post on here you said it could be done.

    Can I just put my modified function in the functions.php file in my child theme?

  • Hemanta Chakladar
    Hemanta Chakladar
    Super Guru 1,710 points
    September 8, 2015 at 1:45 pm

    Yes, I thought it as a independent function, that can be override, but it isn’t. Now it is as simple as copy that code and put it on search.php and search.php should works on child-theme, so your modification remains in child theme, ideally.

    Here problem is search.php should be on parent theme. So, you solution is edit that file and kept that file while updating. Its not a core theme file. Its just a theme tmplate, no problem in editing it.

    Thanks.


  • Janak
    Super Guru 1,283 points
    September 8, 2015 at 8:38 pm

    Ok, thanks for the info Hemanta.

Viewing 15 posts - 1 through 15 (of 16 total)

New Business Themes for WordPress 2020

Start your new website today!

View Business Themes