PAGINACION DE POST WORDPRESS


/ Published in: PHP
Save to your folder(s)

Este código pagina los resultados de wordpress, según los parámetros que se le asignen a la clase WP_query.


Copy this code and paste it in your HTML
  1. <div class="overview">
  2.  
  3.  
  4. <div class="contenido">
  5. <?php
  6. $ppp = 3;
  7. $pag = $_GET['pag'];
  8. if($pag == "" || $pag == 1){
  9. $offset = 0;
  10. $pag = 1;
  11. } else {
  12. $offset = ($pag-1)*$ppp;
  13. }
  14.  
  15. $my_query = new WP_Query(array('category_name' => 'blog', 'posts_per_page' => $ppp, 'offset' => $offset));
  16. while ($my_query->have_posts()) : $my_query->the_post();
  17. $excerpt = get_the_excerpt();
  18. add_theme_support( 'post-thumbnails' );
  19. set_post_thumbnail_size( 145, 100, true ); // Normal post thumbnails
  20. add_image_size( 'single-post-thumbnail', 400, 9999 ); // Permalink thumbnail size
  21. ?>
  22. <div class="homepost">
  23.  
  24. <div class="thumb_a">
  25. <a title="<?php the_title(); ?>" rel="bookmark" href="<?php the_permalink(); ?>">
  26. <?php
  27. if(has_post_thumbnail()) {
  28. the_post_thumbnail(array(145,100));
  29. } else {
  30. echo '<img src="'.get_bloginfo("template_url").'/images/img-default.jpg" width="150" height="64" />';
  31. }
  32. ?>
  33. </a>
  34. </div>
  35.  
  36. <div class="rightcontp">
  37. <div class="bubble"><a title="Comentarios en <?php the_title(); ?>" class=" " href="<?php the_permalink(); ?>/#respond"><?php comments_number('0','1','+'); ?></a></div>
  38. <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
  39. <p><?php
  40. echo string_limit_words($excerpt,80);?>
  41. <?php
  42. //echo "<br />";
  43. //echo "<a href='" . get_permalink() . "'#more-$post->id\" class='linkseguirleyendo'><img src='".get_template_directory_uri()."/images/btonleermas.png' width='31' height='33' />Sigue Leyendo</a>";
  44. ?></p>
  45. <div class="post-meta">Publicado por <a href="<?php the_author_link(); ?>"><?php the_author_link(); ?></a> en <?php the_time('m/j/y g:i A') ?></div>
  46. </div>
  47.  
  48. </div>
  49.  
  50. <?php endwhile; ?>
  51.  
  52. </div>
  53. </div>
  54.  
  55. </div>
  56.  
  57.  
  58. <div class="paginacion_pos">
  59. <?php
  60. //OBTENGO LA CANTIDAD DE POST
  61. $p=0;
  62. $my_query = new WP_Query('category_name=blog&posts_per_page=100');
  63. while ($my_query->have_posts()) : $my_query->the_post(); ?>
  64. <?php $p++; ?>
  65. <?php endwhile; ?>
  66.  
  67. <?php
  68. //GENERANDO PAGINACION
  69.  
  70. //cantidad de paginas
  71. $x = $p / $ppp;
  72.  
  73. if( $x > 1) {
  74.  
  75. if ( $pag > 1 ) {
  76. echo "<span><a href='?pag=".($pag-1)."'>Anterior</a></span>-";
  77. }
  78.  
  79. for ( $k = 1; $k < $x; $k++ ) {
  80.  
  81. if( $k == $pag ) {
  82. echo $k;
  83. } else {
  84. echo "<span><a href='?pag=".$k."'>".$k."</a></span>-";
  85. }
  86.  
  87. }
  88.  
  89. if( $pag < $x ) {
  90. echo "<span><a href='?pag=".($pag+1)."'>Siguiente</a></span>-";
  91. }
  92.  
  93. }
  94. ?>
  95.  
  96. </div>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.