scriptygoddess

13 Jan, 2003

Expanding Categories

Posted by: Jennifer In: Scripts

Michael asked me to do a version of my script here for categories (It's PHP). It was actually easier to do. (The code for this is shown in the "show more" block)…

but I'm working on doing this as a "show/hide" expand option. (It shows a list of categories, you click on the category and it shows the entries for that category). If this is already done somewhere, save my sanity and post the link… otherwise I'll update this post when I have time to figure it out.

UPDATE: I've now also added the code that uses the "hide/show more" javascript below This also uses a little bit of PHP, but if you need it without, I think there's an easy way to make it 100% javascript.

Ok, here's the code to do the php version of that "show/hide" categories:

<MTCategories>
<a href="<? echo $PHP_SELF."?showcat=<$MTCategoryLabel dirify="1"$>
" ?>"><$MTCategoryLabel$></a><br>
<?
if (isset($showcat) && ($showcat == <$MTArchiveCategory dirify="1"$>)) {
?>
<MTEntries>
» <$MTArchiveDate format="%B %e, %Y %I:%M %p"$>: <a href="<$MTEntryPermalink$>"><$MTEntryTitle$></a><br />
</MTEntries>
<? } ?>
</MTCategories>

Demo shown here.

———————————————————————————-

Now here's the code for the same, but using the "show/hide" javascript. (Again there is a little bit of PHP used here, but if you can't use PHP, I think there's a way to make it all javascript). Put the code below in between your <head> </head> tags. (I copied this from Kristine's show/hide archives)

<script language="javascript">
function showMoreCat(archnum, archlink){
hid = ('hide' + (archnum));
unhid = ('click' + (archnum));
if( document.getElementById ) {
if( document.getElementById(hid).style.display ) {
if( archlink != 0 ) {
document.getElementById(hid).style.display = "block";
document.getElementById(unhid).style.display = "none";
} else { document.getElementById(hid).style.display = "none";
document.getElementById(unhid).style.display = "block"; }
} else { location.href = archlink;
return true; }
} else { location.href = archlink;
return true; }
}
</script>

And this is the code for where the category list goes…

<?
$layernum = 100;
?>
<MTCategories>
<span id="click<? echo $layernum; ?>"><a href="<$MTCategoryArchiveLink$>" onclick="showMoreCat(<? echo $layernum; ?>,'<$MTCategoryArchiveLink$>');return false;"><b><$MTCategoryLabel$> (click to show posts)</b></a><br /></span>
<div id="hide<? echo $layernum; ?>" style="display: none">
<a href="#" onclick="showMoreCat(<? echo $layernum; ?>,0);return true;">
<b><$MTCategoryLabel$> (click to close list)</b></a><br>
<MTEntries>
» <$MTArchiveDate format="%B %e, %Y %I:%M %p"$>: <a href="<$MTEntryPermalink$>"><$MTEntryTitle$></a><br />
</MTEntries>
<a href="#" onclick="showMoreCat(<? echo $layernum; ?>,0);return true;">
<b>close list</b></a><br><br></div>
<br>
<?
$layernum++;
?>
</MTCategories>

Demo for this shown here.

17 Responses to "Expanding Categories"

1 | mike

January 13th, 2003 at 10:22 pm

Avatar

you can also demo it here. Thanks Jenn, this is exactly what I was looking for!

2 | Catherine

January 16th, 2003 at 8:08 pm

Avatar

This may be a stupid question and probably fairly simple, but considering I have never used or for that matter implemented "categories" on my site, I am at a loss here.

How would one set up the archives for this to work, or rather for "categories"? Currently I am only archiving 'individual' and 'monthly'. My individual configuration is set up like so:

<$MTArchiveDate format="%Y/%m"$>/<$MTEntryID pad="1"$>.php

…and my monthly are set up like this:

<$MTArchiveDate format="%Y/%m/index.php"$>

So I would like to try and do something similar if possible, that is unless I have gone completely brain dead tonight (it's been a long week!), and I am completely not understanding the concept behind category archiving.

For example I noticed when I hovered over the categories shown in the example all start with "cat_" before the actual category. How is that generated? Is that something I need to set up in my archive configuration?

Any help in understanding all this would be appreciated.

3 | Jennifer

January 17th, 2003 at 8:51 am

Avatar

Catherine – I'm pretty sure that the "cat_" before the name is the default. I think you only thing you need to do is go to the "archiving" section (under blog config) and just check the box next to "categories". It'll automatically generate those pages based on your category archive template – and name them with the prefix of "cat_" before them.

Does that help? (If not, email me, and I'll see if I can explain further)

4 | reese

January 19th, 2003 at 11:39 pm

Avatar

Do you think a modification of this would work for expanding/collapsing entries under each month? And just change the MT tags accordingly?

LOVE your site!

reese

5 | Eli

March 18th, 2003 at 11:44 am

Avatar

This code is great! I've been looking for this for my personal blog for awhile now because my category page was starting to get very long. I'm having a problem though. I got this setup the way I want, but the entry links just point straight back to my main page. Can you tell me why? I didn't modify your code much, just added some style tags. You can see it on my test page here. Thanks much!

6 | Lisa

May 24th, 2003 at 2:54 am

Avatar

I tried this on my page (i'm new to MT) and it just went to the regular archived categories page. It's not expanding at all. Basically it's working like i never put that code in, and i'm just using MT's default code for listing the (linked) names of the categories..can you help?? I'm guessing it's because I don't have .php on my site. so i need ALL javascript :(

7 | Lisa

May 28th, 2003 at 12:50 am

Avatar

Fixed above problem by changing over to php. BUT… How can I get it from "jumping" on my page? When I click on a category, it jumps to the top of my page.. I can't stand that! HELP!! :) Please.

8 | Jennifer

May 28th, 2003 at 7:19 am

Avatar

Lisa – can you post a URL?

9 | Lisa

May 28th, 2003 at 8:02 pm

Avatar

Hehe silly me. I figured since I put it above, i didn't need to put it here..
It's http://www.lisaandben.com/alittlebitoflisa
If you are at the absolute top of the page, it's fine, but if I move slightly down the page, it snaps back up to the top..

10 | Jennifer

May 28th, 2003 at 8:24 pm

Avatar

It looks like you're using the first version of the code which refreshes the page and is php only) the second version of the code is php and javascript – that's the one that will keep your place on the page (because it doesn't refresh the page). (That's why I asked for the URL – because I wasn't sure you had given the right one…)

11 | Lisa

May 28th, 2003 at 9:23 pm

Avatar

Ahhhhh. ok.. Thanks a bunch. I have it on my site now http://www.lisaandben.com/alittlebbitolisa
and it doesn't jump when I click it but it jumps if i click it to close it.. is there anything that can be done with that? And how do I get a count of how many entries are in each category.. i think i had it on before, but i can't seem to find it again.
Thanks In Advance.
lisa

12 | Lisa

May 29th, 2003 at 9:21 pm

Avatar

http://www.lisaandben.com/alittlebitoflisa
HELP! I installed the javascript version and now all but one of the categories work. the one that doesn't work, opens another show/hide block.
That block is using the show/hide anything script.
I think I fixed it by changing the layernumber from 100 to 200. is that ok??

13 | lisa

May 29th, 2003 at 9:46 pm

Avatar

Ok, I had to change it back to layernumber 100. after I changed it the first time, and rebuilt it, the screen where I upload new templates were acting funny…so I assumed it was because I changed it to 200…sigh.
lisa
http://www.lisaandben.com/alittlebitoflisa

14 | inluminent/weblog

January 17th, 2003 at 2:50 am

Avatar

Busy Day: Links on marketing, business, code, and whatever else I found
Here's a list of links for you to peruse on Friday: Hoover's & D&B: Perfect Together? from the Perkins Group

15 | Code Novice

April 29th, 2004 at 9:26 pm

Avatar

Show / Hide Category Posts
I've been looking for this script forever and wouldn't you…

16 | Code Novice

April 29th, 2004 at 11:57 pm

Avatar

Bookmarks Abound
[Edited to add my apologies if I pinged your entry…

17 | judy

October 5th, 2004 at 12:28 pm

Avatar

THANKS for this script. I'd like to use it as a sidebar menu on every category page….is it easy to have the menu items remain the same no matter what category or subcategory page the menu is used on (sorry, I don't know enough about JS)?
thanks again,

judy

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