WordPress.org

Ready to get started?Download WordPress

Forums

Custom Content Type Manager
Pagination formatting templates have no effect when used with GetPostsQuery (2 posts)

  1. jamesguest
    Member
    Posted 1 year ago #

    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/

  2. fireproofsocks
    Member
    Plugin Author

    Posted 1 year ago #

    Sorry if the docs aren't clear (or up-to-date). You may need to look at the source code.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic