WordPress.org

Ready to get started?Download WordPress

Forums

Displaying Posts with Custom Taxonomies (3 posts)

  1. brisimmons105
    Member
    Posted 3 years ago #

    Hello, I've got a quick question...I haven't been able to get an answer on this, I'm hoping that posting it here will help.

    I've got a loop that is going through my categories and displaying posts with a custom taxonomy 'session' called 'session1'....is there a way to limit this by only 1 post per category?

    Can anyone help me? Please!? I'm begging here :)
    Thanks

    See my code below:

    <?php
    $args=array(
    //   avoid duplicate posts
    post__not_in => $ids,
    taxonomy => 'session',
    term => 'session1',
    //   PAGANATION FIX
    paged=>$paged,
    );
    query_posts($args);
    if (have_posts()) :
    echo
    '<div id="mydiv">
    <ul id="mylist">';
    $count = 0;
    while (have_posts()) : the_post();
    $count++;
    echo'<li id=mylist-'.$count.'>';
    $ids[] = get_the_ID();
    ?>
    <span>
    <h2><?php the_title();?></h2>
    <p><?php the_excerpt(); ?></p>
    </span>
    <?php
    echo'</li>';
    endwhile;
    echo '</ul><!– //mylist –></div><!– //mydiv –>';
    endif;
    ?>
  2. brisimmons105
    Member
    Posted 3 years ago #

    I've updated my code to use wp_query rather than query_posts..
    Still wondering the same question as above....

    A little help?

    <?php
    $args=array(
      'session' => 'rhythm-and-roots-2010',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'Artists';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  3. cangpo
    Member
    Posted 3 years ago #

    <?php $args = array (
    'taxonomy' => 'session'
    );
    $categories = get_categories($args);
    foreach ($categories as $cat) : ?>
    <?php $index_query = new WP_Query('post_type=post&showposts=1&session='.$cat->slug.''); ?>
    <?php while ($index_query->have_posts()) : $index_query->the_post(); ?>
    <p><a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    <?php endwhile; ?>
    <?php endforeach; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic