If you run a WordPress blog, you will eventually want to make some modifications to your theme.
Perhaps you want to show your tags, not just categories, perhaps you want the date in a different format, you might want to add the URL of the author to each post, there are a lot of things like that which can easily be done with a little knowledge of WordPress template tags, which are little PHP code snippets, but you don't have to be a coder to use them.
The great thing about these tags is that they are very well documented "see link above", and that they are extremely simple to use. You don't need to know anything about PHP, so let me explain their basic use in common sense language. WordPress uses a loop, elegantly called "the loop" in "Wordpressian", which cycles through the posts you have.
If you show 10 posts on your main page, the loop cycles through the latest 10 posts. This means that on the first loop it will pull in the data of your latest post, on the second pass it will look at the second and so on. All the data is pulled, all you need to do is specify what you want to display out of that data, let's take a look at how.
First of all, you need to identify the start and the end of the loop. The loop starts with the following (there may be some variation) :
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
And ends with a "<?php endwhile; ?> <?php endif; ?>". This end statement is usually followed by the page navigation links which let you "turn the page" to the next or previous posts. Anything inside the loop gets executed as many times as the number of posts which are shown.
If all you want is to show your title, you just need to put "<?php the_title() ?>", and you will get the titles of your first 10 posts. If you also want to show the tags you can add "<?php the_tags() ?>". There are many others you can add, and don't forget, you also need some HTML and CSS to make them look good.
Here's a list of the most basic ones and what they do, but you can see the full list and expanded usage by clicking on the link above. Remember that the following should be put in the form: <?php function() ?>
While I use many others now and again, there are loads of designs that only use these 8, you can do a lot, with these alone. As you can see, adding to and modifying a WordPress template is not such a big deal, why not try it yourself?Advertisement
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.