• hilj

    (@hilj)


    Hello,
    I would like to trigger stuff when sub page is viewed. The article Mentions that theres no sub_page() and gives an option:

    <?php
    // Get $post if you're inside a function
    global $post;
    
    if (is_page() && $post->post_parent ) {
    	// This is a subpage
    } else {
    	// This is not a subpage
    }
    ?>

    I’m a bit confused how to use this?

    Say, if it would exist, this would be the case:

    <?php if (is_subpage('19'))
    		{
    		include(TEMPLATEPATH . '/header2.php');
    		}

    How should I incorporate the code in this? I tired wrap my head around it for some while with poor results.

    All help is appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter hilj

    (@hilj)

    Bumb. Anyone? This is an old one ??

    Hey hilj
    You may want to try this plugin:

    https://www.mossroot.com/worlds/wordpress-notes-and-plugins/sub-page-functions/

    On another note, if you need to pull a list of subpages from a different page (other than the one being viewed) you can do it this way.

    <?php // add subpage query
    query_posts(‘pagename=our-services’); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php endwhile; ?>
    <?php // add child / subpage list
    $children = wp_list_pages(‘title_li=&echo=0&child_of=’ . $post->ID);
    if ($children) { ?>
    <ul id=”servicelinks”>
    <?php echo $children; ?>

    <?php }
    ?>

    If you additionally want to pull the content from another page, then just add <?php the_content(); ?> the line after <?php while (have_posts()) : the_post(); ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘“There is no is_subpage() function yet”… how to use this?’ is closed to new replies.