WordPress.org

Ready to get started?Download WordPress

Forums

pagination not working on page with shortcode (9 posts)

  1. morganictrie
    Member
    Posted 1 year ago #

    I created a short code and function to pull all posts from a certain category. Then one page called that short code (to act as a more robust archive page if you will). But pagination is not appearing at the bottom of the page. The first 10 entries appear, but there are 12 (and continue to be more). I've tried some of the other solutions but nothing seems to work. I am not sure if this is because of the short code element.

    Any thoughts?

    function AnnualReportShortcode() {
    	$args=array(
    		'cat' => 22
    	);
    	$the_query = new WP_Query($args);
    	while ($the_query->have_posts()) : $the_query->the_post();
    ?>
    <div class="annual_report">
        <h3><a>" rel="bookmark"><?php the_title(); ?></a></h3>
        <p><?php the_excerpt() ?><br clear="all"/></p>
    </div>
    <?php
    	endwhile;
    }
    add_shortcode('annualreport', 'AnnualReportShortcode');
    ?>
  2. morganictrie
    Member
    Posted 1 year ago #

    I've updated it to this, which is sort of working. It does limit the number of posts and when I manually change the page number in the URL it works, but the pagination navigation is still not appearing.

    <?php
    function AnnualReportShortcode() {
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	$args=array(
    		'cat' => 22,
    		'posts_per_page' => 5,
    		'paged' => $paged
    	);
    	$the_query = new WP_Query($args);
    	while ($the_query->have_posts()) : $the_query->the_post();
    ?>
    <div class="annual_report">
        <h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
        <p><?php the_excerpt() ?><br clear="all"/></p>
    </div>
    <?php
    	endwhile;
    }
    add_shortcode('annualreport', 'AnnualReportShortcode');
    ?>
  3. keesiemeijer
    moderator
    Posted 1 year ago #

    I don't think you can paginate a shortcode inside a loop, but maybe I'm wrong. Normally only one loop can be paginated in a theme template file.

    Try one of these functions in the AnnualReportShortcode function: http://codex.wordpress.org/Pagination#Function_Reference

    Why are you using a shortcode for this?

  4. morganictrie
    Member
    Posted 1 year ago #

    I'm looking at page now....and also found some of your comments on other posts.

    I'm realizing that I may have to figure out how to make this into a template file. I've just given that my first shot, but still not page numbers. This would be my first attempt at creating a custom template so I was kind of trying to avoid that. (I'm using Woo Themes Canvas, by the way.)

    So I wrote this loop and then on the page listing the annual reports and then on the page had nothing more than [annualreport].

    Any thoughts would be fantastic as I'm feeling a little muddled down in all the different options and figuring out which is best.

  5. keesiemeijer
    moderator
    Posted 1 year ago #

    I'm realizing that I may have to figure out how to make this into a template file. I've just given that my first shot, but still not page numbers.

    Have you looked at creating a custom Page template file?

    If you did can you paste and submit the full code of the Page template file where pagination is not workink into a pastebin.com and post the link to it here? see the Forum Rules for posting code and using the pastebin.

  6. morganictrie
    Member
    Posted 1 year ago #

    http://pastebin.com/2PnUb1LQ

    Above is my pastebin.com code for a template. Everything from #main div above and from /#main div below is copy and pasted from the existing blog template found in the themes/canvas/template-blog.php folder (which has pagination when viewed but I saw no reference to it in the template-blog.php file).

    Thanks!

  7. keesiemeijer
    moderator
    Posted 1 year ago #

    try to put this:

    <?php posts_nav_link(); ?>

    after this:

    <?php endwhile; ?>
  8. morganictrie
    Member
    Posted 1 year ago #

    That worked!

    While I am more to happy to live with this solution for now the style is quite different from where pagination appears elsewhere on the site. Digging into the parent css it looks like .wp-pagenavi is used. Is there a function out there that would work better in the interest of continuity?

  9. morganictrie
    Member
    Posted 1 year ago #

    I got it! Thanks so much for your help....I was really banging my head against the wall for a while there!

Topic Closed

This topic has been closed to new replies.

About this Topic