WordPress.org

Ready to get started?Download WordPress

Forums

How can I add Pagination to my custom page (12 posts)

  1. adzay
    Member
    Posted 1 year ago #

    Hi all. I have a Video gallery custom page which will allow me to post YouTube videos.

    Can someone please help me and tell me how to add pagination to this so that if 12 videos are shown on the page it will say "Next 12 " at the bottom of the page.

    This is a child theme btw.

    get_header(); ?>
    <Div id="Showcaseting" role="show">
    <?php FA_display_slider(291); ?>
    </div>
    
    		<div id="primary" class="relative">
    <?
    		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'cat' => 1,
    	'paged' => $paged
    );
    query_posts($args);
    ?>
    			<div id="content" role="main">
    				<div id="galvidcontainer" >
    <h1>Videos</h1>
    
         <?php /* Loop the stuff from the videos post type */
    			$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
              $args = array( 'post_type' => 'videos', 'posts_per_page' => 12 );
              $loop = new WP_Query( $args );
              while ( $loop->have_posts() ) : $loop->the_post();
    		  query_posts($args);
    		  ?>
    
              <div class="galvidpre">
                   <div class="galvidprevid glass">
                   <?php
                   /* Set variables and create if stament */
    				$videosite = get_post_meta($post->ID, 'Video Site', single);
    				$videoid = get_post_meta($post->ID, "Video ID", single);
    				if ($videosite == vimeo) {
      				echo '<iframe src="http://player.vimeo.com/video/'.$videoid.'" width="300" height="190" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
    				} else if ($videosite == youtube) {
      				echo '<a class="lbpModal"  href="http://www.youtube.com/embed/'.$videoid.'"><img class="alignnone" src="http://img.youtube.com/vi/'.$videoid.'/0.jpg" alt="" width="300" height="190" /></a>';
    				} else {
      				echo 'Please Select Video Site Via the CMS';
    				}
    				?>
                   </div>
                   <div class="galvidpretext">
                        <h1><?php the_title() ?></h1>
                        <p>
                        <?php /* this is just a limit on characters displayed */
                        $words = explode(" ",strip_tags(get_the_content()));
                        $content = implode(" ",array_splice($words,0,20));
                        echo $content; ?>
                        </p>
                   </div>
              </div>
    
         <?php endwhile;?>
    
    </div>
    
    			</div><!-- #content -->
    		</div><!-- #primary -->
  2. adzay
    Member
    Posted 1 year ago #

    My website is at http://www.linktwitch.com by the way.

  3. graphicgeek
    Member
    Posted 1 year ago #

    Try putting this after the endwhile:

    <div class="navigation">
          <div class="alignleft"><?php next_posts_link('« Previous 12', $query->max_num_pages) ?></div>
          <div class="alignright"><?php previous_posts_link('Next 12 »', $query->max_num_pages) ?></div>
    </div>
  4. adzay
    Member
    Posted 1 year ago #

    I'm afraid that doesn't work. Thanks though.

  5. graphicgeek
    Member
    Posted 1 year ago #

    opps, I didn't look close enough at your loop. Try changing $query->max_num_pages to $loop->max_num_pages

    Also, I'm a little confused as to why you are using wp_query and query_posts together. I haven't seen that done before.

    I wonder if this would do the same thing:

    get_header(); ?>
    <Div id="Showcaseting" role="show">
    <?php FA_display_slider(291); ?>
    </div>
    
    		<div id="primary" class="relative">
    			<div id="content" role="main">
    				<div id="galvidcontainer" >
    <h1>Videos</h1>
    
         <?php /* Loop the stuff from the videos post type */
    			$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
             	$args = array(
    				'post_type' => 'videos',
    				'posts_per_page' => 12,
    				'cat' => 1,
    				'paged' => $paged
    			);
    
              $loop = new WP_Query( $args );
              while ( $loop->have_posts() ) : $loop->the_post();
    		  ?>
    
              <div class="galvidpre">
                   <div class="galvidprevid glass">
                   <?php
                   /* Set variables and create if stament */
    				$videosite = get_post_meta($post->ID, 'Video Site', single);
    				$videoid = get_post_meta($post->ID, "Video ID", single);
    				if ($videosite == vimeo) {
      				echo '<iframe src="http://player.vimeo.com/video/'.$videoid.'" width="300" height="190" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
    				} else if ($videosite == youtube) {
      				echo '<a class="lbpModal"  href="http://www.youtube.com/embed/'.$videoid.'"><img class="alignnone" src="http://img.youtube.com/vi/'.$videoid.'/0.jpg" alt="" width="300" height="190" /></a>';
    				} else {
      				echo 'Please Select Video Site Via the CMS';
    				}
    				?>
                   </div>
                   <div class="galvidpretext">
                        <h1><?php the_title() ?></h1>
                        <p>
                        <?php /* this is just a limit on characters displayed */
                        $words = explode(" ",strip_tags(get_the_content()));
                        $content = implode(" ",array_splice($words,0,20));
                        echo $content; ?>
                        </p>
                   </div>
              </div>
    
         <?php endwhile;?>
    <div class="navigation">
          <div class="alignleft"><?php next_posts_link('« Previous 12', $loop->max_num_pages) ?></div>
          <div class="alignright"><?php previous_posts_link('Next 12 »', $loop->max_num_pages) ?></div>
    </div>
    </div>
    
    			</div><!-- #content -->
    		</div><!-- #primary -->
  6. adzay
    Member
    Posted 1 year ago #

    I'm afraid that didn't work

  7. graphicgeek
    Member
    Posted 1 year ago #

    This might be a silly question, but how many 'videos' posts do you have published? If it's 12 or less, the navigation won't show up.

  8. adzay
    Member
    Posted 1 year ago #

    At first there were 14.. but after I put in your code, nothing would show up until i put the number of posts down to 12. I reverted the code back to its original and now I have 13 posts.

  9. graphicgeek
    Member
    Posted 1 year ago #

    Found this in the codex:

    Pagination Note: You should set get_query_var( 'page' ); if you want your query to work with pagination. Since WordPress 3.0.2, you do get_query_var( 'page' ) instead of get_query_var( 'paged' ). The pagination parameter 'paged' for WP_Query() remains the same.

    So, maybe change $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    to:

    $paged = (get_query_var('page')) ? get_query_var('page') : 1;

  10. adzay
    Member
    Posted 1 year ago #

    okay thanks..i'll give it a try

  11. adzay
    Member
    Posted 1 year ago #

    lol it still didn't work :/ ...by the way.. If you look at my video page.. I have a very annoying little "directly before" down there. Do you know how I can remove it?

  12. graphicgeek
    Member
    Posted 1 year ago #

    The only thing I can see that might be missing is wp_reset_postdata();

    It should go right after endwhile;

    I'm not seeing "directly before". Did you figure out how to get rid of it?

Topic Closed

This topic has been closed to new replies.

About this Topic