WordPress.org

Support

Support » Plugins and Hacks » [Resolved] [Plugin: Widget Logic] Is there a "is_subpage" alternative?

[Resolved] [Plugin: Widget Logic] Is there a "is_subpage" alternative?

Viewing 15 replies - 1 through 15 (of 18 total)
  • Plugin Author alanft

    @alanft

    one of the sample codes on http://wordpress.org/extend/plugins/widget-logic/other_notes/ is

    global $post; return (in_array(77,get_post_ancestors($post))); — WP page that is a child of page 77

    if you can get the page ID number of ‘california’ that might do you.

    Plugin Author alanft

    @alanft

    the next sample, adapted would work for DIRECT CHILDREN as opposed to all descendants.

    global $post; return ($post->post_parent==”77″);

    Thanks Alan, I need to know exactly where to put that code in relation to the widget showing up on those pages.
    I registered 2 new sidebars/widget areas in functions.php. I also added them to sidebar-bottom.php so they work correctly. I have added text widgets to the new sidebars and I need each of them to show up on the pages discussed earlier.
    I am using Genesis Framework – News Child theme. The only editing capabilities I have are for home.php, functions.php & sidebar-bottom.php

    P.S. This is the shortlink location of “california” >> http://addictiondiscussion.com/?p=1153

    Is 1153 the correct “page ID” or “post ID”?

    Alan, lets take this a step further and lets make the “text widget” show up only in the “Footer 3” (bottom right corner) of the pages. That is really the main objective.

    Plugin Author alanft

    @alanft

    yes 1153 is the page ID in that instance.

    sorry, i’m not too sure what you are asking in that last question. you set your widgets up in each sidebar, and then you set the widget logic in that widget as per the screenshot

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

    Yes, I get that, but do I put the tag >> global $post; return ($post->post_parent==”1153″); right in the widget_logic box at the bottom of the widget?

    Or would I place the >> global $post; return ($post->post_parent==”1153″); tag in the function.php file?

    Plugin Author alanft

    @alanft

    in the box at the bottom of the widget where it says “Widget logic”

    Thank you Alan, I really appreciate your answer. I have found posts that place the code in the functions.php, that’s why i asked.

    Plugin Author alanft

    @alanft

    Glad to help.

    if you have complex code it’s a good idea to bundle it up in a special function, put it in functions.php and then call that from the Widget Logic…

    eg in function.php
    function my_is_direct_child_of($id)
    { global $post;
    return ($post->post_parent==$id);
    }

    in widget logic: my_is_direct_child_of(1153)

    Doesn’t work for me, i just can’t get it to work. I have 3 levels of navigation, 1st level is the main navigation level, 2nd level there are two pages each with their own 3rd level subpages. I want to show the Facebook comments plugin on the 1st level (main nav) page including all of her descendants, no matter the depth. None of the suggestions work. I’ve tried different tricks from around the web, but i was not able to achieve this. I would like to avoid modifying the functions.php file if possible.

    I thought this would work, but it doesn’t:

    – return’s TRUE for all sub-pages of Parent pages ID’s 87, 342, 429, the page ID 87 being the top level main navigation page with no parent, and the page IDs 342 and 429 being child pages of page ID 87, (also having multiple subpages of their own):

    global $post; $ancestors = get_post_ancestors($post); $show_widgets_for = array(87, 342, 429); $show_widgets = FALSE; foreach ($show_widgets_for as $child) { if (in_array($child, $ancestors)) { $show_widgets = TRUE; break; } } return $show_widgets;

    It only shows the widget on the first child of the page ID 87, that being the page ID 342, and on the first child of the page ID 342, being ### ..

    Does not show the widget on all children, or descendants.

    Oh man.

    I have a theme that has custom widget groups that are hidden by default, that’s why i don’t see the changes.

    Yup. I need to get some sleep.

    I’m having trouble with understand conditional statements. I’d like say; if NOT home page, NOT page 86 and NOT 86 subpages. I’ve tried this without luck:

    !is_home() || !is_page( ’86’ ) || ’86’ == $post->post_parent

    Thanks for any direction. Wouldn’t it be great if there were a wordpress conditional statement builder tool?

    I tried adding this function to functions.php:

    function is_tree($pid) {      // $pid = The ID of the page we're looking for pages underneath
            global $post;         // load details about this page
            if(is_page()&&($post->post_parent==$pid||is_page($pid)))
                   return true;   // we're at the page or at a sub page
            else
                   return false;  // we're elsewhere
    };

    and then this to widget:

    !is_home() || !is_page( '86' ) || !is_tree('86')

    No cigar.

    I’ve also tried placing this in functions.php:

    function is_child($parent) {
      global $post;
      return $post->post_parent == $parent;
    }

    and this in widget:

    !is_home || !is_page( 86 ) || !is_child( 86)

    no good either

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘[Resolved] [Plugin: Widget Logic] Is there a "is_subpage" alternative?’ is closed to new replies.