Shop PCMemoryStore.com Today! MacSpeech Dictate 1.5

Sunday, April 12, 2009

Show only Post Titles on a WordPress Blog in Arcvhives Page

·

If you're running Wordpress, how do you like your archive page? Do you like having complete post after complete post for page after page? Do you like just showing excerpts for each page?
I wanted to try something different.

I wanted to show just the titles of the posts on each archive page because it looks cleaner and because it takes away another possible source of duplicate content on the blog. I also decided to add the number of comments for each post so readers can see which ones got the most response, the date published, and the author. Finally, I wanted all the posts to show up on one page.

I know there are plugins to do similar tasks, like Clean Archives and Clean Archives Reloaded, but neither of these did exactly what I wanted.

So, I got to learn a little more about Wordpress. First up was a little function called query_posts(). While this function can do a lot of things, the part I was interested in was it's ability to change the page structure from one that was paged to including all the posts on one page. So, my first step was to call query_posts() before entering the loop on the archive page of my theme with the original query string (held in $query_string) and the parameter posts_per_page set to -1 (which tells wordpress to put everything on one page):

<?php query_posts($query_string . "&posts_per_page=-1"); ?><?php if (have_posts()) : ?>

The next step happens within the loop. This was mostly a matter of removing calls from the loop to show the content of the post. I also took the post titles out of headers and added the call to comments_number() to get the number of comments for the post.

<?php while (have_posts()) : the_post(); ?><div style="padding-bottom: 10px;"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a><?php echo ' - ' ?><?php comments_number('0 comments', '1 comment', '% comments'); ?><br /><small><?php the_time('F jS, Y') ?> by <?php the_author() ?></small></div><?php endwhile; ?>

I don't know if this will work on Wordpress 2.3 or higher. It shows you don't have to be a Wordpress expert to make some nice customizations to your blog.

0 comments:

Post a Comment

Related Articles


Related Article Widget by Hoctro

About Me


嗨,我是花,居住在印度兴奋的Windows,Linux中国的外籍人士和所有高科技的东西

Hi, I am Hua, a chinese expat residing in India excited about windows, linux and all things tech

Receive updates for free

Enter your email address:

Delivered by FeedBurner

Mobile Version

Bookmark

Bookmark and Share

Blog Archive

matchmaker.com gold membership valentine's