• Below I have code that I have pulled from several sources

    How can I tie my custom query into the page navigation? All I want to do is have a custom query that allows me to have 4 post per page. With a page nav at the bottom to get to each page containing the post.

    Here is a link to my page: https://gods-image.com/news-2

    <?php query_posts('cat=1&showposts=4'); ?>
    
      <div id="content">
    
    <?php if (have_posts()) : ?>
    
    	<?php while (have_posts()) : the_post(); ?>
    
    		<div class="post" id="post-<?php the_ID(); ?>">
    			<p class="post-date">
    				<span class="date-day"><?php the_time('j') ?></span>
    				<span class="date-month"><?php the_time('M') ?></span>
    			</p>
    			<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    
    			<div class="entry">
    				<?php the_excerpt(); ?>
    
         </div>
           <p class="metadata">Posted by <?php the_author() ?>.<?php edit_post_link('Edit', ' | ', ''); ?></p>
    		</div>
    
      <?php endwhile; endif; ?>
    
              <?php
    global $wp_query;
    
    $big = 999999999; // need an unlikely integer
    
    echo paginate_links( array(
    	'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    	'format' => '?paged=%#%',
    	'current' => max( 1, get_query_var('paged') ),
    	'total' => $wp_query->max_num_pages
    ) );
    ?>
Viewing 8 replies - 1 through 8 (of 8 total)
  • Is this the main query or a secondary query?.

    Thread Starter JusHerb

    (@jusherb)

    @esmi somehow I need to tie both queries into one… I know it may sound kind of crazy. But I am new to php. It will more than likely end up being the second query which displays page Navigation. See the issue is I tweaked this custom query sometime back and here recently I needed to add navigation because of how the page is built. I need to be able to call 4 post per page. I need to some how pull from the first query to finish the second query. Basically I just need the navigation to work with the post category. Make sense?

    It will more than likely end up being the second query which displays page Navigation

    Then you shouldn’t be using query_posts() but WP_Query(). However, it will always be the primary query & Loop that controls pagination. You cannot have separate pagination with a second custom query & Loop.

    Thread Starter JusHerb

    (@jusherb)

    Right, Thats my problem I have no clue on how to use WP_Query() to produce what I need. 4 post per page coming from the category with navigation…. Didnt think it would ruff me up this bad… Any suggestions on how I can accomplish this? I am clueless at this point. Its there in the code but I have no clue on what to do to get started and finish it

    Do you intend to have 1 or 2 loops on the page?

    Thread Starter JusHerb

    (@jusherb)

    At this point I have no real preference on what code is on the page. I’m just trying to accomplish my goal of having my post show as they are but just 4 to a page in that category of “News” but with Page Navigation (Prev 1 2 3 4 Next)… So to answer your question I dont care how i get there as long as i figure it out… What do you suggest?

    Thread Starter JusHerb

    (@jusherb)

    Check out this page https://gods-image.com/news-2

    [No bumping. This is a volunteer-staffed forum – not online chat. If it’s that urgent, consider hiring someone.]

    Thread Starter JusHerb

    (@jusherb)

    WHAT!?

    Anyways….

    Here my solution to my problem if there is anybody searching for the same solution

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    <?php query_posts('posts_per_page=3&cat=6&paged='.$paged); ?> 
    
      <div id="content">
    
    <?php if (have_posts()) : ?>
    
    	<?php while (have_posts()) : the_post(); ?>
    
    		<div class="post" id="post-<?php the_ID(); ?>">
    			<p class="post-date">
    				<span class="date-day"><?php the_time('j') ?></span>
    				<span class="date-month"><?php the_time('M') ?></span>
    			</p>
    			<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    
    			<div class="entry">
    				<?php the_excerpt(); ?>
    
         </div>
           <p class="metadata">Posted by <?php the_author() ?>.<?php edit_post_link('Edit', ' | ', ''); ?></p>
    		</div>
    
      <?php endwhile; endif; ?>
    
    	<?php global $wp_query;
    
    $big = 999999999; // need an unlikely integer
    
    echo paginate_links( array(
    	'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    	'format' => '?paged=%#%',
    	'current' => max( 1, get_query_var('paged') ),
    	'total' => $wp_query->max_num_pages
    ) );
    ?>

    This will give you a list of post for an category on your site with working page Navigation

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Custom Query Paginate (Page Navigation)’ is closed to new replies.