Keyword

K2 Content Mod displayed on Cat. Page > Echo Cat. Name

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
8 years 6 months ago #148071 by Joe Campbell
Scenario: Displaying a K2 Content Module on a Category Page.

Challenge: How do you echo the Category Name for the page?

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 6 months ago #148114 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 Content Mod displayed on Cat. Page > Echo Cat. Name
Where do you want the title to show up?
You can print the menu item's title in your template.
<?php
$app	 = JFactory::getApplication();
$menu = $app->getMenu();
$active = $menu->getActive();
$pageHeading = '';
if ($active) {
  $pageHeading = $active->params->get('page_heading');
}
?>
<h2><?php echo $pageHeading; ?></h2>

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
8 years 6 months ago #148118 by Joe Campbell
Actually, I would like to perform conditional statements within the K2 Content Module (based on the current category):

<?php if($this->category->value == 'Music' OR
$this->category->value == 'Health' OR
$this->category->value == 'Fitness'): ?>

Is this possible in K2 v2.x?

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 6 months ago #148126 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 Content Mod displayed on Cat. Page > Echo Cat. Name
Yes, but you need different code.
github.com/kricore/Advanced-templating-with-K2/blob/master/_inc/cheatsheet.php#L26-L31

You need to check the menu item's id to determine which category you are currently viewing.

This code is pretty much component-agnostic so you can use it pretty much everywhere in your template.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
8 years 6 months ago #148143 by Joe Campbell
Thanks, but I still do not understand (remember, I am NOT a coder :)

It sounds like the first step is to include the following code into the K2 Content Module override:
$option = JRequest::getCmd('option');
$view 	= JRequest::getCmd('view');
$layout = JRequest::getCmd('layout');
$page 	= JRequest::getCmd('page');
$task 	= JRequest::getCmd('task');
$id 	= JRequest::getInt('id');

So the real question is, what code would I use to execute the following?

request 1
If CATEGORY A [or] CATEGORY B - display XYZ

request 2
echo current category

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 6 months ago #148146 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 Content Mod displayed on Cat. Page > Echo Cat. Name
The easiest way would be to map the menu item's id.
$itemid 	= JRequest::getInt('Itemid');

if( $itemid == 123 ) { 
  echo 'this is something';
} else {
  echo 'this is another category';
}

PS. I 'll add the itemid in the repo as well.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
8 years 6 months ago #148217 by Joe Campbell
Thanks Krikor :)

Is $id for the menu ID and $itemid for the K2 item ID?

How do I access the menu category ID?

Please Log in or Create an account to join the conversation.

More
8 years 6 months ago #148223 by Lefteris
@Joe Campbell

No, it's the opposite. Also remember to keep your module off caching otherwise your custom code will run only once and subsequent requests will display the cached result.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
8 years 6 months ago #148242 by Joe Campbell
Thanks Lefteris & Krikor :)

Please Log in or Create an account to join the conversation.

More
8 years 6 months ago #148258 by Lefteris
You are welcome.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum