Using PHP in Excerpts+ Meta fields

Excerpts+ v2.2 introduced a very useful ability to allow PHP code in the Meta fields.

For example, let’s say you’ve got your Excerpts+ leaf setup the way you want but you also want to display the most recent comment for each post. You simply insert the code intio the meta field, making sure it is enclosed in the <?php ?> pair, as shown in the image below.

 

The setup

media_1308709362798.png

The code is:

<?php
$comments = get_comments(‘post_id=’.get_the_ID().’&order=DESC&status=approve’);
if ($comments) {
echo ‘<strong>Latest comment:<br/>’.$comments[0]->comment_author.’ said: </strong>’;
echo ‘<em>’.substr($comments[0]->comment_content,0,200).’…</em>’;
}
?>

 

The result

media_1308709830493.png

Although this is a very brief tutorial, hopefully it will inspire you to think of other ways you might use this new facility.

If you want to see more of what the Excerpts+ Leaf can do, check out this demo site put together by Chris Howard.  And get your copy of the powerful Excerpts+ Leaf here.

Spread the word!

Leave a reply

Copyright © 2016 Vesped Inc. All Rights Reserved. Proudly Powered by Headway and WordPress