Tonight we will be finishing off our loop, and making the pagination work. We will add our loop to the index template file of the Kubrik Theme. I'm actually going to do it, and provide you with a download and explination of what has changed.
OK, so all I really did to the index file was remove the old loop that was originaly in it, and replaced it with our custom loop. I also changed a reference to our pagination, adding a function call (thats in tut #4). I will post the complete template file but some parts may be cut off, so I highly recommend downloading the txt file for a hard copy.
Here is the complete template with custom loop:
<?php
/**
* @package WordPress
* @subpackage Default_Theme
*/get_header(); ?>
<div id="content">
<div> <!-- the new class we wrap the loop with -->
<?php
<!-- START custom loop -->
$customloop = 0; $customloop2 = 0;
$customtemp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('paged='.$paged);
if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post();$customloop++; $customloop2++;
if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
<div
id="post-<?php the_ID(); ?>">
<!-- adds the POST title to the loop -->
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?>
</a></h2><!-- adds basic META data to the loop -->
<span>Posted by <?php the_author(); ?> on <?php the_time('F j, Y') ?></span>
<div>
<!-- grabs IMAGE and CONTENT data to check if IMAGE is available -->
<!-- If Available or Unavailable Produces array 1 or 0 --><?php
$id =$post->ID;
$the_content =$wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id");
$pattern = '!<img.*?src="(.*?)"!';
preg_match_all($pattern, $the_content, $matches);
$image_src = $matches['1'][0];
?><p>
<!-- POST CONTENT IMAGE -->
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><img width="100px" height="100px;" src="<?php if($image_src != '') { echo $image_src; } else { ?><?php bloginfo('template_directory'); ?><?php } ?>" alt="<?php the_title(); ?>"/>
</a><!-- POST CONTENT TEXT choose start and end position and excerpt trail -->
<?php
$customtext = get_the_excerpt();
if(strlen($customtext ) > 0) {
$customtext = substr($customtext , 0, 330);
}
echo ''.$customtext.'...';
?><br />
<!-- READ MORE link -->
<a href="<?php the_permalink() ?>" style="float:right;" rel="bookmark" title="Read More of <?php the_title(); ?>">read more</a>
<br />
</p>
<div>hrbg</div></div>
</div>
<?php wp_link_pages(); ?>
<!-- END custom loop -->
<?php $wp_query = null; $wp_query = $temp;?>
<?php endwhile; endif; ?>
<br />
</div>
<div></div>
<div><?php custom_pagination() ?></div></div> <!-- closes our new class wrap of the loop -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Nice! Our custom loop is set up, and the pagination will work (except it will call an error until we move to tut #4). But having standard pagination isn't that nice looking. Woldn't it be nice to have a list, lets say a row of numbers that direct to each page. Like my site has on the blog.
In part 4 we are going to add some special features that will make the pagination killer, and we will throw in a little AJAX for fun! Hope you stick around to finish off how to Create a Custom Loop with Pagination (now with ajax!).
the tags: create, custom, functions, loop, pagination, tutorial, wordpress










1 Trackback or Pingback for this entry
August 20th, 2010 on 9:34 am
[...] make our pagination killer! Hope you come back and have a look… Download Paginated Custom LoopRead Part 2 hrbg I Have Written 45 Posts So Far!hrbgGetting The Latest Tweet…hrbgLooking For Custom [...]