Adding images to the sub categories

  • Mariana
    Mariana
    Newbie 14 points
    April 3, 2015 at 5:37 pm

    Dear people

    I’m trying to add thumbnails to the sub categorie links that appear when the users opens one of the categories.

    I have been able to fiend where the sub categories are called .
    themes>DT>search.php line 40: <?php hook_gallerypage_results_before(); ?>
    I tryed to add this file to my custom child theme in order to edit it
    themes>myChildtheme>search.php
    but I found that it affect the search results page only (but the search.php in DT only affects the category page, where the URL sais “listing-category/exampleCategory”)

    That confuses me a little which file do I need to add to my child theme in order to edit this page? and is there an easy way to add the thumbnails to those sub categories?

    Thank you all in advance

  • Mariana
    Mariana
    Newbie 14 points
    April 7, 2015 at 11:18 am

    bump, anyone?

  • zarko
    zarko
    Senior Member 360 points
    April 7, 2015 at 5:40 pm

    hi Mariana,

    hook_gallerypage_results_before() seems like a great hook which you can use for this purpose, you don’t need to copy a file into your child theme folder

    I suppose you are going to use category icon which you attached to each category/subcategory in Categories menu. I’m not sure what styles you would like here and in which cases for icons to show, but try code like this:

    [code title=””]function custom_subcategory_thumbs() {

    $current = get_queried_object();
    $termid = $current->term_id;

    $icon = $GLOBALS[‘CORE_THEME’][‘category_icon_’.$termid];
    if(!isset($icon) && empty($icon)) { return; }
    ?>

    ” class=”img-responsive” style=”max-width:150px”>

    <?php
    }

    add_action(‘hook_gallerypage_results_before’, ‘custom_subcategory_thumbs’);[/code]

    you can put this in your child theme functions.php file

  • zarko
    zarko
    Senior Member 360 points
    April 7, 2015 at 5:43 pm

    code above may have syntax error due to formatting, use code from file attached instead

    Attachments:
    You must be logged in to view attached files.
    This reply was awarded the best answer by the topic poster.
  • Mariana
    Mariana
    Newbie 14 points
    April 8, 2015 at 3:30 pm

    Hi Zarko you have helped me quite a lot with your example code, however that is not entirely what I whant to do.

    I whant to replace the subterm a links with the term images, have alook at my code and you will see what I’m trying to do. This code works but I cants seem to remove the a links of the terms

    [code title=”function”]
    function custom_subcategory_thumbs() {

    $current = get_queried_object();
    $termid = $current->term_id;
    $termTaxName = $current->taxonomy;

    $cur_cat = get_cat_ID( single_cat_title(“”,false) );
    $children = get_term_children($termid,$termTaxName );

    $icon = $GLOBALS[‘CORE_THEME’][‘category_icon_’.$termid];
    if(!isset($icon) && empty($icon)) { return; }
    echo ““;

    for($i = 0; $i < count($children); $i++)
    {
    $icon = $GLOBALS[‘CORE_THEME’][‘category_icon_’.$children[$i]];
    echo ““;
    }

    }

    add_action(‘hook_gallerypage_results_before’, ‘custom_subcategory_thumbs’);

  • zarko
    zarko
    Senior Member 360 points
    April 8, 2015 at 5:23 pm

    Mariana,

    Your code seems to be working fine ( If I read it correctly because it’s not clearly visible ). Try to attach it again in .txt file maybe

    In your for($i = 0; $i < count($children); $i++) loop, $children[$i] return subcategory ID correctly, than just use[code title=””] $icon = $GLOBALS[‘CORE_THEME’][‘category_icon_’.$children[$i]];[/code] to get direct link of the image

  • Mariana
    Mariana
    Newbie 14 points
    April 8, 2015 at 7:14 pm

    yes that already in the code 🙂 what I was trying to do is disable the text links that were already on the page but it appears you can do that in the admin panel 🙂 thank you for your help.

Viewing 7 posts - 1 through 7 (of 7 total)

New Business Themes for WordPress 2020

Start your new website today!

View Business Themes