Template & Conditional Tags

Template Tags are used in your Template Files to display information dynamically or otherwise customize your site.

How to Use Template Tags:

To use a template tag, simply place it within your template file where you want the content to appear.

<article>
	<h2><?php the_title(); ?></h2>
	<p>Posted by <?php the_author(); ?> on <?php the_date(); ?></p>
	<div><?php the_content(); ?></div>
</article>

Conditional Tags returns boolean value that can be used in your Template Files to alter the content depending on the conditions that the current page matches.

How to Use Conditional Tags:

1. Checking if it’s the Homepage

<?php if ( is_home() ) : ?>
    <p>This is the homepage.</p>
<?php endif; ?>

2. Checking if it’s a Single Post

<?php if ( is_single() ) : ?>
    <p>This is a single post.</p>
<?php endif; ?>

Coding Exercise

Please explore the template tags and conditional tags to achieve the following in the coding exercise:

  • Show only post title without link on single post
  • Show excerpt text on archive listing
  • Show full content on single post

References

Go through the following handbook pages to know all conditional and template tags functions.

Ideas to Explore:

  • What template tags and conditional tags you can use in the loop?
  • What is a loop, and where can you use it? Write code examples of Multiple Loops.
  • What is is_admin() tag? Illustrate the use of is_admin() using an example.