• 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="https://player.vimeo.com/video/'.$videoid.'" width="300" height="190" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
    				} else if ($videosite == youtube) {
      				echo '<a class="lbpModal"  href="https://www.youtube.com/embed/'.$videoid.'"><img class="alignnone" src="https://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 -->
Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter adzay

    (@adzay)

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

    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>
    Thread Starter adzay

    (@adzay)

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

    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="https://player.vimeo.com/video/'.$videoid.'" width="300" height="190" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
    				} else if ($videosite == youtube) {
      				echo '<a class="lbpModal"  href="https://www.youtube.com/embed/'.$videoid.'"><img class="alignnone" src="https://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 -->
    Thread Starter adzay

    (@adzay)

    I’m afraid that didn’t work

    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.

    Thread Starter adzay

    (@adzay)

    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.

    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;

    Thread Starter adzay

    (@adzay)

    okay thanks..i’ll give it a try

    Thread Starter adzay

    (@adzay)

    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?

    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?

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘How can I add Pagination to my custom page’ is closed to new replies.