Eject2
Member
Posted 10 months ago #
Hi,
There's this line of code in a theme I bought:
<div class="category"><?php the_category(', ') ?></div>
It shows all of the categories a post is related to at the homepage and some other pages.
There are two top categories (tag_ID=36 and tag_ID=15). A post never belongs to a top category but to multiple sub-categories that are under these 2 main categories.
I'd like php the_category to show only sub-categories which their parent is not 36 (exclude).
Or alternatively, show only sub-categories their parent is 15.
How can I do it ?
Thanks !
write your own code based on get_the_category() http://codex.wordpress.org/Function_Reference/get_the_category, and use conditional tags to exclude categories from the foreach loop needed to create the output.
Eject2
Member
Posted 10 months ago #
If only I knew how.. :)
Unfortunately I'm not a coder. That's why I'm asking...
try to add this code to functions.php:
http://pastebin.com/ZfMAuTTU
no need to edit any other files.
just be aware that it is quite specialized and not flexible - if the only category of the post is from a child of cat 36, it will show empty.
make a backup copy of functions.php before editing in case you want to undo the edit.
Eject2
Member
Posted 10 months ago #
Thanks for the help!
I get this error:
Fatal error: Call to undefined function add_filter() in /home/getwebho/public_html/wp-includes/functions.php on line 4555
you edited the wrong functions.php file - you need to add the code to functions.php of your theme
located somewhere here:
/wp-content/themes/yourtheme/functions.php
Eject2
Member
Posted 10 months ago #
Great, it's working.
Thank you very very much !
shoshanna
Member
Posted 7 months ago #
Hi, I used the code in the pastebin below and it works perfectly on the site. In the admin, however, if you go to edit a post the category list is broken in an odd way there. It's showing up as HTML link code next to each checkbox, duplicated multiple times.
http://pastebin.com/ZfMAuTTU
Is there any way to block this function from affecting the admin?
Thanks!