Submit Your Article
Home Articles News Tutorials Videos Add An Article
Topics: Design Photoshop Programming PHP CSS Java Database Web Development Javascript Ajax
– Close + Open

Find Out More About DevWebPro!

Sign up for the newsletter


» Terms & Conditions

Welcome to the New DevWebPro!

DevWebPro Includes:
  Hundreds Of Tutorials   Developer News
  Unique Gadget Videos   Tons of Topics to Discuss
  Expert Advice   We Will Publish Your Articles

New Design Structures For WordPress

By: Barry Welford
Monday, May 18th, 2009
Text: Decrease Font Size Increase Font Size | Print Print Article | Share: Delicious Digg StumbleUpon Post to Twitter Post to Facebook

The WordPress blogging software is quite rightly immensely popular. The Open-Source community that supports it has developed a whole raft of supporting code and applications that make it a pleasure to use.

This blog and the other SMM blogs now have a slightly different look. This is because we are now using a feature of WordPress, Multiple Loops. The beauty of WordPress is that the concepts are all very easy to understand. This particular feature will hopefully give much more reader satisfaction.

There are two elements to the change. The first is that you will now only see one blog post when you visit. Although Google tries to be helpful, it can occasionally provide more from a blog that you wish to see. Now you will see precisely the blog post that is relevant to your keyword query.

The other element is that at the bottom of this single blog post you will now see a list of the most popular blog posts as determined by our visitors. If you like what you see in the initial post then perhaps some of the other blog posts may tweak your interest.

The changes to the theme required for this new look are very straightforward. Hopefully this simple explanation will help you apply this same approach to your blog if you so wish.

The WordPress Loop

Web pages in a blog are produced by WordPress templates. These are files with names such as index.php or single.php. Within these template files, the heart of the WordPress software is code which is called The Loop. The WordPress Codex gives a more detailed explanation of The Loop In Action.

The content of all blog posts is held in an associated mySQL database. When a blog web page is displayed, the web page will show certain information for every blog post entry that fits the particular database query implied by your selection of web page. For example, if you want the most recent blog post, then the loop picks up only the information on that blog post. This is illustrated by the following image of a WordPress blog page.

Wordpress blog for single post

When you visit the home page of the blog, you are often seeing a series of blog posts that are created via the file named index.php. The number of blog posts is selected by the blog webmaster. For example if it is arranged that the blog would normally show the 3 most recent blog posts, then this is illustrated by the following image.

Wordpress blog for three posts

When Google sends you to a single blog post to fit your keyword query then you are often seeing what a file named single.php produces by applying the loop. Normally in the index.php and the single.php files, the loop starts with the following code (note that a space has been inserted after < in the following code samples to ensure the code could be printed.):

< !-- start of the loop -->
  < ?php  if (have_posts()) : ?>

The Loop is then all the code before a final < ?php endif; ?> terminates the Loop (again as mentioned a space has been inserted between < and ? to allow this code to display correctly).

Multiple Loops

As mentioned the new feature is that we are now using Multiple Loops in the WordPress software. The following image shows what is being displayed. The first post is produced by a first Loop. The list of Most Popular Posts is then produced by a second Loop.

Wordpress blog for post and popular list

In order to have only one post appear in the first loop, we use a Template Tag, query_posts. This query_posts tag can modify what the Loop accesses from the database. In this case we wish to have only one blog post to appear so the first Loop starts off as follows:

< !-- start of first loop -->
  < ?php  query_posts('showposts=1');
      if (have_posts()) : ?>

The only complication here is that as entries are taken from database in The Loop, the database software maintains a count of the data that has been used. Normally other applications of the Loop will access only new data since past data has already been accessed. In order to see the posts which are of interest, we use another WordPress Template Tag as the second Loop starts to reset the count. This tag is the rewind_posts tag.

In order for the list of Most Popular Posts to be displayed, a new category, popular, has been created. When visitor traffic confirms that a blog post is popular, then it is assigned to this category in addition to whatever category may have been appropriate.

The code to start the second Loop to achieve the effect shown here is as follows:

< !-- start of second loop -->

< ?php  rewind_posts();
    query_posts('category_name=popular&showposts=-1');
    if (have_posts()) : ?>

Other Benefits Of This Type of Display

In addition to displaying popular posts for greater visitor satisfaction, this also ensures that such posts have more links pointing to them. This should ensure greater search engine visibility for these posts. In all, this format would seem to have only benefits. It will be interesting to see what reactions blog visitors have to this new format.

Comments

Topics: , , , , , , , ,

About the Author:
Barry Welford, President of SMM Strategic Marketing Montreal works with business owners and senior management on Internet Marketing strategy and action plans to grow their companies. He is a moderator at the Cre8asite Forums and writes on current issues on the Internet and on the Mobile Web in three blogs, BPWrap, StayGoLinks and The Other Bloke's Blog.

Leave a Comment

DevWebPro is an iEntry Network ® publication - © 1998-2010 All Rights Reserved