• Im hoping someone can help me out here, for all I know I am looking to do something that cant be done, or done efficantly anyway.

    So what I am trying to do is create a list of child pages under a parent page that displays links and excerpt of the page. The same as using the the_excerpt for categories, except for pages, basically…. Ive run a few searches and havent found anything. Any help would be appreciated.

    (Ive got the list displaying only child pages under the parent page, I just cant get the excerpt)

    Jer

Viewing 15 replies - 1 through 15 (of 15 total)
  • You will not get the excerpts for Pages. It just dosn’t work like that.
    Normally there is no ‘multi-Page’ display as in the case of ‘multi-post’ display (like category or monthly archives).
    So, unless you write a plugin or modify core files… give it up.

    Thread Starter jerxs

    (@jerxs)

    There is no way to grab an excerpt out of the pages and include one for each after the page link?

    Here is a good example, http://gotroutfishing.net/trout-fishing-tips/ , there has to be a simple solution, I know there does I just cant see it right now……..

    take a look at this and then look at the list of tips, the title is displayed, yet I cant figure out how to grab the first X ammount of carachters and display them along with the link.

    Do you know of a plugin? Do you know where I should start to modify the base code to do such a thing?

    Thanks again, Jer

    Your “good exaample” is absolutely NOT doing what you are talkong about. Or we see different blogs…
    It does not display Page excerpts because excerpts don’t work with Pages. I thought I was clear about it.
    Sorry, I don’t know what core files should be modified.

    Why not do it as Category pages and Category_Templates?

    Thread Starter jerxs

    (@jerxs)

    Yes It looks like I am going to have to use category_templates if I want to achieve what I am looking to do…..or maybe Ill I will just move forward with what I have and settle with just a list of page titles / links for the child pages under each parent.

    [quote]Your “good exaample” is absolutely NOT doing what you are talkong about. Or we see different blogs…[/quote]

    I should have been more clear, that is an example of what I have, what I am working with and was trying to show that my list is there, it shows only children of parent, but is lacking the excerpt, but its pretty clear its not as simple as I first thoght it would be…….

    Hi Jexs!

    I thinks that I am looking for the same solucion.

    I have 8 parents pages, that have few child pages, and in the overview of the section I want to list the chils pages titles with some text like the_except.

    I Found the plugin “Page Friendly Excerpt” in the Alesxking’s webpageand it works well.

    But it works only to see one page, but it doesn’t works in the wp_list_pages

    I thing that with the_loop it can be posible, but i don’t know a lot of PHP and I don´t know how can I do it.

    Anyone have any idea?

    Thanks a lot

    I think I might have a solution to this (WP v2.2):

    I have a parent page that has 5 children and I wanted to show the excerpt for each child page on the parent page. The first thing that I did was install a plug-in called Excerpt Editor. This plug-in enables you to create excerpts for pages as well as other helpful things that pertain to excerpts…

    After activating this plug-in ( and creating excerpts for all of it’s children ), I created a new template file and titled it “Summary Page”. I then applied this template to the parent page. This template consists of the following code:

    <div class="page">
    	<h3><?php the_title(); ?> <?php edit_post_link('Edit', '(', ')'); ?></h3>
    	<?php
    	$pageChildren = $wpdb->get_results("
    		SELECT *
    		FROM $wpdb->posts
    		WHERE post_parent = ".$post->ID."
    		AND post_type = 'page'
    		ORDER BY menu_order
    	", 'OBJECT');
    
    	if ( $pageChildren ) :
    		foreach ( $pageChildren as $pageChild ) :
    			setup_postdata( $pageChild );
    			?>
    
    		<h4><?php print '<a href="' . get_permalink( $pageChild->ID ) . '">' . get_the_title( $pageChild->ID ) . '</a>'; ?></h4>
    		<div class="entry">
    			<?php the_excerpt(); ?>
    		</div>
    
    		<?php
    		endforeach;
    	endif;
    	?>
    </div>

    Hope that someone finds this useful 🙂

    It was very helpful. It solved one of my problems. I’m still looking for a loop that can list the latest 5(or specified number) page titles with linking to their respective pages. thanks for sharing.

    Questions for mfields (and others in the know)

    1. What code did you use to apply the summary page template to the parent? (I’m just getting into php)

    2. On the site I will be creating, some of the child pages have child pages themselves and so I would like to be able to create a loop or something, that will only show the excerpts of child pages 1 level deep and if there are no child pages display normal page content. ie:

    If page has children {
    display the_excerpt(depth of 1) //I would probably put the TEMPLATEPATH link here and mod the code in summary.php
    }
    else {
    the_content();
    }

    I’m sure it’s something simple, but I can’t get the code right.

    3. The plugin outputs a heap of divs (I think more than any good css’er would need). Has anyone made any mods to the output markup?

    mfields said: I think I might have a solution to this (WP v2.2):

    This is very close to being just the right solution. 🙂

    I don’t know if it’s WordPress 2.3.1 which has broken it, but the excerpts this code presents seem to ignore my custom excerpts and create default ones from the content.

    You can see what’s happening on this site in development. The top half shows what I’m trying to achieve but it’s all manually coded into the post. The bottom half shows the auto-generated version using the code posted above. The first entry in the bottom half has a custom excerpt to match the hand-written version above. But instead I get the default.

    However, I can still view that custom excerpt in a normal page if I replace the_content() with the_excerpt() in the template.

    Anyone know what’s going wrong?

    I’m not sure if I made sense in the post above, so I’ve tweaked the example pages to illustrate where things are going wrong more succinctly.

    The parent page in the link displays a hard coded example of how I want the page to look. I’ve created excerpts for each child page to match and enabled html in the_ excerpt().

    Below the hard coded example are excerpts called by ‘mfields’ code listed earlier in this thread. As you can see, the excerpt is an auto generated excerpt using a portion of the post, ignoring my custom excerpt.

    However, if you click through to any of the child pages, you’ll see that WordPress is quite happy to display my custom excerpt in the_excerpt() within the loop.

    NB: I’ve used both advanced-excerpt and excerpt-editor plugins to create, manage and display html excerpts. WordPress 2.3.1 seems to be quite happy to display html excerpts without the use of either – unless my ISP is doing some funky caching thang.

    Does anyone know what’s going on?

    jamesbisset,

    Hi. I think I know why this is happening and the reason is a bit strange, but anyway, here’s what I found: $pageChild should be called $post. For some reason the setup_postdata() only seems to work when the variable passed to it is named $post. If it is named anything else, the_excerpt seems to fail. Note: if you are using any other loops on there page where this script runs… it is necessary to call unset($post) before and after this chunk of code. please see below:

    <div>
    	<?php unset( $post ); ?>
    	<h3><?php the_title(); ?> <?php edit_post_link('Edit', '(', ')'); ?></h3>
    	<?php
    	$childQuery = $wpdb->get_results("
    		SELECT *
    		FROM $wpdb->posts
    		WHERE post_parent = ".$post->ID."
    		AND post_type = 'post'
    		AND post_status = published
    		ORDER BY date_posted
    	", 'OBJECT');
    
    	if ( $childQuery ) :
    		foreach ( $childQuery as $post ) :
    			setup_postdata( $post );
    			print '<a href="' . get_permalink( $post->ID ) . '">' . get_the_title( $post->ID ) . ':</a> ';
    			the_excerpt();
    
    		endforeach;
    	endif;
    	unset( $post );
    	?>
    </div>

    please let me know what you think. this is working for me on v 2.3.1

    -mfields

    excentricjester,

    Hi.

    1. To apply the page template to the parent page, no code is needed just log into the wordpress admin section and edit the parent page. look on the right-hand sidebar of the edit screen and you should see a drop-down under the heading of “Page Template”. As long as you have saved the approiate code as a template file in your theme’s directory, the template should show up in the drop down list. If none of this made any sense, please see this page about creating page templates

    2. The query that I authored will only show childern for the given page that it is applied to. No grandchildren will show up. Hypotheticaly, you could set your second level page’s “Page Template” to summary also. this should work although I have not personally tried it. In the case that it does it might be a good idea to code some sort of “one-level up” and/or “root” type links.

    3. Do you mean the “Excerpt Editor” plugin? In the event that this plugin is causing trouble for you, you can delete it and use the new streamlined method:

    Copy and paste this code into your functions.php file and upload to you template directory…

    // Add Excerpts to pages in admin
    //---------------------------------------
    add_action( 'dbx_page_advanced', 'mfAddExcerpt2Pages' );
    function mfAddExcerpt2Pages(){
    	global $post;
    ?>
    	<div class="dbx-b-ox-wrapper">
    	<fieldset id="postexcerpt" class="dbx-box">
    	<div class="dbx-h-andle-wrapper">
    	<h3 class="dbx-handle"><?php _e('Optional Excerpt') ?></h3>
    	</div>
    	<div class="dbx-c-ontent-wrapper">
    	<div class="dbx-content"><textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt"><?php echo $post->post_excerpt ?></textarea></div>
    	</div>
    	</fieldset>
    	</div>
    <?php
    }

    Hope this answers all your questions…
    Good luck to you,
    -mfields

    Thanks mfields. 🙂

    I can see a plugin coming on…

    OK – I modified your query slightly using

    AND post_status = 'publish'
    ORDER BY menu_order

    and used $post.

    Same result as before – I get the auto-generated excerpts, not my explicit excerpts.

    FWIW, it works fine for me without using unset(). But I’m using this code in a template file outside and after the loop, so I don’t think there are any issues there.

    You’ve seen the thread I opened on exactly the issue of auto vs explicit excerpts. I’m still using your $pageChild successfully with Kafkaesqui’s recommended

    <?php echo apply_filters('the_excerpt', $pageChild->post_excerpt); ?>

    You can see the result here.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘List Pages With Excerpt Of Each Page’ is closed to new replies.