0

Forgive my ignorance in wordpress, but I'm not finding the information I am looking for.

What I am trying to do is (on an existing site) remove dropdowns from navigation by creating landing pages. In example for about in the navigation instead of having a drop down (about > founding in example) when the user clicks on about they should be going to a landing page. This landing page would have excerpts of the pages that were links in the dropdown nav originally. In example, there would be a featured image, the excerpt and a read more link to the page founding in the above example. The challenge I am having is gathering the excerpt of a page and linking to it (via the read more link), and I'd like to avoid converting it to a post if at all possible.

I'd also love help figuring out how to grab the featured image but believe I could discover that on my own.

  • Are the pages hierarchical? Meaning, is 'founding' a child of the 'about' page? – Steven Mar 18 '15 at 21:59
  • yes, exactly. I'm trying to remove the hierarchy from navigation, and instead reflect it on the parent about page, with a linked excerpt for each 'child' if that makes sense. – NathanKTC Mar 18 '15 at 22:01
0

You can get an array of child pages using get_children. Use the parent page's ID as post_parent.

Once you have the array, you can loop through them and display whatever info you want. For example, to show the page title (linked) and the excerpt you could do:

$args = array(
    'post_parent' => $post -> ID
);
$children = get_children( $args );

if( $children ):
    foreach( $children as $child ):
        $permalink = get_permalink( $child -> ID );
        echo '<a href="' . $permalink . '">' . $child -> post_title . '</a>';
        echo $child -> post_excerpt
    endforeach;
endif;

You mentioned using the read more link - that's actually added to the post content, not the excerpt.

How to use 'Read More' - create a loop

Get the children as above but create a loop from the results. Using the_content() will show the truncated content where you have added a 'Read More' marker. Do this instead of the if statement above.

foreach ( $children as $child ) : setup_postdata( $child );
  the_content();
endforeach; 
wp_reset_postdata();

You can see more examples on the get_posts page

|improve this answer|||||
  • Thanks for this answer, it certainly seems we are going in the right direction, the issue I see here is that it is written for posts where I am using custom pages as the children and that is what has me caught up – NathanKTC Mar 18 '15 at 22:52
  • nope, this is for pages. If you're using a custom post type, then just specify that in the get_children $args: 'post_type' => 'custom_post_type'. (Post can't have children - they're non-hierarchical) – Steven Mar 18 '15 at 22:58
  • awesome, let me give it a shot then – NathanKTC Mar 19 '15 at 16:52
  • this is working to some extent but it is not creating the excerpt, it is creating links out of all the titles of the children however. All the children are pages, some of which are made with custom unique custom templates. Any ideas? – NathanKTC Mar 19 '15 at 17:08
  • Perhaps there's a mis-understanding of the Wordpress terminology, the excerpt is a manually added summary of the article, while 'Read More' placed in the content. I've updated the answer to include 'Read More' – Steven Mar 19 '15 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.