news: category nav menu?

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
mikemee
Forum Members
Forum Members
Posts: 20
Joined: Sun May 21, 2006 11:31 am

news: category nav menu?

Post by mikemee »

This seems like it should be simple so I've probably overlooked it somewhere, but I tried!

I'd like to have a submenu menu on my News page that uses categories to populate itself. I.e., if I add/remove a category the menu would change accordingly, and if I click on a category it would filter and show only the news items in that category.

Oh, and of course I'd like a 'show all' button, though I could live without it if need be.

Fwiw, I don't have any nested categories.

thanks in advance!

cheers,  michael
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: news: category nav menu?

Post by Dr.CSS »

you could use the News module to show the "menu" ie. just make a news call {cms_module module='News' summarytemplate='yourtemplate.tpl'}
make a new template,  (optional) summarytemplate="sometemplate.tpl" - Use a separate template for displaying the article summary. It have to live in modules/News/templates.
(optional) detailtemplate="sometemplate.tpl" - Use a separate template for displaying the article detail. It have to live in modules/News/templates.,
from News Help,, by copying one of the original ones and strip out the 'calls' you don't need...

  new name if you want, for styling so other news styling don't interfere..

    delete if you don't need... same with other calls
{$entry->titlelink}   



{$entry->category}
                              this you want to keep ...

{if $entry->formatpostdate}

{$entry->formatpostdate}

{/if}
  ....etc. etc.  deletable along with other none needed calls... some times i just delete the {$entry->formatpostdate} part and it won't show or mess up the {if... } statements
cyberman

Re: news: category nav menu?

Post by cyberman »

mikemee wrote: it would filter and show only the news items in that category.
Mark i think this will be the main problem - we need categories as clickable links ::) ...
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: news: category nav menu?

Post by Dr.CSS »

me thinks Categories on a single page may be a way to make a link... not sure how to make the call to that page on the fly yet... it's needed for sure because i made the"Blog" out of News and have a need for the category link meself will have to come up with template for that...
like...


  category}">?? need to find a way to print out the name of the category between> maybe >{$entry->category} again... but it still needs somewhere for the link to go...
mikemee
Forum Members
Forum Members
Posts: 20
Joined: Sun May 21, 2006 11:31 am

Re: news: category nav menu?

Post by mikemee »

Since I only have a few categories so far, I'm wondering if there's another way to solve this. Not as elegant, but good enough.

Is there some way to pass a parameter from a Content page to a Template?

I'm thinking I'll setup one template and add one News sub-page for each Category I have. If I can pass the Category into the template so it can be passed to the category parameter of the call. For example, I could set the Title to be the category name. If so, how do I make this work:

        {cms_module module='news' number='5' category=$title}

I'm hoping this is a trivial - I'm a CMSMS beginner. The above doesn't work, and these links seemed relevant, but I couldn't find quite the right syntax: http://forum.cmsmadesimple.org/index.ph ... 065.0.html, http://forum.cmsmadesimple.org/index.ph ... 385.0.html.

Of course the downside of this approach is that it doesn't auto adapt when I create a new News Category. But I can live with that!

thx, michael
Last edited by mikemee on Thu Jun 01, 2006 10:04 am, edited 1 time in total.
mikemee
Forum Members
Forum Members
Posts: 20
Joined: Sun May 21, 2006 11:31 am

Re: news: category nav menu?

Post by mikemee »

I discovered the get_template_vars code and played around a bit more with this and found a solution that works well enough.  In brief, it is:

1) create a master page, e.g. "News" of type News
2) Create a matching template. I used EllNav Horiz/Vert L 1col as the starting point.
3) In the new template (EllNav Horiz/Vert L 1col News), add the lines:

     
     
        {cms_module module="news" category="$page"}
     
     


4) create a set of regular content pages that are nested below your News page with one page corresponding to each category in your news. Use the new template in each page, and be sure to Name the page to correspond to the category name you wish to show

That's it!  You'll now get a nav bar which shows subsets of each news item - because the $page variable corresponds to the category name.

I combined this with the {parent_title} addition described http://wiki.cmsmadesimple.org/index.php ... nu_Heading to get a heading over the menu bar. And I tweaked it slightly to add a link to 'All' to the heading just to make it a little more obvious (the main menu bar is an alternative).  I.e., in the template I had:

     
     
        Sub Navigation
        {parent_title} [All]
          {cms_module module='menumanager' template='ellnav-accessible.tpl' start_level='2' collapse='1'}
     
     
     


Hope this helps someone else. 
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: news: category nav menu?

Post by Dr.CSS »

got a link to a working model?
cyberman

Re: news: category nav menu?

Post by cyberman »

mark wrote: me thinks Categories on a single page may be a way to make a link...
Upps, have found a patch on news project what will do that ...

http://dev.cmsmadesimple.org/tracker/in ... 8&atid=111
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: news: category nav menu?

Post by Dr.CSS »

and how do we use a .diff file?
cyberman

Re: news: category nav menu?

Post by cyberman »

You can use the (un*x-like) patch command ...

The other option is to open the diff file with your favourite editor. There you will found the files to change and you will see lines with [-/+] to change  ;). You can also see the rigth position for changes.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: news: category nav menu?

Post by Dr.CSS »

You can use the (un*x-like) patch command ...  the what?...  ???

still not sure what all this means.... but i will say it looks better pasted in here than it did in notepad...

diff -urN cmsmadesimple-0.13/lib/classes/class.content.inc.php cmsmadesimple-0.13.tglx/lib/classes/class.content.inc.php
--- cmsmadesimple-0.13/lib/classes/class.content.inc.php 2006-05-09 01:41:15.000000000 +0200
+++ cmsmadesimple-0.13.tglx/lib/classes/class.content.inc.php 2006-05-27 16:12:17.000000000 +0200
@@ -2352,6 +2352,28 @@  these are the lines to take out and add?
}


+ function GetPageTitleFromID( $id )
+ {
+ global $gCms;
+ $db = &$gCms->GetDb();
+
+ if (!is_numeric($id) && strpos($id,'.') == TRUE && strpos($id,',') == TRUE)
+ {
+ return $id;
+ }
+
+ $params = array($id);
+ $query = "SELECT * FROM ".cms_db_prefix()."content WHERE content_id = ?";
+ $row = $db->GetRow($query, $params);
+
+ if ( !$row )
+ {
+ return false;
+ }
+ return $row['content_name'];
+ }
+
+
function CheckAliasError($alias, $content_id = -1)
{
global $gCms;
diff -urN cmsmadesimple-0.13/modules/News/action.default.php cmsmadesimple-0.13.tglx/modules/News/action.default.php
--- cmsmadesimple-0.13/modules/News/action.default.php 2006-05-17 04:05:58.000000000 +0200
+++ cmsmadesimple-0.13.tglx/modules/News/action.default.php 2006-05-27 16:15:14.000000000 +0200
@@ -36,6 +36,13 @@

if (isset($params["category"]) && $params["category"] != '')
{
+ if ($params["category"] == 'content_alias')
+ {
+     $alias = '*';
+     $alias .= ContentManager::GetPageAliasFromID( $returnid );
+     $alias .= '*';
+     $params['category'] = $alias;
+ }
$categories = explode(',', $params['category']);
$query = "SELECT mn.*, mnc.news_category_name FROM " . cms_db_prefix() . "module_news mn LEFT OUTER JOIN " . cms_db_prefix() . "module_news_categories mnc ON mnc.news_category_id = mn.news_category_id WHERE status = 'published' AND (";
$count = 0;
@@ -143,6 +150,11 @@
$onerow->link = $this->CreateLink($id, 'detail', $detailpage!=''?$detailpage:$returnid, '', $sendtodetail,'', true, false, '', true, $prettyurl);
$onerow->titlelink = $this->CreateLink($id, 'detail', $detailpage!=''?$detailpage:$returnid, $row['news_title'], $sendtodetail, '', false, false, '', true, $prettyurl);
$onerow->morelink = $this->CreateLink($id, 'detail', $detailpage!=''?$detailpage:$returnid, $moretext, $sendtodetail, '', false, false, '', true, $prettyurl);
+ $catid = ContentManager::GetPageIDFromAlias($onerow->category);
+ if ($catid != false && $catid != $returnid) {
+ $contenttitle = ContentManager::GetPageTitleFromID($catid);
+ $onerow->categorylink = $this->CreateContentLink($catid, $contenttitle);
+ }
$sendtoprint = array('articleid'=>$row['news_id'],'showtemplate'=>'false');
if (isset($params['lang']))
{
cyberman

Re: news: category nav menu?

Post by cyberman »

mark wrote: You can use the (un*x-like) patch command ...  the what?...  ???
http://unxutils.sourceforge.net/

But cause I've not the knowledge to use  ;D, I'm doing the following ...
but i will say it looks better pasted in here than it did in notepad...
I don't like notepad - wordpad does it better (line breaks)  ;) ...

Go to this file
cmsmadesimple-0.13/lib/classes/class.content.inc.php
and this line
-2352
and add near this part

Code: Select all

+	function GetPageTitleFromID( $id )
+	{
+		global $gCms;
+		$db = &$gCms->GetDb();
+
+		if (!is_numeric($id) && strpos($id,'.') == TRUE && strpos($id,',') == TRUE)
+		{
+			return $id;
+		}
+
+		$params = array($id);
+		$query = "SELECT * FROM ".cms_db_prefix()."content WHERE content_id = ?";
+		$row = $db->GetRow($query, $params);
+
+		if ( !$row )
+		{
+			return false;
+		}
+		return $row['content_name'];
+	}
+
+
If you have done, once again the same procedure with this file
cmsmadesimple-0.13/modules/News/action.default.php
and this line
-36

if (isset($params["category"]) && $params["category"] != '')
{

Code: Select all

+			if ($params["category"] == 'content_alias') 
+			{
+			    $alias = '*';
+			    $alias .= ContentManager::GetPageAliasFromID( $returnid );
+			    $alias .= '*';
+			    $params['category'] = $alias;
+			}
and so one
143

Code: Select all

+			$catid = ContentManager::GetPageIDFromAlias($onerow->category);
+			if ($catid != false && $catid != $returnid) {
+				$contenttitle = ContentManager::GetPageTitleFromID($catid);
+				$onerow->categorylink = $this->CreateContentLink($catid, $contenttitle);
+			}
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: news: category nav menu?

Post by Dr.CSS »

Thanx  :)
jezjones
New Member
New Member
Posts: 5
Joined: Tue Feb 12, 2008 4:21 pm

Re: news: category nav menu?

Post by jezjones »

This topic title is just what i was looking for, however after reading this whole post and being a fairly established developer, i am astounded that the solution is so complex.

Really, this is ridiculous.
I am implementing a CMS for some designers and they want simple. So far, loving cmsmadesimple, but i would consider the news module to beta if it cannot list its own categories with out some serious patching of core files.

Any suggestions?
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: news: category nav menu?

Post by Dr.CSS »

Actually the latest News will make a clickable list of categories, this thread is old, use the browsecat="1" with the news tag...
Post Reply

Return to “Modules/Add-Ons”