Hello,
I'm trying to display category names on my summary pages of CGBlog.
I'm using BrowseCat to show a page with three categories, this works fine.
Next when clicking on a category link I go to the summary page and can see my category specific articles and I want to show the category name for the articles above the articles.
I tried adding the following to the summary page template but it did not work:
{if $entry->categories}
{foreach from=$entry->categories item='category' name=cat}
{if $category.category_id == $param_category_id}
{assign var='categoryname' value=$category.name}
<p>{$categoryname}</p>
{/if}
{/foreach}
{/if}
I thought this code would use the category_id for the category the articles were from on the page.
Thanks for any help!
Monte
CGBlog How To Show Category Name on Summary Page
-
- Forum Members
- Posts: 64
- Joined: Wed Jul 03, 2013 7:44 pm
Re: CGBlog How To Show Category Name on Summary Page
At his blog:
https://cmscanbesimple.org/blog/breadcr ... ews-module
I use:
https://cmscanbesimple.org/blog/breadcr ... ews-module
I use:
Code: Select all
{if $entry->categories}{$entry->categories[0]['name']}{/if}
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Re: CGBlog How To Show Category Name on Summary Page
In your case it could be a little different as you're on a summary page.
IF the page has articles AND IF all items have one (and only one) category, you could use this code to create the heading before the foreach loop:
If one of the above conditions is not always true there are two ways to cat the category name:
- query the database using a UDT and get the name based on the id in ($actionparams['category_id'])
- save the category_id and call CGBlog's browsecat action with a template that only displays the name of the category that matches the saved id (inefficient).
IF the page has articles AND IF all items have one (and only one) category, you could use this code to create the heading before the foreach loop:
Code: Select all
{if $items[0]->categories}{$items[0]->categories[0]['name']}{/if}
- query the database using a UDT and get the name based on the id in ($actionparams['category_id'])
- save the category_id and call CGBlog's browsecat action with a template that only displays the name of the category that matches the saved id (inefficient).
-
- Forum Members
- Posts: 64
- Joined: Wed Jul 03, 2013 7:44 pm
[SOLVED] Re: CGBlog How To Show Category Name on Summary Page
Thank you Rolf and Velden! I really appreciate you both posting. Your posts both have helped me. As Velden mentioned I am on a summary page, really I'm using the browsecat action to display specified categories, which is working but I was looking to add the category name the user chooses on the articles summary page using the $param_category_id. I would have to match check the categories array for a category.id that matched the $param_category_id. I like Velden's approach as I will have multiple categories per article and would prefer not to use the first category as the presented page category name. Thanks again for posting I appreciate your help.
Re: CGBlog How To Show Category Name on Summary Page
Quick and dirty (needs some checks and error handling actually) but you get the idea:
UDT name: print_cgblog_cat_name
Example usage in summary template for category:
UDT name: print_cgblog_cat_name
Code: Select all
$db = cmsms()->GetDb();
$query = 'SELECT long_name FROM ' . cms_db_prefix() . 'module_cgblog_categories WHERE id = ?';
$category_name = $db->GetOne($query,array($params['catid']));
echo $category_name;
Code: Select all
<h3>{print_cgblog_cat_name catid=$actionparams['category_id']}</h3>
-
- Forum Members
- Posts: 64
- Joined: Wed Jul 03, 2013 7:44 pm
Re: CGBlog How To Show Category Name on Summary Page
Velden, thank you again! I will give this a try, I had no idea on how I was going to create the UDT LOL!