Displaying a “No Comment/Trackback Received Yet” Message
Published on May 16, 2005 at 7:34 PM EST
Last updated on October 9, 2006 at 12:02 AM EST
In the Tutorials category.
One of the changes I made with Scrapbook, the new site design, is to add a little “no comments yet” or “no TrackBacks yet” message to the entries that haven’t received any. Using a little PHP, it’s easy to do….
One of the changes I made with Scrapbook, the new site design, is to add a little “no comments yet” or “no TrackBacks yet” message to the entries that haven’t received any. Using a little PHP, it’s easy to do.
Below is some code to do this, using default template code as an example. The PHP is bolded to (hopefully) make it easier for you to institute on your site.
<?php if (<MTEntryCommentCount> != '0' ) { ?>
<MTComments>
<$MTCommentBody$>
<p class="posted">Posted by <$MTCommentAuthorLink default_name="Anonymous" spam_protect="1"$> at <$MTCommentDate$></p>
</MTComments>
<?php } else { ?>
<p>No comments have been posted on this entry. Be the first!</p>
<?php } ?>
Doing the same thing to TrackBacks is similar:
<?php if (<MTEntryTrackbackCount> != '0' ) { ?>
<p>Listed below are links to weblogs that reference <a href="<$MTEntryPermalink$>">'<$MTEntryTitle$>'</a> from <a href="<$MTBlogURL$>"><$MTBlogName encode_html="1"$></a>.</p>>
<MTPings>
<p id="p<$MTPingID$>">
<a href="<$MTPingURL$>"><$MTPingTitle$></a> from <$MTPingBlogName encode_html="1"$><br />
<$MTPingExcerpt$> <a href="<$MTPingURL$>">[Read More]</a>
</p>
<p class="posted">Tracked on <$MTPingDate$></p>
</MTPings>
<?php } else { ?>
<p>No TrackBack pings have been received on this entry. Be the first!</p>
<?php } ?>
That’s all there is to it!
If you found this article useful, please consider supporting this site through a donation.
Comments
So far, there are 3 comments and Trackbacks on this entry. Add yours!
Thanks for this entry, Dan. I have a question, though, about the code (and here I’m betraying my ignorance). I was under the impression that the end of a PHP statement needs to have a semicolon. But I don’t see any in your code. Is there something I’m missing? thanks again.
One more question: Any reason why this doesn’t seem to work in a dynamically published page?
Yes, Karl, normally the end of a PHP statement needs a semicolon. But there aren’t any real statements here! If, after “if ( != ‘0’) {” there were an “echo ‘blah blah’” statement, that would need to be followed by a semicolon. Instead, I exit PHP usage (“?>”) and begin entering HTML. The real reason for doing that is that it’s easier than thinking about entering single or double quotes, and it’s easier to read.
I’m not sure why it wouldn’t work with dynamic publishing; as you can guess I’m only using static. But something to try might be reversing the approach, which might be better anyway:
<?php if (<MTEntryTrackbackCount> = 0) { ?>
<p>No trackbacks!</p>
<?php } else { ?>
<p>Trackback listing</p>
<?php } >
TrackBack URL for Displaying a “No Comment/Trackback Received Yet” Message:
http://www.eatdrinksleepmovabletype.com/cgi-bin/mt/mt-tb.cgi/284