Wednesday, 24 July 2013

Adding the tag

When you have the category ID number in hand, you’re ready to add the <query_post> tag to your template.

Here are two parameters that you can use with the <query_posts> tag:

✦ showposts=X: This parameter tells WordPress how many posts you
want to display. If you want to display only three posts, enter show-
posts=3.
✦ cat=X: This parameter tells WordPress that you want to pull posts from
the category with this specific ID number. If the ID category is 40, enter
cat=40.
Follow these steps to add the <query_post> tag to your template:

1. Click Editor in the Appearance drop-down list.
The Edit Themes page opens.
2. Click the template in which you want to display the content.
If you want to display content in a sidebar, for example, choose the Sidebar template: sidebar.php.
3. Locate the ending </ul> tag at the bottom of the template for the
theme you’re using.
If you’re using the Twenty Ten theme, the ending </ul> tag is the second-to-last line.
4. Type the following code directly above the ending </ul> tag:
<?php query_posts(‘showposts=3&cat=40’); ?>
<h2>Type Your Desired Title Here</h2>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<strong><a href=”<?php the_permalink() ?>” rel=”bookmark”
title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_ title(); ?></a></strong>
<?php the_excerpt();endwhile;endif; ?>

In the first line, you indicate the following: showposts=3&cat=40. You

can change these numbers to suit your specific needs. Just change 3 to
whatever number of posts you want to display (there’s no limit!) and
change 40 to the specific category ID number that you want to use.
5. Click the Update File button.
The changes you just made are saved to the sidebar.php template.

0 comments:

Post a Comment