WordPress.org

Ready to get started?Download WordPress

Forums

Exec-PHP
Code not executed in a widget but ok when hard coded (6 posts)

  1. ouranos2
    Member
    Posted 3 years 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);
        }
    }
    ?>
  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 3 years ago #

  3. ouranos2
    Member
    Posted 3 years 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.

  4. ouranos2
    Member
    Posted 3 years 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 ... ;)

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 3 years ago #

    Your code doesn't have $cat defined. Where is that variable supposed to be coming from?

  6. ouranos2
    Member
    Posted 3 years 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" ?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic