- Posts: 40
COMMUNITY FORUM
if category statement
- John-Eilif Eliassen
-
Topic Author
- Offline
- Senior Member
in mod_k2_content.php i am trying to configure an if / else statement that shows a message if certain category but nothing if other categories..
This is what i have tried
This works, but only for all categories. What if (categoryid = 5) statement do i have to throw in to display this message only for certain div? I have no idea of how to call if statements..
if (count($items))
{
require (JModuleHelper::getLayoutPath('mod_k2_content', $getTemplate.DS.'default'));
}
else
{
echo '<div class="noerrors"><i class="fa fa-info" aria-hidden="true"></i> No errors. </div>';
}
Appreciate any answers.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
You want in the items' loop a check whether an individual item belongs to a certain category.
If that is the case, then display a message, right?
Please Log in or Create an account to join the conversation.
- John-Eilif Eliassen
-
Topic Author
- Offline
- Senior Member
- Posts: 40
Krikor wrote: Let me see if I get you right.
You want in the items' loop a check whether an individual item belongs to a certain category.
If that is the case, then display a message, right?
Hi Krikor.
What i want to achieve. I understand that i might be explaining myself very poorly at times..
I use multiple content modules to get articles from one category each. And there are several categories (10+ categories, 10+ modules), some which will be empty at times.
All categories(modules) should display nothing if there are no articles in them, except one category (content module with ID 1) that should show the message i previously posted if the category is empty. Is this achieveable. This is an internal site on .local so I cannot display much "live action".
Please Log in or Create an account to join the conversation.
- John-Eilif Eliassen
-
Topic Author
- Offline
- Senior Member
- Posts: 40
if (count($items))
{
require (JModuleHelper::getLayoutPath('mod_k2_content', $getTemplate.DS.'default'));
}
else
{
if ($this->category == 'CATEGORY_NAME');
echo '<div class="noerrors"><i class="fa fa-info" aria-hidden="true"></i> No errors. </div>';
}
else
{
}
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
In the K2 content module locate this line:
<?php foreach ($items as $key=>$item): ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; if(count($items)==$key+1) echo ' lastItem'; ?>">
This is the start of each item's layout.
The check should be performed right after this line of code.
<?php if($item->categoryname == 'CATEGORY_NAME'):
echo '<div class="noerrors"><i class="fa fa-info" aria-hidden="true"></i> No errors. </div>';
else: ?>
You now need a closing endif statement which should be placed before this line of code.
</li>
<?php endforeach; ?>
Please Log in or Create an account to join the conversation.
- John-Eilif Eliassen
-
Topic Author
- Offline
- Senior Member
- Posts: 40
That is my hassle. I have created templates for the various module versions. But one of the categories only show featured articles and we will toggle/unfeature if they are no longer relevant (1 article view).
So at times it will be "empty" and we need some info that it is empty, but with all other content modules it should just dissapear.
Please Log in or Create an account to join the conversation.
- John-Eilif Eliassen
-
Topic Author
- Offline
- Senior Member
- Posts: 40
{
if($item->categoryname == 'Varsel'):
echo ''<div class="noerrors"><i class="fa fa-info" aria-hidden="true"></i> No errors. </div>';
else
{
}
}
Is it possible to do something like this in mod_k2_content.php file? Because it never gets to template view if the category is empty.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Just follow the instructions on my previous post.
Please Log in or Create an account to join the conversation.
- John-Eilif Eliassen
-
Topic Author
- Offline
- Senior Member
- Posts: 40
Krikor wrote: It is possible but this check will be performed for every item in the loop.
Just follow the instructions on my previous post.
But that will not work if the module has no articles. Because empty module never gets to the template view and therefore the code will not be executed..
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
if (count($items))
{
require (JModuleHelper::getLayoutPath('mod_k2_content', $getTemplate.DS.'default'));
}
If you remove the if (count($items)) check the module will be rendered even if there are no items.
However the module will produce error if you do not move this check in the module's template.
Please Log in or Create an account to join the conversation.