• Resolved jeffmckeand

    (@jeffmckeand)


    Hello everyone!

    I’m developing a new site for an author, and have a main “Library” page on which to showcase all of the book’s she’s written. This Library page has child pages, each of which contains custom fields with information specific to a book, plus the description of the book in the main content field.

    I’ve written the following code to pull the information I need into a list on the Library page:

    <?php $parentID = 7;
    
    	$books = get_pages("child_of=$parentID");
    
    	foreach($books as $book) {
    
    		$bookCover = get_post_meta($book->ID, 'cover', true);
    		$bookDesc = get_post_meta($book->ID, 'short-description', true);
    		$bookTitle = get_the_title($book->ID);
    		$bookLink = get_permalink($book->ID);
    		$bookID = get_the_ID($book->ID);
    
    	if ($bookCover) {
    
    	?>
    
    	<li>
    		<img class="alignleft" src="<?php bloginfo('url'); ?><?php echo $bookCover; ?>" alt="<?php echo $bookTitle; ?>" title="<?php echo $bookTitle; ?>" />
    		<h2 id="page-id-<?php echo $bookID; ?>"><?php echo $bookTitle; ?></h2>
    		<p><?php echo $bookDesc; ?></p>
    		<a href="<?php echo $bookLink; ?>" title="View More & Order">View More & Order &raquo;</a>
    	</li>
    
    	<?php }
    
    	}
    
    ?>

    For now, as you can see, I’ve put a custom tag called “short-description” in each of the book pages to pull just that: a short description of the book. The author, however, would like to have the full description (from each book page’s main content field) on the Library page instead of the short description.

    The problem is that I can’t seem to find a way to pull that content within the function I’ve written above. Basically, I want $bookDesc to pull the child page’s content. Not sure I know how to do this…

    Any help? Thanks!

    EDIT: And yes, I know that I can put the full description in a custom field, but I’m trying not to put any redundant content on the pages, as the author will eventually be editing the content of her site.

Viewing 2 replies - 1 through 2 (of 2 total)
  • After this line:

    foreach($books as $book) {
    echo $book->post_content;

    Just a tip–use something like this after your foreach to ‘find out’ what’s in an object:

    echo "<pre>"; print_r($book); echo "</pre>";

    Thread Starter jeffmckeand

    (@jeffmckeand)

    Exactly what I was looking for. Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Add Content from Child Pages?’ is closed to new replies.