Ed's Big Plans

Biology, Computing, Adventure

WordPress Inline Comments

without comments

Thanks to flisterz for this tip!

I added inline comments to this blog– it actually involves editing index.php, something I generally avoided doing. Peering into the code, it’s as normal as any other PHP so all of those silly worries were washed aside. The WordPress Codex does an excellent job of — well, it’s an incomplete API reference so it at the very least lists the functions that exist if it doesn’t truly explain them all.

Anyway– I didn’t just copy the hint from flisterz one to one because I wanted different functionality– but it did offer an example that let me make my changes much more easily. Because I don’t get very many comments, I don’t mind having complete comments show up inline on the main page instead of just an excerpt. As well, I wanted to have nice title bars to separate out the comments too… finally, while I was mucking around in the code, I decided to move the post tags up right beneath the title of each post instead of at the very bottom.

Changes made are inside index.php located before <?php end_while() ?>, just as in flisterz’s tip– here’s my version.

<div class="recent-comment">
<?php $comment_array = get_approved_comments($wp_query->post->ID); ?>
<?php if ($comment_array) {  ?>
    <?php foreach($comment_array as $comment){ ?>
    <br />
        <div style="background-color: #DDD9C6; border: 1px #F2EFE5 solid;">
        <em><?php comment_author_link(); ?> says...</em>
        </div><div>
        <?php comment_text(); ?>
        </div>
    <?php } ?>
<?php } ?>
</div>

In future, I’ll probably want to clean up the markup a bit by moving the style changes to this theme’s CSS. Oh, while I’m at it, I should also thank Digital Nature for this awesome theme (Arclite).

Written by Eddie Ma

November 24th, 2009 at 12:29 pm

Posted in Web Programming

Tagged with ,

Leave a Reply