Inspired by Katherine’s Quilting Bee spring cleaning efforts, I decided to add on to my Integrating Q*Bee with WordPress tutorial by showing you how you can have an archive page for all your trade logs. You can view mine here.
First, we’re going to create a template for your trade log archive page. Open your favorite html editor, and add the following code:
[code]<?php /* Template Name: QBee Trade Log Archive */ ?>
<?php get_header(); ?>
LOOP-DEE-LOOP
<?php get_sidebar(); ?>
<?php get_footer();?>[/code]
You can change the template name to anything; I just called it that for easy reference. Now we’re going to add the actual archives in the WordPress loop, where it says LOOP-DEE-LOOP:
[code]<h2>GIVE YOUR PAGE A TITLE!</h2>
<?php
global $query_string;
query_posts(“post_type=qbee&post_status=publish&posts_per_page=10″);
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_time(‘m/d/y’) ?>: <?php the_title(); ?>
<?php endwhile;
endif; ?>
<div class=”paginate”>
<?php if(function_exists(‘wp_pagenavi’)) { wp_pagenavi(); } ?>
</div>
<?php wp_reset_query(); ?>[/code]
A couple notes:
- Notice how for
query_posts("post_type=qbee
, the post type is qbee? This is because we named our custom post type “qbee” in the previous tutorial. Of course, if you named it something else, you will have to change it here. posts_per_page=10
defines how many logs will show up on this page. If you want more, simply change the number!<?php the_time('m/d/y') ?>: <?php the_title(); ?>
generates the same log style as the previous tutorial. Feel free to change the format if you wish.- Lastly, don’t forget to change the title of the page :)
Now about the loop. It’s called a loop because like a loop, certain things inside the loop repeats itself. Notice how <?php the_time('m/d/y') ?>: <?php the_title(); ?>
sits between if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
and <?php endwhile;
? This is because everything that sits between those two codes will repeat itself if posts are found. So if you have 10 trade logs, the <?php the_time('m/d/y') ?>: <?php the_title(); ?>
and ONLY that, will repeat itself 10 times to display the 10 trade logs. Everything outside of those two codes stay constant (eg. the title). So if you want each log to show up as a paragraph:
[code]<h2>GIVE YOUR PAGE A TITLE!</h2>
<?php
global $query_string;
query_posts(“post_type=qbee&post_status=publish&posts_per_page=10″);
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<p><?php the_time(‘m/d/y’) ?>: <?php the_title(); ?></p>
<?php endwhile;
endif; ?>
<div class=”paginate”>
<?php if(function_exists(‘wp_pagenavi’)) { wp_pagenavi(); } ?>
</div>
<?php wp_reset_query(); ?>[/code]
Notice how I put the <p>
and </p>
between those two codes mentioned earlier? This is because we want the p tags to repeat whenever the logs repeat. Now if you wanted to put your logs in an unordered list:
[code]<h2>GIVE YOUR PAGE A TITLE!</h2>
<ul>
<?php
global $query_string;
query_posts(“post_type=qbee&post_status=publish&posts_per_page=10″);
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li><?php the_time(‘m/d/y’) ?>: <?php the_title(); ?></li>
<?php endwhile;
endif; ?>
</ul>
<div class=”paginate”>
<?php if(function_exists(‘wp_pagenavi’)) { wp_pagenavi(); } ?>
</div>
<?php wp_reset_query(); ?>[/code]
Notice again how the <li>
and </li>
are between those two codes mentioned earlier, but the <ul>
and </ul>
are OUTSIDE? This is because we only want the <ul>
and </ul>
to appear once.
Lastly, notice:
[code]<div class=”paginate”>
<?php if(function_exists(‘wp_pagenavi’)) { wp_pagenavi(); } ?>
</div>[/code]
This is here because I use the WP Paginate plugin to display pages. If you don’t use this or don’t want any sort of pagination, feel free to remove this from the code.
You’re done with the tough part! Upload your template into your WordPress theme folder, and go to your WP admin panel. Now, add a new page, and make sure you select your newly created trade archive template as the template for this page! Give the page a title, and click publish. Voila, your trade log archives page ^_^
If you have any comments or questions, please leave a comment, and I’ll try to get back to you asap :]