Page pagination category.php in WordPress

1

I'm trying to turn paging of WordPress into a category.php file for a theme, but the paging links do not appear. For the little I researched, it would have something to do with using custom queries, but I did not quite understand its usage.

How could I enable paging (either native or with the WP PostNavi plugin) in the code on my page, shown below?

<?php get_header(); ?>  
  <main>
  <div id="content_internas">
    <div id="lista_noticias">
      <h2><span><?php echo strtoupper(single_cat_title( '', false )) ?></span></h2>
      <ul>
          <?php $posts = get_all_posts(null, get_cat_id( single_cat_title("",false) )); ?>

          <?php foreach($posts as $key => $post): ?>
        <li>
          <a href="<?php the_permalink() ?>">
            <?php if (function_exists('has_post_thumbnail')) {
              if (has_post_thumbnail()) { ?>
              <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(array(460, 300, true)); ?></a>
              <?php } } ?>
          </a>
          <br />
          <span><?php the_time('j F') ?></span>
          <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
          <p><?php the_excerpt(); ?></p>
        </li>
        <?php endforeach; ?>
      </ul>
      <div class="paginacao">
        <?php if(function_exists('wp_pagenavi')) : ?>
          COM PLUGIN
          <?php wp_pagenavi() ?>
        <?php else : ?>
          SEM PLUGIN
          <div class="maisantigos"><?php next_posts_link(__('&laquo; Mais antigos','arclite')) ?></div>
          <div class="maisrecentes"><?php previous_posts_link(__('Mais recentes &raquo;','arclite')) ?></div>
        <?php endif; ?>
      </div>
      <!--<center><a href="#" id="veja_mais">MAIS NOTÍCIAS</a></center>--><br> <br>
    </div>
  </div>
</main>
<?php get_footer(); ?>
    
asked by anonymous 07.08.2014 / 15:37

1 answer

4

There is no get_all_posts() function in WordPress, try searching for it: link

It is probably some custom function, where the global variable $wp_query is not configured and therefore does not work paging.

How you want to use category.php correct is to use the native WordPress query. In case just use as:

<?php get_header(); ?>
<main>
<div id="content_internas">
    <div id="lista_noticias">
        <h2><span><?php echo strtoupper(single_cat_title( '', false )) ?></span></h2>
        <ul>
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <li>
                <a href="<?php the_permalink() ?>">
                    <?php if ( has_post_thumbnail() ) : ?>
                        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( array( 460, 300, true ) ); ?></a>
                    <?php endif; ?>
                </a>
                <br />
                <span><?php the_time( 'j F' ); ?></span>
                <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
                <p><?php the_excerpt(); ?></p>
            </li>
            <?php endwhile; else: ?>
                <li><?php _e( 'Sorry, no posts matched your criteria.' ); ?></li>
            <?php endif; ?>
        </ul>
        <div class="paginacao">
            <?php if ( function_exists( 'wp_pagenavi' ) ) : ?>
                COM PLUGIN
                <?php wp_pagenavi() ?>
            <?php else : ?>
                SEM PLUGIN
                <div class="maisantigos"><?php next_posts_link(__('&laquo; Mais antigos','arclite')) ?></div>
                <div class="maisrecentes"><?php previous_posts_link(__('Mais recentes &raquo;','arclite')) ?></div>
            <?php endif; ?>
        </div>
    </div>
</div>
</main>
<?php get_footer(); ?>

You can find more details on working with the WordPress loop here .

Note 1: In your code you tested whether the has_post_thumbnail() function existed, note that it was implemented in < a WordPress 2.9 , which had its release date on December 18, 2009. In other words, you never need to test if there is one. , no one will be using a WordPress so outdated so.

Note 2: If you want, you do not have the slightest need to use WP-PagiNavi, at least not since January 22, 2007 when WordPress 2.1 and the paginate_links() function has been implemented.

    
07.08.2014 / 22:08