- Posts: 438
COMMUNITY FORUM
- Forum
- K2 Community Forum
- English K2 Community
- K2 Content Mod displayed on Cat. Page > Echo Cat. Name
K2 Content Mod displayed on Cat. Page > Echo Cat. Name
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
Less
More
9 years 6 months ago #148071
by Joe Campbell
K2 Content Mod displayed on Cat. Page > Echo Cat. Name was created by Joe Campbell
Scenario: Displaying a K2 Content Module on a Category Page.
Challenge: How do you echo the Category Name for the 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
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
9 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.
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>
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 438
9 years 6 months ago #148118
by Joe Campbell
Replied by Joe Campbell on topic K2 Content Mod displayed on Cat. Page > Echo Cat. Name
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?
<?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
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
9 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.
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.
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 438
9 years 6 months ago #148143
by Joe Campbell
Replied by Joe Campbell on topic K2 Content Mod displayed on Cat. Page > Echo Cat. Name
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:
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
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
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
9 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.
PS. I 'll add the itemid in the repo as well.
$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.
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 438
9 years 6 months ago #148217
by Joe Campbell
Replied by Joe Campbell on topic K2 Content Mod displayed on Cat. Page > Echo Cat. Name
Thanks Krikor :)
Is $id for the menu ID and $itemid for the K2 item ID?
How do I access the menu category ID?
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.
- Lefteris
-
- Offline
- Platinum Member
Less
More
- Posts: 8743
9 years 6 months ago #148223
by Lefteris
Replied by Lefteris on topic K2 Content Mod displayed on Cat. Page > Echo Cat. Name
@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.
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.
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 438
9 years 6 months ago #148242
by Joe Campbell
Replied by Joe Campbell on topic K2 Content Mod displayed on Cat. Page > Echo Cat. Name
Thanks Lefteris & Krikor :)
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Platinum Member
Less
More
- Posts: 8743
9 years 6 months ago #148258
by Lefteris
Replied by Lefteris on topic K2 Content Mod displayed on Cat. Page > Echo Cat. Name
You are welcome.
Please Log in or Create an account to join the conversation.
- Forum
- K2 Community Forum
- English K2 Community
- K2 Content Mod displayed on Cat. Page > Echo Cat. Name