WordPress.org

Support

Support » Plugins and Hacks » Pagination formatting templates have no effect when used with GetPostsQuery

Pagination formatting templates have no effect when used with GetPostsQuery

  • jamesguest
    Member

    @jamesguest

    Hi

    I’m having an issue with Pagination formatting templates (tpls) when used with the GetPostsQuery class.

    I’ve pretty much copied and pasted the example code from the docs (but added in my post type, set a limit of 1 to see the pagination with just two posts, removed [+extra+] and put the word ‘TEST’ in the outerTpl formatting string.

    My template renders the pagination, but always with the default templates. Any ideas?

    Code here…

    <?php
    			require_once(CCTM_PATH.'/includes/GetPostsQuery.php');
    			$Q = new GetPostsQuery();
    
    			// Define the query
    			$args = array();
    			$args['post_type'] = array('event');
    			$args['limit'] = 1;
    			$args['paginate'] = true;
    
    			// Read the offset variable (VERY IMPORTANT!)
    			if (isset($_GET['offset'])) {
    			        $args['offset'] = (int) $_GET['offset'];
    			}
    
    			$results = $Q->get_posts($args);
    
    			foreach ($results as $r) {
    			    // print out a bit about each post in the result set...
    				echo '<p>A result to go here</p>';
    			}
    
    			// Pagination
    			// Set formatting templates
    			$tpls['prevTpl'] = '<a href="[+base_url+]&offset=[+offset+]">&lsaquo; Prev.</a>&nbsp;';
    			$tpls['nextTpl'] = '&nbsp;<a href="[+base_url+]&offset=[+offset+]">Next &rsaquo;</a>';
    			$tpls['currentPageTpl'] = '&nbsp;<span>[+page_number+]</span>&nbsp;';
    			$tpls['pageTpl'] = '&nbsp;<a href="[+base_url+]&offset=[+offset+]">[+page_number+]</a>&nbsp;';
    			$tpls['outerTpl'] = '<div id="pagination">[+content+]<br/> Page [+current_page+] of [+page_count+]<br/>Displaying TEST [+first_record+] thru [+last_record+] of [+record_count+]</div>';
    
    			$Q->set_tpls($tpls);
    			print $Q->get_pagination_links();
    
    ?>

    Also note, I excluded [+extra+] from the strings as the example code only shows how to add this an instance of the CCTM_Pagination object, but not how to use this with GetPostsQuery. I attempted the following, but no joy…

    $args['extra'] = 'test'; before the call to $results = $Q->get_posts($args);

    Thanks,
    James

    http://wordpress.org/extend/plugins/custom-content-type-manager/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Pagination formatting templates have no effect when used with GetPostsQuery’ is closed to new replies.