Keyword

Need help for conditionnal tag display

  • STEPHAN HERBY
  • STEPHAN HERBY's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 6 months ago #166875 by STEPHAN HERBY
Need help for conditionnal tag display was created by STEPHAN HERBY
Hi all K2 aficionados :)
I have done an override for K2 item display...
In this override, I want to display Tag with a title ("Title") only if there's some tags to display.
But there's also, 4 tags i never want to be display.
So I wrote :
		<?php if($this->item->params->get('itemTags') && count($this->item->tags)): ?>
		<dt class="uk-text-small">Title</dt>
		<dd>
			<ul class="uk-list">
				<?php foreach ($this->item->tags as $tag): ?>
				<!-- NE pas affiché les tags si gestion Fil actus -->
				<?php if (($tag->id == 539) || ($tag->id == 540) || ($tag->id == 541) || ($tag->id == 542))
				{
				
				} else { ?>
				<li><a href="<?php echo $tag->link; ?>"><?php echo $tag->name; ?></a></li>
				<?php }
				endforeach; ?>
			</ul>
		</dd>
		<?php endif; ?>
It works as i want and that's great.

But actually, when there's only one of this 4 tags on the item, the "Title" is display with no result.
This is normal as this is what is written in php above.
I'm looking for the great conditionnal php which would :
  • Print the Title and tags if there is at least one tag with ID different of 539, 540, 541, 542)/li]
  • Print No Title AND no tag if there's only one of this 4 tags called
Thanks for any advice or code example... If you have understood my purpose ;)

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
6 years 6 months ago #166884 by Krikor Boghossian
Replied by Krikor Boghossian on topic Need help for conditionnal tag display
Hello Stephan,

You can have a separate count (in a separate loop) which acts as a flag.
In this loop you can check the value of that variable (count) to see if it is larger than one.

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

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

  • STEPHAN HERBY
  • STEPHAN HERBY's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 6 months ago #166893 by STEPHAN HERBY
Replied by STEPHAN HERBY on topic Need help for conditionnal tag display
Hi Krikor, thank you very much for answering this topic :-)
Actually I was more thinking at something like :
<?php if($this->item->params->get('itemTags') && count($this->item->tags [ ONLY $this->item->tags != 539 OR 540 OR 541 OR 542] ) ): ?>
Of course, what is between [ONLY ...] is not PHP!
It is MY language ... mean this is what I don't know how to write due to my so bad knowledge...

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


Powered by Kunena Forum