WordPress.org

Support

Support » Themes and Templates » Add custom post above page content

Add custom post above page content

  • Having a problem with a page template. What I’m trying to do is get the content from a custom field to output above the page content. In other words, this:

    Page title

    Custom field output

    Page content

    What it’s doing is outputting the three custom post type entries as described, but then when it’s time to do the regular page content, it outputs the three custom posts again, but this time formatted like the page content was supposed to be.

    This is the code that I’m using to do this:

    [code moderated – the forum limit for posting is 10 lines – for more, please use the pastebin]

    What am I doing wrong? This should work…

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try not to overwrite the global $wp_query do something like this instead:

    <?php
    $wp_query->in_the_loop = true; $addedLoop = new WP_Query(); $addedLoop->query('post_type=site_updates&post_status=publish&paged=$paged&posts_per_page=3');
    // var_dump($addedLoop); - uncomment this to check the contents returned
    while ($addedLoop->have_posts()) : $addedLoop->the_post();
    
    <li><p class="smalltext"><B><?php the_time('F j, Y'); ?>, <?php the_time('g:i A'); ?></B> – <?php the_content(); ?></p></li>
    <?php
    endwhile;
    wp_reset_query();
    ?>

    ya

    That got it! Thanks much. You did leave out a ?> in your code, however, so here’s the final code that I ended up using:

    <?php
    $wp_query->in_the_loop = true; $addedLoop = new WP_Query(); $addedLoop->query('post_type=site_updates&post_status=publish&paged=$paged&posts_per_page=3');
    // var_dump($addedLoop); - uncomment this to check the contents returned
    while ($addedLoop->have_posts()) : $addedLoop->the_post(); ?>
    
    <li><p class="smalltext"><B><?php the_time('F j, Y'); ?>, <?php the_time('g:i A'); ?></B> – <?php the_content(); ?></p></li>
    <?php
    endwhile;
    wp_reset_query();
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add custom post above page content’ is closed to new replies.