sibling categories

Posted in: Newspaper
Post count: 388

Hi,

I’ve created a custom category header using the TD api (so easy and great!), and I’ve come across a difficult problem for my skill level…

I don’t like showing the sibling categories when there are no children to show. I’d rather just show nothing. Hence, I wish I could comment out this block in get_sibling_categories:

// if no child categories get siblings
if (empty($categories_objects)) {
$categories_objects = get_categories(array(
'parent' => $this->current_category_obj->parent,
'hide_empty' => 0,
'number' => self::SIBLING_CATEGORY_LIMIT
));
}

But I’m not sure of the best way to override that function.

Should I:

— Overwrite the function in my plugin’s category template, since it’s a child of td_category_template?
— Try to overwrite td_category_template in a child theme?
— Edit the parent theme’s td_category_template and make the edit again on every update?
— Copy td_category_template and have my header be a child of that class instead?
— Something else?

Sorry if this is a stupid question, but if you have any ideas, please let me know!

Post count: 1291

Hi,

The easiest way would be to make the modification inside the main theme and apply it each time you update. If you want to make it from the child-theme you have to overwrite the category template and copy the get_sibling_categories method inside the file. Modify the code to make sure it works, then change the call from parent::get_sibling_categories to self::get_sibling_categories

Thank you!

Post count: 388

Thank you! That worked — copying the function from td_category_template, avoiding using $this, and switching parent to self. 🙂

Post count: 3

Hi there,

I know that this is an old topic, but my question is similar to the issue above. I only want to display child categories and no siblings. The solution above seems to work, but as I am a complete rookie I don’t exactly know which steps to take and which code to implement to achieve this. Could anyone explain the above solution in a more simpler or step-by-step manner? It would be totally awesome if you could help me with this!

Post count: 20685

Hi,


@Nadelaine
In case a category does not have any sub-categories, the theme will display other categories instead, this would be considered a feature.
If it has sub-categories these will be displayed.

You can simply comment or remove the mentioned code in the theme files if you would like to display nothing in case there are no sub-categories
https://www.screencast.com/t/Ll526ib61Gq
Then make a back-up of the file and after an update replace the new file, or keep commenting the code after each update. That would be the easiest way.

Thanks

Post count: 9

I have do it, but it’s work only on original theme. On category template created in “cloud templates” it’s nothing happen. How to fix it?

Post count: 20685

Hi,


@A
.Mason That would require modifications in the cloud library plugin, not theme files. Try the same in this file – https://www.screencast.com/t/rQUTl5BE
Note that this is not tested and recommended, you can try it and see if it works.

Thanks

Post count: 9

It’s work. Thx!

Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic.