Keyword

if category statement

  • John-Eilif Eliassen
  • John-Eilif Eliassen's Avatar Topic Author
  • Offline
  • Senior Member
More
8 years 3 months ago #155677 by John-Eilif Eliassen
if category statement was created by John-Eilif Eliassen
Hello, i have a question..

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 3 months ago #155685 by Krikor Boghossian
Replied by Krikor Boghossian on topic if category statement
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?

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

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

  • John-Eilif Eliassen
  • John-Eilif Eliassen's Avatar Topic Author
  • Offline
  • Senior Member
More
8 years 3 months ago - 8 years 3 months ago #155721 by John-Eilif Eliassen
Replied by John-Eilif Eliassen on topic if category statement

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".
Last edit: 8 years 3 months ago by John-Eilif Eliassen.

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

  • John-Eilif Eliassen
  • John-Eilif Eliassen's Avatar Topic Author
  • Offline
  • Senior Member
More
8 years 3 months ago #155727 by John-Eilif Eliassen
Replied by John-Eilif Eliassen on topic if category statement
Something like this.. like, the logic is there but the formatting is wrong
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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 3 months ago #155729 by Krikor Boghossian
Replied by Krikor Boghossian on topic if category statement
It is much simpler actually.
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; ?>

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

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

  • John-Eilif Eliassen
  • John-Eilif Eliassen's Avatar Topic Author
  • Offline
  • Senior Member
More
8 years 3 months ago #155785 by John-Eilif Eliassen
Replied by John-Eilif Eliassen on topic if category statement
The message should only appear when the one spesific module is empty tho...

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
  • John-Eilif Eliassen's Avatar Topic Author
  • Offline
  • Senior Member
More
8 years 3 months ago - 8 years 3 months ago #155786 by John-Eilif Eliassen
Replied by John-Eilif Eliassen on topic if category statement
else
{
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.
Last edit: 8 years 3 months ago by John-Eilif Eliassen.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 3 months ago #155796 by Krikor Boghossian
Replied by Krikor Boghossian on topic if category statement
It is possible but this check will be performed for every item in the loop.
Just follow the instructions on my previous post.

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

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

  • John-Eilif Eliassen
  • John-Eilif Eliassen's Avatar Topic Author
  • Offline
  • Senior Member
More
8 years 3 months ago #155807 by John-Eilif Eliassen
Replied by John-Eilif Eliassen on topic if category statement

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 3 months ago #155886 by Krikor Boghossian
Replied by Krikor Boghossian on topic if category statement
In the module's folder and the mod_k2_content.php file you will find the if(count(... check.
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.

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