WordPress.org

Ready to get started?Download WordPress

Forums

Widget Logic
[resolved] Shortcode for a parent page and it child pages (8 posts)

  1. valentino321
    Member
    Posted 2 years ago #

    I would like to know what is the shortcode to include a widget for a particular page like "product 1" and also to his child pages like "service A" + "service B" + "service C" + "service D", etc...

    Parent page + sub pages

    There ise a way to do it automatically, because i use this shortcode :

    is_page( array( 'product 1', 'service A', 'service B', 'service D', 'service E', 'service F', 'service G', 'service H', 'service I', 'service J', 'service K' ) ) AND MUCH MORE...

    But imagine you have 10 pages of products, and each product have 15 dedicated pages of servicies...It become difficult to write correctly shortcodes..

    There is an easier way to use shortcode than is_page( array ??

    Thank you !

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

  2. alanft
    Member
    Plugin Author

    Posted 2 years ago #

    There's an example on

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

    that will do most of the work for you:

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

  3. isle2isle
    Member
    Posted 1 year ago #

    But how does one put that into the widget? I'm trying to get a menu to appear only on a certain page and it's child pages.

  4. isle2isle
    Member
    Posted 1 year ago #

    OK, I added it and it now displays on the child page, but not on the paret. I've tried adding the parent,

    is_page('supplies')

    in a variety of ways but that just breaks stuff.

    Sorry to be a pest.

  5. alanft
    Member
    Plugin Author

    Posted 1 year ago #

    return is_page('supplies') || (in_array(77,get_post_ancestors($post)));

    should do it

  6. isle2isle
    Member
    Posted 1 year ago #

    that gave me parent, but not children :-(

  7. alanft
    Member
    Plugin Author

    Posted 1 year ago #

    is 77 the ID of the supplies page?

  8. isle2isle
    Member
    Posted 1 year ago #

    I finally got this to do it.
    (Replace '123' in the line below with the parent page ID number)

    global $post; return (is_page('123') || ($post->post_parent=="123"));

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic