Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This is a page that list posts witht he category Content (CDs):

<div id="tagline">
    <div class="container">
        <?php // Run main loop (The Loop). ?>
        <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
        <div class="content0">
            <?php the_content(); // <- I want to get this ?>
        </div>
        <?php endwhile; ?>
    </div><!-- .container -->
</div><!-- #content-bottom -->
<div id="content">
    <div class="container">
        <div id="mainbar">
            <?php $custom_posts = new WP_Query(); ?>
            <?php $custom_posts->query('category_name=Content (CDs)'); ?>
            <?php while ($custom_posts->have_posts()) : $custom_posts->the_post(); ?>
                <div class="content-block-4">
                    <h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                    <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail('large'); ?></a>
                    <p><?php the_content(); ?></p>
                </div>
            <?php endwhile; ?>

single.php has the following:

    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    <div class="content0">
        <?php $parent = get_post($post->post_parent); ?>
        <?php $parent->post_content; ?>
    </div>
    <?php endwhile; ?>

But still can't get the_content of the parent page.

Any suggestions?

share|improve this question
    
It could do with the fact that posts have no parent where as pages do? –  Bainternet Apr 12 '11 at 6:34
    
@Bainternet I've tested posts parents, for instance with the bbPress 'Forum' custom post type. Effectively the 'Reply' custom post type act as their children (I'm not very sure). –  janoChen Apr 12 '11 at 14:59
    
ok, thats a custom post type, not posts. –  Bainternet Apr 12 '11 at 17:12
    
Shouldn't there be an echo infront of $parent->post_content;(assuming you want to output it), did you just forget to put that in what you posted? –  t31os Apr 12 '11 at 17:47
add comment

1 Answer

up vote 2 down vote accepted

I think you need to do two things

  1. add 'echo' to last line

<?php echo $parent->post_content; ?>

  1. add 'global $post;', before accessing the $post.

let me know if this does not work.

share|improve this answer
    
+1 - Should of scrolled down the screen before posting my comment. –  t31os Apr 12 '11 at 17:48
    
Though i personally don't think the global is necessary, it will likely work as is, $post usually has scope inside template files. –  t31os Apr 12 '11 at 17:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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