Thord Daniel Hedengren - Smashing WordPress_ Beyond the Blog-Wiley (2014)

(avery) #1

CHAPTER 4 • WordPress Theme Essentials 83



<?php get_footer(); ?>


You’ll notice some classes in the article tag after endwhile. These are following Word-
Press standards, and the sole purpose of adding the post-0 ID, for example, is so that fancy
plugins that give the ID special treatment (through CSS or JavaScript) will work. The post
class is useful because it means that you can style the content the same way you would a
regular post. All in all, the classes added here aren’t crucial to the theme in any way, but they
might be useful in some cases — and besides, it’s good to understand and know how Word-
Press labels its content, even though it’s done with post_class() and not hardcoded like it
is here.


Because you learned all about the loop in the previous chapter, I’m pretty sure you’ll recognize
the if ( have_posts() ) : while ( have_posts() ) : the_post(); part. After that,
you’ll find a commented placeholder for where the actual output will be, and then you’ve got
an else clause for those occasions when there are no posts available to loop out. Then you
need a different message obviously, so that’s what you get. Nothing particularly weird here; if
you need to refresh your memory, just revisit the previous chapter.


Moving on, you’ll get the actual output in there as well, replacing the comment. Looking at
the dummy content, you need to replace it all with template tags that output the actual
content, such as the title, correct date and time, and author:


<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>










// The content
the_content();
?>
Free download pdf