I made a page called blog.php which will store my blog entries, all the other pages have a custom post type called "Page Content" (for static content). I wanted to make a heading in this blog page which is retrieved from main loop of the current page (the_content
), and used a get_posts
to retrieve the blog entries.
I tried doing the opposite: using get_posts
to get the_content
of the current page but it retrieved the_content
of the blog entries. (and using the main loop to retrieve the posts).
Will I have problems by using this method? Is there a better way to do this?
The desired result:
<?php
/**
* Template Name: Blog
* @package WordPress
* @subpackage Prominent
* @since Prominent 1.0
*/
get_header(); ?>
<div class="shadow-top">
<!-- Shadow at the top of the slider -->
</div>
<div id="intro2">
<div class="container">
<?php // Start the Main Loop
if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="content">
<h2><?php the_content(); ?></h2>
</div><!-- .content -->
<?php endwhile; ?>
<?php endif; ?>
</div><!-- #slider-wrapper -->
</div><!-- .container -->
</div><!-- #featured -->
<div class="shadow-bottom">
<!-- Shadow at the bottom of the slider -->
</div>
<div id="content">
<div class="container">
<?php // Create custom loop
$custom_posts = get_posts(); // Defaults args fetch posts starting with the most recent ?>
<?php foreach( $custom_posts as $post ) : setup_postdata( $post ); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?>
<?php endforeach; ?>
<?php wp_reset_query(); ?> </div><!-- .container -->
</div><!-- #content-bottom -->
<?php get_footer(); ?>