Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Loops, Pagination, and get_posts

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #174258
    herbyderby
    Participant

    Hello all,

    I am having the hardest time simply paginating a category of posts. I’ve looked at many forums, codexes, and Google results to no avail. What the heck am I doing wrong here?

    The code:

    <?php if ( have_posts() ) : ?>
            
        <?php while ( have_posts() ) : the_post(); /* THE LOOP */ ?>
    
    <div id="pageHeader"><?php the_block('Page Header'); ?></div>
    
    <div id="pageEntry" class="group">
        <div class="inner group">
    
            <h2 class="pageTitle"><?php the_title(); ?></h2>
    
                    <?php $posts = get_posts("posts_per_page=5&cat=15,22"); ?>
                        <?php if( $posts ) : ?>
                            <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
                            
                <article class="projects group">
                    <div class="leftProjCol group"><?php echo get_the_post_thumbnail($post->ID, 'feat-thumb'); ?></div>
                    <div class="rightProjCol">
                        <h2 class="projectTitle"><a href="<?php echo get_permalink(); ?>"><?php echo $post->post_title; ?></a></h2>
                        <div class="thePost">
                            
                                        <p><?php
                                          $excerpt = get_the_excerpt();
                                          echo string_limit_words($excerpt,60);
                                        ?>&nbsp;</p>
                            
                            <?php //echo apply_filters('the_content', $post->post_content); ?>
                            
                        </div>
                        <a class="readOn" href="<?php echo get_permalink(); ?>">Read More</a>
                    </div>
                </article>
                    <?php /* Keep these three lines out to separate each article */ ?>
                    <?php endforeach; ?>
                    <?php endif; ?>
                    <?php wp_reset_postdata(); #clean up ?>
                    
                    <div id="pagWrap" class="group"><span class="prev"><?php previous_post_link('%link', 'Previous in category', TRUE); ?></span><span class="next"><?php next_posts_link(); ?></span></div>
                    
        </div>
    </div>
    
    <?php endwhile; ?>
    <?php endif; ?>

    Thanks in advance.

    #174516
    mcjohnst
    Participant

    I’d recommend converting this over to using WP_Query along with properly set paged params.

    http://codex.wordpress.org/Class_Reference/WP_Query

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.