WordPress.org

Ready to get started?Download WordPress

Forums

Widget Logic
[resolved] Have widget appear in child category (6 posts)

  1. mek8
    Member
    Posted 1 year ago #

    I'm attempting to use the code suggested on the "other notes" page of the plugin in order to display a widget on all descendants of a category.

    Here's the code:
    is_category() && in_array($cat, get_term_children( 5, 'category'))

    To be clear, here's the category structure:

    Cat 1
    Sub A
    Sub B

    I'm trying to get a widget to appear on Sub A and Sub B by specifying the parent category ID in the code above. I have not yet met with success as the widget is not showing up on Sub A and Sub B. What am I missing?

    http://wordpress.org/extend/plugins/widget-logic/

  2. alanft
    Member
    Plugin Author

    Posted 1 year ago #

    I've just looked at the example code and it's missing a bit. It should be

    global $cat; return (is_category() && in_array($cat, get_term_children( 5, 'category')));

    try adapting that

  3. mek8
    Member
    Posted 1 year ago #

    Unfortunately that didn't seem to do the trick either. If it helps to see one of the sub categories, here it is:

    http://www.stthomas.edu/news/category/publications/st-thomas-magazine/2012-spring/

    You'll note that the parent is st-thomas-magazine and the sub in this case is 2012-spring. If everything works right, there should be a "St. Thomas Magazine" logo that appears in the upper right corner in a widgetized area.

    I appreciate the help.

  4. alanft
    Member
    Plugin Author

    Posted 1 year ago #

    I would try using a PHP widget that does something like

    global $cat; echo "cat= ".$cat." term_children="; print_r( get_term_children( 5, 'category'))

    which will help troubleshoot this.

  5. mek8
    Member
    Posted 1 year ago #

    For anyone who happens to come across this thread, here's the code I finally used to make the widget display on any child of category X.

    cat_is_ancestor_of(
    get_cat_ID("CATEGORY X"),
    $GLOBALS["cat"]
    )

  6. alanft
    Member
    Plugin Author

    Posted 1 year ago #

    oh that's a really good tip using $GLOBALS - that had not occurred to me!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.