[MOD] Categories in header like Digg (useful if you have subcategories)

Register an Account
Pligg Chat Room
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-26-2007, 02:14 PM
dollars5's Avatar
Pligg Donor
 
Join Date: Dec 2006
Location: India
Posts: 1,961
UPDATE: Included manager456's code to display the categories link properly while in published and in unpublished pages - thanks manager456 .

This can be sen live at Meme or Lame / Published News

in header.tpl adding this code to where ever you want to display the categories strip.
Code:
{if $pagename eq 'published' || $pagename eq 'upcoming'}
{******Get the parent category******}
	{assign var=requested_cat value=$request_category}

	{* if story page - set the story's category to this *}
	{if $pagename eq 'story'}

		{assign var=requested_cat value='sub'}
	{/if}

	{assign var=mainCatStr value=''}
	{assign var=parentCat value=-1}
	{section name=thecat loop=$cat_array}
		{if $cat_array[thecat].safename eq $requested_cat}
			{if $cat_array[thecat].parent neq 0}
				{assign var=parentCat value=$cat_array[thecat].parent}
				{assign var=mainCatStr value=$cat_array[$parentCat].safename}
			{else}
				{assign var=parentCat value=$cat_array[thecat].auto_id}
				{assign var=mainCatStr value=$cat_array[thecat].safename}
			{/if}
		{/if}
	{/section}

{********* Displaying the Main categories *******************}
	<div id="headbar" style="border-bottom:1px solid #ccc;padding-bottom:4px">
	{section name=thecat loop=$cat_array}

		{if $cat_array[thecat].parent eq 0}
			{if $cat_array[thecat].safename eq $requested_cat || $cat_array[thecat].auto_id eq $parentCat}
				{if $pagename eq "published"}
					<a href="{$URL_maincategory, $cat_array[thecat].safename}" style="padding-bottom:5px;">{$cat_array[thecat].name}</a>
				{else}
					<a href="{$URL_queuedcategory, $cat_array[thecat].safename}" style="padding-bottom:5px;">{$cat_array[thecat].name}</a>
				{/if}
			{elseif $requested_cat eq "" && $cat_array[thecat].auto_id eq 0}
				{if $pagename eq "published"}
					<a href="{$URL_maincategory, $cat_array[thecat].safename}" style="padding-bottom:5px;">{$cat_array[thecat].name}</a>
				{else}
					<a href="{$URL_queuedcategory, $cat_array[thecat].safename}" style="padding-bottom:5px;">{$cat_array[thecat].name}</a>
				{/if}
			{else}
				{if $pagename eq "published"}
					<a href="{$URL_maincategory, $cat_array[thecat].safename}" style="padding-bottom:5px;">{$cat_array[thecat].name}</a>
				{else}
					<a href="{$URL_queuedcategory, $cat_array[thecat].safename}" style="padding-bottom:5px;">{$cat_array[thecat].name}</a>
				{/if}
			{/if}
		{/if}
	{/section}</div>
	<br/>
	{********* Displaying the Sub categories *******************}
	<span>
	{if $parentCat gt 0}
		<div id= "headbar" style="border-bottom:1px solid #ccc;padding-bottom:4px">
		{if $requested_cat eq $mainCatStr}
			{if $pagename eq "published"}
				<a href="{$URL_maincategory, $cat_array[thecat].safename}" style="padding-bottom:5px;">{$cat_array[thecat].name}</a>
			{else}
				<a href="{$URL_queuedcategory, $cat_array[thecat].safename}" style="padding-bottom:5px;">{$cat_array[thecat].name}</a>
			{/if}

		{else}

			{if $pagename eq "published"}
				<a href="{$URL_maincategory, $cat_array[thecat].safename}" style="padding-bottom:5px;">{$cat_array[thecat].name}</a>
			{else}
				<a href="{$URL_queuedcategory, $cat_array[thecat].safename}" style="padding-bottom:5px;">{$cat_array[thecat].name}</a>
			{/if}
		{/if}
		{section name=thecat loop=$cat_array}
			{if $cat_array[thecat].parent eq $parentCat}
				{if $cat_array[thecat].safename eq $requested_cat}
					{if $pagename eq "published"}
						<a href="{$URL_maincategory, $cat_array[thecat].safename}" style="padding-bottom:5px;">{$cat_array[thecat].name}</a>
					{else}
						<a href="{$URL_queuedcategory, $cat_array[thecat].safename}" style="padding-bottom:5px;">{$cat_array[thecat].name}</a>
					{/if}

				{else}
					{if $pagename eq "published"}
						<a href="{$URL_maincategory, $cat_array[thecat].safename}" style="padding-bottom:5px;">{$cat_array[thecat].name}</a>
					{else}
						<a href="{$URL_queuedcategory, $cat_array[thecat].safename}" style="padding-bottom:5px;">{$cat_array[thecat].name}</a>
					{/if}

				{/if}
			{/if}
		{/section}
		</div>
	{/if}</span>


	{elseif $pagename neq 'submit'}
	{********* Displaying the Main categories *******************}
	<div style="border-bottom:1px solid #ccc;padding-bottom:4px">
	{section name=thecat loop=$cat_array}
	
		{if $cat_array[thecat].parent eq 0}
			<a href="{$URL_maincategory, $cat_array[thecat].safename}">{$cat_array[thecat].name}</a>
		{/if}
	{/section}
	

	<br/>
	{else}<div id="border" style="border-bottom:6px solid #fff;padding:12px"></div>
	{/if}
</ul></div>
There are different scenarios we deal with this code:
1] If the page is published/upcoming - it tries to get the current category and highlight it
2] If the page is a story page only mai categories will get displayed[EDIT:]again we try to get the current category of the story and set a highlight class to it[/EDIT]
3] for other pages just display only the main categories.

the code will expand subcategories if user selects a main category or a story belong to a sub-category.

In submit we have taken care that user can select only sub-categories.

Last edited by dollars5; 07-15-2007 at 09:51 AM.
Reply With Quote
  #2 (permalink)  
Old 05-26-2007, 04:39 PM
Constant Pligger
 
Join Date: Apr 2007
Posts: 168
dollars5, thx for the great mod!

I am looking for functionality where I have only the 'main' categories displayed in the sidebar and the 'sub-categories' displayed in the menu. So basically hide subcategories in the sidebar and only display in the header.

How could I modify the 2 items (sidebar and header) to make this happen?

Thx

Last edited by aaronpais; 05-26-2007 at 05:15 PM.
Reply With Quote
  #3 (permalink)  
Old 05-26-2007, 05:28 PM
wwwSENSERELYcom's Avatar
Casual Pligger
 
Join Date: May 2007
Location: Tianjin, China
Posts: 67
thank you, but on my beta9.5 yget this functionnality doesn't work:
2] If the page is a story page again we try to get the current category of the story and set a highlight class to it

when I'm on a story of a subcategory, I have only the line of the main categories.
Reply With Quote
  #4 (permalink)  
Old 05-26-2007, 10:30 PM
dollars5's Avatar
Pligg Donor
 
Join Date: Dec 2006
Location: India
Posts: 1,961
Quote:
Originally Posted by wwwSENSERELYcom View Post
thank you, but on my beta9.5 yget this functionnality doesn't work:
2] If the page is a story page again we try to get the current category of the story and set a highlight class to it

when I'm on a story of a subcategory, I have only the line of the main categories.
Hi James thanks for noting, I have edited the original post - for stories, there is no request_category so only main categories will get displayed. Actually we did work on trying to get the category - but for some reason - it did not work. [It would require an additional query t o get it]
Reply With Quote
  #5 (permalink)  
Old 05-27-2007, 01:02 AM
New Pligger
 
Join Date: Nov 2006
Posts: 29
In the story submit page, I want the categories displayed in radio buttons like in Digg, how to do that?
Reply With Quote
  #6 (permalink)  
Old 05-27-2007, 02:00 AM
dollars5's Avatar
Pligg Donor
 
Join Date: Dec 2006
Location: India
Posts: 1,961
check here for radio button category selection http://forums.pligg.com/questions-comments/6625-mod-submit-step2-digg-like-categories-selection-radio-button-post30143.html
Reply With Quote
  #7 (permalink)  
Old 06-04-2007, 12:08 AM
Genghis's Avatar
Casual Pligger
 
Join Date: Mar 2007
Posts: 57
I've just got a quick "if statement" question.

Dollars, I'd really appreciate your help with this. I think it's simple...

How would I go making a statement in categories.tpl that does the following actions:

{if category_mainlevel}
<div class="mainlevel">
{elseif category_secondlevel}
<div class="secondlevel">
{/if}

Basically, I just want the browser to read <div class="mainlevel"> when no subcategories are displayed and then to read <div class="secondlevel"> in its place when subcategories are displayed. help please...!
Reply With Quote
  #8 (permalink)  
Old 06-04-2007, 06:55 AM
dollars5's Avatar
Pligg Donor
 
Join Date: Dec 2006
Location: India
Posts: 1,961
categories.tpl? I dont see such a file - can you post it in here pls - that should provide me some idea to proceed.

The above presented code is to be used in header.tpl to get a digg style categories.
Reply With Quote
  #9 (permalink)  
Old 06-04-2007, 01:12 PM
Genghis's Avatar
Casual Pligger
 
Join Date: Mar 2007
Posts: 57
Dollars,


categories.tpl can be found in the sidebar_modules folders of the yget template. What I did (and I think this is more consistent with the development of the templates) is just change the categories code in categories.tpl.

Then in pligg.tpl, I added the following code:

HTML Code:
{assign var=sidebar_module value="categories"}
{include file=$the_template_sidebar_modules."/wrapper.tpl"}
placing the categories wherever I want dynamically in pligg.tpl and not having to actually 'move' it to 'header.tpl'.

I've attached my categories.tpl file anyway...but it's non-sequitur, as I'm wondering what {if} statement to use to invoke the commands I posted for originally....
Attached Files
File Type: tpl categories.tpl (2.9 KB, 199 views)
Reply With Quote
  #10 (permalink)  
Old 06-04-2007, 09:26 PM
dollars5's Avatar
Pligg Donor
 
Join Date: Dec 2006
Location: India
Posts: 1,961
I really doubt this code will work in the sidebar - because all info needed by this is available only in the header.tpl file.

I will see my best to get it on to side-bar - the best guy who can help with smarty stuff is Beatniak - try PMming him - he might put his suggestions.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
[MOD] Submit-step2 Digg like categories selection with radio button dollars5 Questions and Comments 71 09-09-2009 03:10 PM
Shredit - Categories on header? b4ifuru18 Questions and Comments 2 07-22-2009 09:13 PM
In 1.0RC5 - Digg like categories in Submit-step2 selection with radio button arif1999 Questions and Comments 1 07-02-2009 10:46 AM
HELP: Drop Down Categories in Header Tutorial for ver 9.9.5 arkasun Questions and Comments 3 10-19-2008 09:39 PM
Categories like in Digg rhythm Questions and Comments 7 05-26-2007 02:14 PM


Pligg Modules and Pligg Templates from Pligg Pro Find support on the Pligg CMS Forum - 24 hours a day! Make a donation to support Pligg CMS development