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

(avery) #1

CHAPTER 2 • The WordPress Syntax 39


Something often overlooked by beginners is that knowing where the visitors are, and in what
situation, also tells you where they are not. If you need to do something for everything that is
not a particular circumstance, then you can use the if not solution, which means that you’ll
put an exclamation mark before the conditional tag, like this:


<?php
if (! is_front_page() ) {
// Do something for every page but the front page
}
?>


This will let you do something whenever is_front_page() is false, which would be on
every page but the front page.


NEXT UP: THE LOOP


Now that you know that WordPress sites are built on themes, which in turn consist of
template files containing different kinds of tags that do funky stuff, it’s time to start
manipulating the content. This is done with the loop, a PHP snippet that is the heart and soul
of WordPress. Although you can do a lot with WordPress without knowing about the loop,
you certainly have to understand it if you want to truly bend the platform to your will. You
can use the loop to make posts show up in a different order and generally display things the
way you want.


A lot of the things you’ll want to do with WordPress are only possible within the loop. And
that in turn means that you sometimes need multiple loops with custom outputs. Or, at the
very least, you need to figure out where the loop begins and ends so that you can add the cool
template tags and plugin features you no doubt will find or create on your own.


There’s no way of getting around it; the loop is important. Better hop to it, then.

Free download pdf