scriptygoddess

30 Dec, 2003

Updated Show/Hide script – (with additional links in the same line)

Posted by: Jennifer In: MT Tips n Tricks

Long title. Sorry. 😀
Someone wanted to use the show/hide comments script but have more than just the "show comments"/"hide comments" text in the same line. Basically – what they wanted was :

Permalink | Show Comments(3) | Add Comment | Trackback(2)

Where the "Show Comments" would drop down and do the show/hide comments – and it would only be there IF there had been comments to display. (for this last part, to use this script, you need to be running PHP on your page)

I know this is a very particular case – but there's pieces in here you could probably cut, mix, and match.

First, you need to get the updated version of the show more comments script here. (Side note: to Mr. Tweezer's complaint in his post about my not making it easier for him to use my scripts… I'm sorry- I'll refund your money… oh wait – this site is free and actually here for my OWN PERSONAL reference… Sometimes I even drop code here without explanation – just so I can grab it later. The "disclaimer" in the sidebar also says "we are volunteers, not paid tech support. In the end, you're on your own." Seems he decided to take that part down. How nice.)

In any case instead of using the show more comments function I've posted previously, use his revised one instead (function name changed to work seperately for comments):

<script type="text/javascript">
function showMoreComments(entryID, entryLink, htmlObj) {
extTextDivID = ('extText' + (entryID));
extLinkDivID = ('extLink' + (entryID));
if( document.getElementById ) {
if( document.getElementById(extTextDivID).style.display ) {
if( entryLink != 0 ) {
document.getElementById(extTextDivID).style.display = "block";
document.getElementById(extLinkDivID).style.display = "none";
htmlObj.blur();
} else {
document.getElementById(extTextDivID).style.display = "none";
document.getElementById(extLinkDivID).style.display = "block";
}
} else {
location.href = entryLink;
return true;
}
} else {
location.href = entryLink;
return true;
}
}
</script>

Now put this code below your entries in your template:

<div id="extLink<$MTEntryID$>">
<a href="<$MTEntryPermalink$>">Permalink</a>
<MTEntryIfAllowComments>
<?php if (<$MTEntryCommentCount$> > 0) { ?>
| <a href="<$MTEntryPermalink$>" name="ext<$MTEntryID pad="1"$>" onclick="showMoreComments(<$MTEntryID$>,'<$MTEntryPermalink$>', this);return false;">Show Comments (<$MTEntryCommentCount$>)</a>
<?php } ?>
| <a href="<$MTEntryPermalink$>#comments">Add your comment</a>
</MTEntryIfAllowComments>
<MTEntryIfAllowPings>
| <a href="<$MTCGIPath$><$MTTrackbackScript$>?__mode=view&entry_id=<$MTEntryID$>" onclick="OpenTrackback(this.href); return false">TrackBack (<$MTEntryTrackbackCount$>)</a>
</MTEntryIfAllowPings>
</div>
<div id="extText<$MTEntryID$>" style="display: none">
<a href="<$MTEntryPermalink$>">Permalink</a>
<MTEntryIfAllowComments>
| <a href="#ext<$MTEntryID pad="1"$>" onclick="showMoreComments(<$MTEntryID$>,0, this);return true;">Hide Comments</a>
| <a href="<$MTEntryPermalink$>#comments">Add your comment</a>
</MTEntryIfAllowComments>
<MTEntryIfAllowPings>
| <a href="<$MTCGIPath$><$MTTrackbackScript$>?__mode=view&entry_id=<$MTEntryID$>" onclick="OpenTrackback(this.href); return false">
TrackBack (<$MTEntryTrackbackCount$>)
</a>
</MTEntryIfAllowPings>
<MTEntryIfAllowComments>
<MTComments>
<$MTCommentBody$>
<p>Posted by <$MTCommentAuthorLink show_email="0"$> at <$MTCommentDate$></p><br>
</MTComments>
</MTEntryIfAllowComments>
<a href="<$MTEntryPermalink$>">Permalink</a>
<MTEntryIfAllowComments>
| <a href="#ext<$MTEntryID pad="1"$>" onclick="showMoreComments(<$MTEntryID$>,0, this);return true;">Hide Comments</a>
| <a href="<$MTEntryPermalink$>#comments">Add your comment</a>
</MTEntryIfAllowComments>
<MTEntryIfAllowPings>
| <a href="<$MTCGIPath$><$MTTrackbackScript$>?__mode=view&entry_id=<$MTEntryID$>" onclick="OpenTrackback(this.href); return false">TrackBack (<$MTEntryTrackbackCount$>)</a>
</MTEntryIfAllowPings>
</div>

20 Responses to "Updated Show/Hide script – (with additional links in the same line)"

1 | mike

December 30th, 2003 at 10:05 pm

Avatar

where exactly would i put this code?

2 | Jennifer

December 30th, 2003 at 10:10 pm

Avatar

The javascript part can go between your <head></head> tags.

The rest can go after your your post (and your more link and/or drop down…) in your template.

My suggestion is make a test template page – dump the code in and see what happens. The best way to learn is by doing just that – putting code in – test. Move code. Test. Change code. Test. etc. etc.

3 | mike

December 30th, 2003 at 10:17 pm

Avatar

d'oh, I posted the comment on the wrong entry. I ment to ask that on the php code you posted before this

4 | Jennifer

December 30th, 2003 at 10:18 pm

Avatar

One additional note – it goes BEFORE your ending </MTEntries> tag…

5 | Jennifer

December 30th, 2003 at 10:19 pm

Avatar

😀 No prob… moving over there to answer…

6 | Doc

December 31st, 2003 at 9:11 am

Avatar

Thanks for the updated Code link (tweezer's edge). I was unaware it had been updated.

Anyway, after installing that I went back and recreated the Expanding Comments code as well (as I used the old combined script) It wasn't hard and only required changing a couple of variables.

Thnaks for posting the updates..

7 | Doc

December 31st, 2003 at 9:14 am

Avatar

I guess I should clear it up..
I made my version without PHP and basically used just the included Javascript from Tweezer's Edge script.

8 | Phoenix

January 5th, 2004 at 9:52 pm

Avatar

Hey guys, I have a question. I used the hide anything script to made my sidebars retractable, but with the new update, it doesnt work anymore. Here is the code:

<span id="varP1234"><a href="#my_favorite_blogs"
onclick="showMore(1234,'#my_favorite_blogs');return false;">Favorite
Blogs »</a><br /></span><div id="varXYZ1234"
style="display: none">
<$MTInclude module="Blogroll"$>
<p> <a href="#my_favorite_blog" onclick="showMore(1234,0);return
false;">« Hide Favorite Blogs</a></p></div>

9 | Phoenix

January 5th, 2004 at 9:53 pm

Avatar

What happens is that when I click on the link, nothing happens.

10 | Jennifer

January 5th, 2004 at 10:03 pm

Avatar

Your "showmore" function needs three variables passed into it (the original "showmoreanything" required two)

In the new version it looks as if the third variable being passed is simply 'this' – I'd have to test it, but I wonder if that alone would do it…

so:
showMore(1234,'#my_favorite_blogs',this);
and
showMore(1234,0,this);

but I haven't tested it so I'm not sure…

11 | Marc

January 6th, 2004 at 2:44 pm

Avatar

I have coded my index page to hide/show comments and it works great with the following exception.

I also have the extended entry code on the page, if their is an extended entry on a post clicking on "show comments" will extend the entry, vice open comments. Is a work around available?

12 | Jennifer

January 6th, 2004 at 3:03 pm

Avatar

The way I did it originally is I had to have TWO seperate functions – one for comments, and one for expanded entries. I will try to play around with it tonight to see if that's still neccessary (ideally, it would be nice if we didn't have to do that…) – If I get it to work – I'll do a new post with whatever code I come up with…

13 | Jennifer

January 6th, 2004 at 9:26 pm

Avatar

Updated with a new post and revised function and code here:
http://www.scriptygoddess.com/archives/004618.php

14 | Hobbes

January 17th, 2004 at 11:52 am

Avatar

Hey, sweet site!

I am triying to use this function to show/hide links placed at the end of my page. I have included the javascript in the head of my template, and implement the links as suggested, but I have (2) main problems:

  • When Clicking the link, the link is actually followed (isn't 'return false' suppossed to stop this behaviour?)
  • Nothing is shown or hidden. Also noteworthy is that the link doesn't become 'slim' as the links below it (used for previous code) and is displayed blockstyle, not inline, by default. I at first suspected it was the <span> tags, but once removed, they proved little help.
  • 15 | Jennifer

    January 17th, 2004 at 1:49 pm

    Avatar

    I don't actually see this code on your page… (??)

    16 | Hobbes

    January 17th, 2004 at 2:10 pm

    Avatar

    ? really? it's behind the 'Links (click to show)' in the first post (Entitled 'test'. Though I am not using the full php implementation, I attempted hardcoding the IDs in my initial run, and combining it with the MTProcessTags feature later to allow for quick posting of links to the blog (without using up the extended entry and excerpt fields).

    Thanks alot! all help is appreciated :)

    17 | Jennifer

    January 17th, 2004 at 10:32 pm

    Avatar

    I mean when I view source – I don't see any of this code in there… I can't find the javascript function, or even see where your implementation is… You've got a lot going on in there…

    18 | KevinDonahue.com

    December 31st, 2003 at 6:11 pm

    Avatar

    Daily Links
    Weapons of Mass Destruction found…in Texas Coming soon? Mini-IPods for around $100 Mini-IPod a good idea or bad? This is not a photo of a Mini-Ipod No, Virginia, there is no Mini-IPod Blog Madness 2003: Enter your best blog…

    19 | The Tweezer's Edge

    December 31st, 2003 at 7:02 pm

    Avatar

    Complaints About "Imporved Extended Entry Script" Post
    Since publishing my post "Improved Extended Entry Script and Template Code for MT", a couple of complaints have surfaced regarding what I wrote. In an MT Forum thread, LisaJill posted a link to my post.  In response, Girlie (a forum…

    20 | belonging

    January 17th, 2004 at 2:16 pm

    Avatar

    test
    I'm trying out this new code to implement expandable content by using this elements. Links (click to show) " style="display: none"> Hide Comments Links (click to close list) » October 5, 2002 10:53 PM: A Sample » Another Sample Hi…

    Featured Sponsors

    Genesis Framework for WordPress

    Advertise Here


    • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
    • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
    • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

    About


    Advertisements