14 Mar, 2003
show/hide comments or extended entries (only for x number of entries)
Posted by: Jennifer In: Scripts
This was insipired by Quadsk8's comment here. I've actually been using this script for awhile on my personal blog, but realized I never posted the script here when GeekGrrl mentioned a longer download time on her pages when she added the show/hide script. Quadsk8 had originally suggested doing this using only MT tags – but I prefer to do it with php. I explain why at the very bottom of this post…
(note: this script requires your being able to use PHP on your page)
First go here and follow the instructions for adding the show/hide comments or extended entries.
Now somewhere on the top of your page, add this (changing the red/bold number as appropriate):
<?
$showcommentmax = 6;
$currentshowcomment = 0;
$showextendedmax = 3;
$currentshowextended = 0;
?>
For the comments block:
Before the block that shows/hides your comments put this:
<?
if ($showcommentmax > $currentshowcomment) {
/*
this next line will make it so that it only displays the show/hide comment option IF there are actually comments
*/
if (<$MTEntryCommentCount$> > 0) {
?>
After that block add this:
<?
$currentshowcomment++;
// only counting show comment if it there are comments to show
}
}
?>
For the extended entries block:
Do kind of the same thing for the extended entries except a slight modification.
Find the block that shows/hides your extended entries, directly after the <MTEntryIfExtended> put this:
<?
if ($showextendedmax > $currentshowextended) {
After that block, but before the </MTEntryIfExtended> add this:
<?
$currentshowextended++;
}
?>
Now, the reason why I prefer the PHP method over the strictly MT tag method:
1) I like to have a full 7 days worth of posts on my blog. It's what I like to see on other blogs (sometimes I'll only have time to visit once a week – and it's nice to have it all on one page, where I won't have to hunt for the earliest entries). If you do it with mt tags, you only get x number of entries on the page – it's not day sensitive. So if you have a busy week – some of those entries from earlier in the week may fall off the main page.
2) I have a lot of code – with all my restricted entries, drop down comments, drop down extended entries, etc. – using the mt tag method requires me to have basically two copies of my main content – one for the first x number entries, and another for the remaining x number of entries. This became a real pain to maintain.
However, if you don't have PHP – I guess the MT tag method is better than nothing.