Viewing 2 replies - 1 through 2 (of 2 total)
  • From the Codex page:
    is_single()
    When any single Post page is being displayed.

    is_page()
    When any Page is being displayed.

    For your subpages, the following sample code was provided:

    <?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
    }
    ?>

    Your code should work. But what I am wondering is if you placed it inside the template for pages as well because in difference to your writing, the single page does not have the title working as intended as well.

    I am having issues as well getting is_page working. Here’s my sidebar code:

    <div id="Sidebar">
      <div id="Sidebar-in">
        <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
    
    	<!-- start page relevant content -->
    	<?php
    		if (is_page('compounding'))
    		{
    			echo '1';
    		}
    		else
    		{
    			echo '2';
    		}
    	?>
    
    	<!-- list Categories-->
        <h2><?php _e('Categories'); ?></h2>
        <ul>
          <?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?>
        </ul>
    
    	<!-- list Archives -->
        <h2><?php _e('Archives'); ?></h2>
        <ul>
          <?php wp_get_archives('type=monthly'); ?>
        </ul>
    
        <?php endif; ?>
      </div><!-- end #sidebar-in -->
    </div><!-- end #Sidebar -->

    The echo numbers are just for testing and will be replaced with content. However, this doesn’t seem to work. The page slug is compounding and it is a parent page. You can see it here.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘is_page() not working’ is closed to new replies.