Advertisement
Guest User

loop no dups 2

a guest
Feb 16th, 2012
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.08 KB | None | 0 0
  1. <!-- Query - 1 post from each category no duplication -->
  2.         <!-- Featured is first -->
  3.         <?php $my_query = new WP_Query('category_name=featured&posts_per_page=1');
  4.           while ($my_query->have_posts()) : $my_query->the_post();
  5.           $do_not_duplicate = $post->ID; ?>
  6.             <?php
  7.                 // Get the ID of a given category
  8.                 $category_id = get_cat_ID( 'Featured' );
  9.                 // Get the URL of this category
  10.                 $category_link = get_category_link( $category_id );
  11.             ?>
  12.             <article>
  13.                 <header>
  14.                     <h1><a href="<?php echo esc_url( $category_link ); ?>">// Featured</a></h1>
  15.                 </header>
  16.                 <div class="related-thumb">
  17.                     <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail( 'cat-post-thumb'); ?></a>
  18.                 </div>
  19.                 <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
  20.                 <time datetime="<?php echo the_time('j-m-Y'); ?>" pubdate><?php echo ''.get_the_time('j').' '.''.get_the_time('M').' '.get_the_time('Y').''; ?></time>
  21.                 <p><?php the_excerpt(); ?></p>
  22.             </article>
  23.         <?php endwhile; ?>
  24.    
  25.         <!-- Top 3 -->
  26.         <?php $my_query = new WP_Query('category_name=top-three&posts_per_page=1');
  27.           while ($my_query->have_posts()) : $my_query->the_post();
  28.           $do_not_duplicate = $post->ID; ?>
  29.             <?php
  30.                 // Get the ID of a given category
  31.                 $category_id = get_cat_ID( 'top-three' );
  32.                 // Get the URL of this category
  33.                 $category_link = get_category_link( $category_id );
  34.             ?>
  35.             <article class="centre-margin">
  36.                 <header>
  37.                     <h1><a href="<?php echo esc_url( $category_link ); ?>">// Top Three</a></h1>
  38.                 </header>
  39.                 <div class="related-thumb">
  40.                     <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail( 'cat-post-thumb'); ?></a>
  41.                 </div>
  42.                 <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
  43.                 <time datetime="<?php echo the_time('j-m-Y'); ?>" pubdate><?php echo ''.get_the_time('j').' '.''.get_the_time('M').' '.get_the_time('Y').''; ?></time>
  44.                 <p><?php the_excerpt(); ?></p>
  45.             </article>
  46.         <?php endwhile; ?>
  47.    
  48.         <!-- Arts -->
  49.         <?php $my_query = new WP_Query('category_name=arts&posts_per_page=1');
  50.           while ($my_query->have_posts()) : $my_query->the_post();
  51.           $do_not_duplicate = $post->ID; ?>
  52.             <?php
  53.                 // Get the ID of a given category
  54.                 $category_id = get_cat_ID( 'Arts' );
  55.                 // Get the URL of this category
  56.                 $category_link = get_category_link( $category_id );
  57.             ?>
  58.             <article>
  59.                 <header>
  60.                     <h1><a href="<?php echo esc_url( $category_link ); ?>">// The Arts</a></h1>
  61.                 </header>
  62.                 <div class="related-thumb">
  63.                     <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail( 'cat-post-thumb'); ?></a>
  64.                 </div>
  65.                 <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
  66.                 <time datetime="<?php echo the_time('j-m-Y'); ?>" pubdate><?php echo ''.get_the_time('j').' '.''.get_the_time('M').' '.get_the_time('Y').''; ?></time>
  67.                 <p><?php the_excerpt(); ?></p>
  68.             </article>
  69.         <?php endwhile; ?>
  70.        
  71.         <!-- Arts > Galleries -->
  72.         <?php $my_query = new WP_Query('category_name=galleries&posts_per_page=1');
  73.           while ($my_query->have_posts()) : $my_query->the_post();
  74.           $do_not_duplicate = $post->ID; ?>
  75.             <?php
  76.                 // Get the ID of a given category
  77.                 $category_id = get_cat_ID( 'galleries' );
  78.                 // Get the URL of this category
  79.                 $category_link = get_category_link( $category_id );
  80.             ?>
  81.             <article>
  82.                 <header>
  83.                     <h1><a href="<?php echo esc_url( $category_link ); ?>">// Galleries</a></h1>
  84.                 </header>
  85.                 <div class="related-thumb">
  86.                     <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail( 'cat-post-thumb'); ?></a>
  87.                 </div>
  88.                 <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
  89.                 <time datetime="<?php echo the_time('Y-j-m'); ?>" pubdate><?php echo ''.get_the_time('j').' '.''.get_the_time('M').' '.get_the_time('Y').''; ?></time>
  90.                 <p><?php the_excerpt(); ?></p>
  91.             </article>
  92.         <?php endwhile; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement