Advertisement
Ordene

Pagination not Working with WP_Query

May 13th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.78 KB | None | 0 0
  1. <?php get_header(); ?>
  2.     <div class="row">
  3.         <div class="large-4 columns">
  4.             <?php get_sidebar(); ?>
  5.         </div>
  6.         <div class="large-8 columns">
  7.             <h4>Últimas notícias</h4>
  8.             <ul class="no-bullet">
  9.                 <?php
  10.                     $args = array (
  11.                     'category_name'          => 'noticias',
  12.                     'pagination'             => true,
  13.                     'posts_per_page'         => '5',
  14.                     );
  15.                    
  16.                     $query = new WP_Query( $args );
  17.                    
  18.                     // Loop
  19.                     if ( $query->have_posts() ) {
  20.                         while ( $query->have_posts() ) { $query->the_post();
  21.                 ?>
  22.                        
  23.                         <li class="panel">
  24.                             <h5>
  25.                                 <a href="<?php the_permalink();?>"><?php the_title() ?>
  26.                             </h5>
  27.                             <p class="post-info"><?php the_time('F j, Y'); ?> | Por <a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>"><?php the_author(); ?></a> | Postado em
  28.                                 <?php
  29.                                     $categories = get_the_category();
  30.                                     $separator = ", ";
  31.                                     $output = '';
  32.                                     if ($categories) {
  33.                                         foreach ($categories as $category) {
  34.                                             $output .= '<a href="' . get_category_link($category -> term_id) . '">' . $category -> cat_name . '</a>' . $separator;
  35.                                         }
  36.                                         echo trim($output, $separator);
  37.                                     }
  38.                                 ?>
  39.                             </p>
  40.                             <hr />
  41.                             <p> <?php the_excerpt() ?>  </p>
  42.                            
  43.                             <a href="<?php the_permalink();?>" class="button radius">Ver notícia completa</a>
  44.                         </li>
  45.                     <!-- End of the Loop -->
  46.                         <li>
  47.                             <ul>
  48.                                 <li><?php next_posts_link( 'Older posts' ); ?></li>
  49.                                 <li><?php previous_posts_link( 'Newer posts' ); ?></li>
  50.                             </ul>
  51.                         </li>
  52.                     <?php   }   } else {    ?>
  53.                        
  54.                         <h5>Não foi encontrado o conteúdo desejado!</h5>
  55.                     <?php   }   wp_reset_postdata();    ?>
  56.             </ul>
  57.         </div>
  58.     </div>
  59. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement