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.

I'm managing a movie related site.. I'm using yoast's simple taxonomies plugin to classify my content with Artists, Genre (action, horror, comedy, drama etc..), Director, Writer etc...

On a specific page (template), I want to pull last 5 posts with only their titles from custom taxonomies.. how can I pull last 5 titles from Action, Comedy or Horror taxonomies as list?

I will try to get an output like http://tutsplus.com/

Thanks

share|improve this question
    
genre is the taxonomy and Action, Comedy or Horror are terms in that taxonomy? –  Bainternet Jun 5 '11 at 16:49
add comment

2 Answers

up vote 1 down vote accepted

create additional loops in your template, selecting the taxonomy and term you'd like to limit display to for each. for instance, this will pull the last 5 posts from taxonomy "genre", term "action":

<?php

$args = array( 'taxonomy'=>'genre','term'=>'action','posts_per_page'=>5 );
$action_films = new WP_Query( $args );

while( $action_films->have_posts() ) : $action_films->the_post();
    echo '<li>';
    the_title();
    echo '</li>';
endwhile;

?>
share|improve this answer
    
Im still kind of new to the whole php stuff but why not use a for each statement? –  xLRDxREVENGEx Jun 5 '11 at 16:51
    
@xLRDxREVENGEx - I guess you could use a foreach, though you'd have to do foreach $results->posts as $item since the results are an object containing an array of posts, not just a flat array. you'd still have to call $results->the_post() to set up the data properly for all the template functions. I sometimes use a foreach if I'm accessing data directly from the object, but otherwise while is simpler, and what WordPress uses in their code and docs. –  Milo Jun 5 '11 at 17:16
    
great!.. that was exactly what I wanted.. just forgot to mention permalink.. but Bainternet provided related code.. thanks :) –  teja Jun 5 '11 at 17:58
add comment

alternative approach :

$genres = array('action','drama','horror','comedy');
foreach ($genres as $genre){
    $query = new WP_Query( array( 'posts_per_page' => 5, 'genre' => $genre ) );
    echo '<div class="genre-list"><ul>';
    while ($query->have_posts()){
        $query->the_post();
        echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
    }
    echo '</ul></div>';
    wp_reset_query();
}
share|improve this answer
    
thanks for this approach also.. :) –  teja Jun 5 '11 at 17:58
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.