Advertisement
rtsaboya

Categorizar posts por ano

Aug 11th, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. <?php get_header(); ?>
  2.  
  3.     <div id="content" class="col">
  4.         <?php if (have_posts()) : ?>
  5.        
  6.             <?php while (have_posts()) : the_post(); ?>
  7.            
  8.                 <div class="col last">
  9.                     <h2><?php the_title(); ?></h2>
  10.                     <?php edit_post_link('Editar','<div class="meta_pesquisa">','</div>'); ?>
  11.                     <?php the_content('Continue reading...'); ?>
  12.                     <?php $lista_categorias= get_post_meta($post->ID,'categorias',true);
  13.                     If ($lista_categorias) {
  14.                         $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  15.                         $myposts = get_posts("cat=$lista_categorias&showposts=10&paged=$paged");
  16.                         foreach($myposts as $post) :
  17.                             setup_postdata($post);
  18.                             $ano = get_the_time('Y');
  19.                             insere_ano_pesquisa($ano);
  20.                            
  21.                             ?>
  22.                            
  23.                             <h2 class="pesquisas"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
  24.                             <div class="meta_pesquisa">
  25.                             <?php
  26.                             the_time('F Y');
  27.                             echo ' | ';
  28.                             the_tags();?>
  29.                             </div>
  30.                             <?php
  31.                             the_excerpt();?>
  32.                             <p><a href="<?php the_permalink(); ?>">Ver mais detalhes</a></p>
  33.                             <?php
  34.                         endforeach;                
  35.                     }
  36.                     ?>
  37.                 </div>
  38.                
  39.             <?php endwhile; ?>
  40.        
  41.         <?php else : ?>
  42.        
  43.             <h3>Page Not Found</h3>
  44.             <p>Sorry, but you are looking for something that isn't here.</p>
  45.            
  46.         <?php endif; ?>
  47.        
  48.     </div>
  49.  
  50.     <hr />
  51.  
  52. <?php // get_sidebar(); ?>
  53.  
  54. <?php get_footer(); ?>
  55.  
  56.  
  57. //ATENÇÃO! COLAR O CÓDIGO ABAIXO NO ARQUIVO FUNCTIONS.PHP DO SEU TEMA
  58. <?php
  59. function insere_ano_pesquisa($ano){
  60. global $post, $anoanterior;
  61. If ($ano!==$anoanterior) {
  62.     echo '<h2 class="ano">'.$ano.'</h2>';
  63. }
  64. $anoanterior=$ano;
  65. }
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement