Advertisement
FireBot

wpdb-post-excerpt

Feb 13th, 2014
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. <?php
  2. $years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE  post_status = 'publish' ORDER BY post_date DESC");
  3.  
  4. foreach($years as $year) : ?>
  5.  
  6.     <h4><?php echo $year; ?></h4>
  7.     <?php  $theids = $wpdb->get_results("
  8.         SELECT ID, post_title, post_excerpt
  9.         FROM $wpdb->posts
  10.         INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)
  11.         INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
  12.         WHERE post_status = 'publish'
  13.         AND YEAR(post_date)= '".$year."'
  14.         AND $wpdb->term_taxonomy.taxonomy = 'category'
  15.         AND $wpdb->term_taxonomy.term_id IN ('1')
  16.         ORDER BY post_date ASC
  17.     ");
  18.     foreach ($theids as $theid): ?>
  19.         <div class="news">
  20.         <h2><a href="<?php bloginfo('url'); ?>?p=<?php echo $theid->ID; ?>"><?php echo $theid->post_title; ?></a></h2>
  21.                
  22.         <?php echo $theid->the_excerpt; ?>
  23.                
  24.         <a href="<?php bloginfo('url'); ?>?p=<?php echo $theid->ID; ?>" class="s-btn">Read More &raquo;</a>
  25.                
  26.         <hr />
  27.         </div>
  28.     <?php endforeach; ?>
  29.            
  30. <?php endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement