lundi 26 janvier 2015

Use post in multiple places on a page with multiple posts


I have three custom post types: workouts, news_items, and business_items. I'm trying to display the top (most recent) item from each on the home page and I'm trying to put the featured picture from the WOD post on the top of the home page.


This is 90%, with code like this:



<?php
$args = array( 'post_type' => 'wod', 'posts_per_page' => 1 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) :
$loop->the_post();
$title = get_the_title();
$content = get_the_content();
$permalink = get_permalink( get_the_ID());
$image = get_the_post_thumbnail(get_the_ID(), 'medium', array( 'class' => 'img-thumbnail hidden-xs' ));
endwhile;
?>
<?php echo $image; ?><!-- I NEED THIS HERE -->
<?php
while (have_posts()) {
the_post();
get_template_part('content', 'page');
} //endwhile;
?>
<div class="box_content">
<a href="<?php echo $permalink ?>"><?php echo $title; ?></a>
<div class="entry-content">
<?php echo $content; ?><!-- I NEED THIS HERE -->
</div>
</div>
<!-- BUSINESS ITEM -->
<div class="box_content">
<?php
$args = array( 'post_type' => 'business_item', 'posts_per_page' => 1 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title( '<h3>', '</h3>' );
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile;
?>
<!-- NEWS ITEM -->
<div class="box_content">
<?php
$args = array( 'post_type' => 'news_item', 'posts_per_page' => 1 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title( '<h3>', '</h3>' );
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile;
?>


The biggest problem is that the workout post displays without markup -- a result of get_the_content() not applying filters. I have to fix that, but I'm pretty sure I'm not doing this efficiently or in a clean implementation and want to learn the best I can.


Full code is at: http://ift.tt/1tj8y6K





Aucun commentaire:

Enregistrer un commentaire