ouranos2
Member
Posted 1 year ago #
I want to display subcategories of current category in a widget. So i tested exec-php and "exec-php / hello world" works fine.
The code I'm using (see below) works fine when hard-coded in the sidebar, but doesn't display anything when i put it in a text widget.
I tried with no other active plugin, same result ...
You can see the two widgets and the hard-coded result here, at the bottom of the sidebar.
http://www.xarax.fr/wpfsc4/rubrique/democratisation-de-la-science/
Any idea ? Thanks.
<?php
if (is_category()) {
$this_category = get_category($cat);
if (get_category_children($this_category->cat_ID) != "") {
wp_list_categories('orderby=id&show_count=0&title_li=
&use_desc_for_title=1&child_of='.$this_category->cat_ID);
}
}
?>
ouranos2
Member
Posted 1 year ago #
Thanks Otto, but i already tried it, and a bunch of other php plugins. I will try once more with php-code-widget, though, and after that i will bother you with the same problem on your plugin page ... ;)
F.
ouranos2
Member
Posted 1 year ago #
So, i tried again with php-code-widget. You can see the result at the same url : http://www.xarax.fr/wpfsc4/rubrique/democratisation-de-la-science/
A php-code-widget "hello world", no problem so far. But the code i try to execute (see above) give no result. Same code hard-coded in the sidebar, no problem (bottom of the sidebar).
Any idea from the Tech Ninja would be a great help ... ;)
Your code doesn't have $cat defined. Where is that variable supposed to be coming from?
ouranos2
Member
Posted 1 year ago #
Sorry Otto, but I've got no php skill at all ... The variable is the current category in the url ? What i don't understand is why this exact same code works fine when i don't use any plugin (when the code is in the sidebar template) and why it doesn't work with a "php-widget-plugin" ?