Support » Fixing WordPress » Individual post pages custom content

  • Resolved Richard Sweeney


    Apologies if this has already been answered elsewhere, but I haven’t been able to turn up anything yet.

    I’m using WP as a CMS for a website I’m working on (still locally, nothing online to show as yet!). I’m displaying posts on a page called ‘news’ (that’s all working fine) but I want to add some additional HTML to the pages where the individual posts are shown.

    Basically, all I want to do is to link back to the ‘news’ page from the child pages (the individual posts). But I obviously don’t want the link to appear on the parent page (the news page).

    I’ve found a (seemingly working) function to find sub-pages:

    function is_subpage() {
     global $post; // load details about this page
     if ( is_page() && $post->post_parent ) { // test to see if the page has a parent
          	$parentID = $post->post_parent; // the ID of the parent is this
            return $parentID; // return the ID
    	} else { // there is no parent so...
          	return false; // ...the answer to the question is false

    But have not been able to get it to work – I’ve tried using the following code:

    <?php if(is_subpage('news')) : ?>
    <p><a href="<?php bloginfo('url') ?>/news/">Read all news stories</a></p>
    <?php endif; ?>

    Any help greatly appreciated!

Viewing 6 replies - 1 through 6 (of 6 total)
  • equalmark


    So have you got a page called ‘News’ and you have set this as your posts page in the WordPress ‘Reading’ setting page?


    Yeah exactly. My page called ‘news’ displays the posts.



    That page is therefore controlled by your themes index.php file. Therefore if you add the following:

    <p><a href="<?php bloginfo('url') ?>/news/">Read all news stories</a></p>

    before the end of the loop inside <div class="post"> it should do the trick.

    thanks for this, I guess I’m not explaining myself very well!

    I don’t want the hyperlink to appear on the ‘news’ page, but I want it to appear on any child pages.

    For example: the page:

    shouldn’t have the link, but the page:

    should have the link. Know what I mean?




    Add it to single.php then in the same place.

    Now I’m just flaunting my inexperience! I didn’t have a single.php page for the site, I do now and all is as it should be!

    Many thanks equalmark, most helpful!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Individual post pages custom content’ is closed to new replies.