How to edit the meta info below the title in Basic Simplicity

Posted January 29th, 2010 by Michael Janzen and filed in How To

I’ve gotten a lot of questions about how to edit the meta information under the post/page titles. This is what the code that generates these four text lines looks like right out of the box, albeit with some extra line spaces between the lines of code to make it easier to read.

<div class=”meta”>

<?php edit_post_link(‘Edit’, ”, ”); ?>

<div class=”meta-postedby”>Posted <?php the_time(‘F jS, Y’) ?> by <?php the_author() ?> <?php if(is_page()) { ?><!–nothing–><?php }else{ ?>and filed in <?php the_category(‘, ‘) ?><?php } ?> </div>

<div class=”meta-tags”><?php the_tags( ‘Tags: ‘, ‘, ‘, ”); ?></div>

<div class=”meta-addcomment”><?php comments_popup_link(‘Add a Comment’, ‘1 Comment’, ‘% Comments’, ‘commentslink’); ?></div>

</div><!–end meta–>

Let me describe each line and how to edit them for different treatments. But before you start editing the index.php (Appearance > Editor) remember that you’ll need to make these code edits again for future edits, unless I add a future feature that makes code edits obsolete.

<div class=”meta”>

The first thing to notice is that the whole section is wrapped in a <div> tag that can be styled with a CSS in the Custom CSS field on the Edit Basic Simplicity page. This is an example of a style that would make the text smaller: .meta { font-size:80%; }

<?php edit_post_link(‘Edit’, ”, ”); ?>

This generates the edit link for administers of your blog. You should just leave this here to make it easy to edit your posts and pages.

<div class=”meta-postedby”>Posted <?php the_time(‘F jS, Y’) ?> by <?php the_author() ?> <?php if(is_page()) { ?><!–nothing–><?php }else{ ?>and filed in <?php the_category(‘, ‘) ?><?php } ?> </div>

This line of code is by far the most difficult to understand, and the most requested line to edit. Let me take a moment to explain how it works in detail.

<div class=”meta-postedby”> (opens the ‘div’ that wraps and styles the line of text)

Posted (visible text)

<?php the_time(‘F jS, Y’) ?> (displays the date the post/page was posted)

by (visible text)

<?php the_author() ?> (displays author name as defined on Users > Authors & Users)

<?php if(is_page()) { ?> (open a conditional statement, if is this a page then show the following)

<!–nothing–> (hidden text, if you wanted something to show for a page you could put it here)

<?php }else{ ?> (if this not a page then show the following)

and filed in (visible text)

<?php the_category(‘, ‘) ?> (displays the category)

<?php } ?> (end of the conditional statement)

</div> (closes the line of text)

The main trick with editing this bit of code is not to mess up order the conditional stuff ans the spaces around the brackets and php tags. If you keep it in the order I have here and just put the things you want to show and hide on pages and posts you can customize what happens on posts and pages.

You can also use this little conditional trick in other parts of the theme. Here’s a clean bit of code you can use:

<?php if(is_page()) { ?>

THIS IS A PAGE

<?php }else{ ?>

THIS IS NOT A PAGE, USUALLY A POST

<?php } ?>

<div class=”meta-tags”><?php the_tags( ‘Tags: ‘, ‘, ‘, ”); ?></div>

This is the tags line. You can hide this on the Edit Basic Simplicity page or even move it down to the bottom of the post by sticking it right before </div><!–end the_content–> in the index.php file.

<div class=”meta-addcomment”><?php comments_popup_link(‘Add a Comment’, ‘1 Comment’, ‘% Comments’, ‘commentslink’); ?></div>

This is the comments link and count.

</div><!–end meta–>

This closes the whole meta section. It looks super simple but don’t forget this closing ‘div’ tag of the whole page breaks.

Conclusion

Three of these four lines, (posted by, tags, and comments), can be shown and hidden from the Edit Basic Simplicity page in version 1.4.1 but I’ve not added any feature for distinguishing their visibility between pages and posts. I will add this in a future release because it is regularly requested.

Happy to answer questions about this, please post comments/questions here.

Leave a Reply