Ok, I figured out how to get it working, so I'll post the answer here. However, I thought I should be able to use the normal WP template tags like the_title();
and the_excerpt();
within a get_posts()
loop? Am I doing this the right way or can I improve this answer?
Thanks
Osu
/* ****************************************************************** */
/* !BOX LAYOUT */
/* ****************************************************************** */
// Function to create boxes
function osu_fbox($day, $cpt, $tax, $term) {
// Filter posts
$args = array(
'post_type' => $cpt,
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => $tax,
'field' => 'slug',
'terms' => $term
)
)
);
$posts = get_posts( $args );
// print_r($posts);
// echo 'COUNT: ' . count($posts);
// Display content for this box
echo '<p class="fheading">' . $day .'</p>';
if (count($posts) > 0) :
foreach ( $posts as $post ) : setup_postdata( $post );
$id = $post->ID;
$title = $post->post_title;
$excerpt = $post->post_excerpt;
$pl = get_permalink( $post->ID );
?>
<div id="lk-<?php echo sanitize_title($day); ?>-post-<?php echo $id; ?>">
<h2><a href="<?php echo $pl; ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'literarykitchen' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark" class="readmore"><?php echo $title; ?></a></h2>
<?php echo $excerpt; ?>
<a href="<?php echo $pl; ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'literarykitchen' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark" class="readmore">Read more...</a>
</div>
<?php endforeach; ?>
<?php else: ?>
<p>No festival items currently scheduled</p>
<?php endif; wp_reset_query(); // Reset query so we can go again
}
// ------------------------------------------------------------------
// // !BOXES
// ------------------------------------------------------------------
// CPT and taxonomy
$cpt = 'lkfestival';
$tax = 'lkdays';
// Start if password protected
if ( post_password_required() ) : ?>
<p>We are currently working on the festivals area.</p>
<p>Please check back soon</p>
<?php echo get_the_password_form(); ?>
<?php else: ?>
<div id="weekdays" class="fcol">
<?php echo osu_fbox( 'Monday', $cpt, $tax, 'monday' ); ?>
<?php echo osu_fbox( 'Tuesday', $cpt, $tax, 'tuesday' ); ?>
<?php echo osu_fbox( 'Wednesday', $cpt, $tax, 'wednesday' ); ?>
<?php echo osu_fbox( 'Thursday', $cpt, $tax, 'thursday' ); ?>
<?php echo osu_fbox( 'Friday', $cpt, $tax, 'friday' ); ?>
</div> <!-- End #weekdays -->
<div id="saturday" class="fcol">
<?php echo osu_fbox('Saturday', $cpt, $tax, 'saturday' ); ?>
</div> <!-- End #saturday -->
<div id="sunday" class="fcol">
<?php echo osu_fbox('Sunday', $cpt, $tax, 'sunday' ); ?>
</div> <!-- End #sunday -->
<?php endif; /* End if post password protected */ ?>