Advertisement
Guest User

dudd

a guest
Jan 10th, 2011
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. <?php
  2. //get all post IDs for posts beginning with cap B, in title order,
  3. //display posts
  4.  
  5. $first_char = 'B';
  6.  
  7. $postids=$wpdb->get_col($wpdb->prepare("
  8. SELECT ID
  9. FROM $wpdb->posts
  10. WHERE SUBSTR($wpdb->posts.post_title,1,1) = %s
  11. ORDER BY $wpdb->posts.post_title",$first_char));
  12.  
  13. if ($postids) {
  14. $args=array(
  15. 'post__in' => $postids,
  16. 'post_type' => 'post',
  17. 'post_status' => 'publish',
  18. 'cat'=>13, //List posts only from category 13
  19. 'posts_per_page' => -1,
  20. 'caller_get_posts'=> 1
  21. );
  22. $my_query = null;
  23. $my_query = new WP_Query($args);
  24. if( $my_query->have_posts() ) {
  25. echo 'Posts that begin with '. $first_char;
  26. ?>
  27. <?php while ($my_query->have_posts()): $i++; if(($i % 2) == 0) : $my_query->the_post(); ?>
  28.  
  29. <li><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
  30.  
  31. <?php
  32.  
  33. endif; endwhile;
  34. $i = 0;
  35.  
  36. }
  37. wp_reset_query(); // Restore global post data stomped by the_post().
  38. }
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement