headerIMG

B2B Articles - January 31, 2014

Getting started with the Wordpress Loop

Wordpress web designPerhaps the most important thing to learn in Wordpress for a web developer is the loop. It's the backbone of Wordpress web design. The loop allows us to display any content from the Wordpress CMS and give that content form, structure and meaning.

By using the loop PHP code, a web developer can request and display Wordpress posts, as well as add HTML, CSS, Javascript, PHP, etc. to style and provide additional layers of functionality to the content. Essentially The Loop are building blocks for building more interactive and useful websites.

Getting started with the Wordpress Loop

<?php if (have_posts()):while (have_posts()) : the_posts();?>

Wordpress provides a set of tags to ensure that the website has posts to display and provides the ability to display those posts. These are called Template Tags. They provide the ability to customize how we display Wordpress posts and the content therein.

  • the_post() - makes available the next post in the queue of posts available for display
  • have_post() - Ensures that there is something available to display from our Wordpress database of content
  • While statement: have_post() will keep tabs on whether we still have content to pull. It is used in the while condition of this loop.

Break this down for me please... What specifically does The Loop do? Here is a dissection of the parts of the loop.

  1. Define what you are requesting
  2. Start the loop.
  3. Do something with each post/page found in the loop.
  4. Close the loop.

Using The Loop in your website

You can use the Wordpress loop pretty much anywhere in your theme templates. It is commonly used in the index.php file in the theme. Often times The Loop is used to display the most recent blog posts. Other common areas for using The Loop is on the single.php file and page.php.

Flexibility of the Wordpress Loop

Wordpress allows developers and web designers to overwrite any out of the box functionality. Generally most developers stick to the theme or plugins area, as it is not a good practice to modify the core of Wordpress. (You'll hate yourself later.)

You can override how The Loop is used to display a particular category for instance. If you are designing a content website that requires one section to have unique features: highlighted feature articles at the top or an entirely different landscape for presenting the content, then customizing the loop is the right approach.

Common template tags

  •  the_title()
  • the_content()
  • the_category()
  • the_excerpt()
  • the_tags()
  • the_permalink()
  • the_author()
  • the_time()

A couple things to remember:

Remember to have your page include a call for the header template at the top of your Theme's templates. Set WP_USE_THEMES to false if you are using your own design and it is not a tempate.

<?php define('WP_USE_THEMES', false); get_header(); ?>

Ending The Loop

<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

More Wordpress tips: searching within specific categories

Tel 212-993-7809  

Ironpaper ®
10 East 33rd Street 
6th Floor
New York, NY 10016
Map

Ironpaper - B2B Agency

B2B Marketing and Growth Agency.

Grow your B2B business boldly. Ironpaper is a B2B marketing agency. We build growth engines for marketing and sales success. We power demand generation campaigns, ABM programs, create B2B content, strengthen sales enablement, generate qualified leads, and improve B2B marketing efforts.

Ironpaper Twitter Ironpaper Linkedin