Keyword

Module K2 Content filter items with specific extrafield

  • Fábio Jordan
  • Fábio Jordan's Avatar Topic Author
  • Offline
  • Senior Member
  • Nothing like a good coffee to make a better web
More
7 years 8 months ago #157670 by Fábio Jordan
Hi there.

I'm trying to filter some specific items in Module K2 Content that have a value in an extrafield. So, I'm using this code in a template:
<ul>
<?php foreach ($items as $key=>$item):	?>
<?php if($item->extraFields->NAMEOFEXTRAFIELD->value): ?>
<?php if(count($item)): ?>
<a class="NameofClass" href="<?php echo $item->link; ?>">
<li> 
<div><?php echo $item->title; ?></div>
</li>
</a>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>

It’s working this way, but the problem is that it’s showing only one item (instead of five, as I inserted in the parameters of the module), because for some reason it’s counting first the five items and than showing only the ones with the specific extrafield (in this case, there’s only one in the five recent items with that extrafield).

Any help to first check the extrafield and then count the items?

Thanks in advance!

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 8 months ago #157677 by Krikor Boghossian
Replied by Krikor Boghossian on topic Module K2 Content filter items with specific extrafield
You need something like this:
Read the comments to see how each block functions :)
<ul>
	<?php if(count($items)): ?>
	<?php foreach ($items as $key=>$item):	?>
	<li>
		<?php if($item->extraFields->NAMEOFEXTRAFIELD->value): ?>
		<!-- EXTRAFIELD IS PRESENT SHOWS THE TITLE WITH A LINK -->
		<a class="NameofClass" href="<?php echo $item->link; ?>">
			<div><?php echo $item->title; ?></div>
		</a>
		<?php else: ?>
		<!-- NO EXTRAFIELD SHOWS THE TITLE -->
		<div><?php echo $item->title; ?></div>
		<?php endif;?>
	</li>
	<?php endforeach; ?>
	<?php endif; ?>
</ul>

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

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

  • Fábio Jordan
  • Fábio Jordan's Avatar Topic Author
  • Offline
  • Senior Member
  • Nothing like a good coffee to make a better web
More
7 years 8 months ago #157689 by Fábio Jordan
Hi, Krikor. Thanks for the reply, but I think this won't work as I need.

The way you told me, the code still shows items without the specific extrafield, but it just wont insert a link. What I need is a solution to show only items with the extrafield and hide any other items (but still using the count from the module).

The thing is, I need a parameter to check if the item has the specific extrafield and, if so, than it will show all the details.

I tried to use a foreach to get that, but with no sucess. Is there a way to use two foreaches?

I mean, in one, I could use the parameter ($items as $key=>$item) and in other I could check the extrafield...

Any help is appreciated.

Thanks!

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 8 months ago #157725 by Krikor Boghossian
Replied by Krikor Boghossian on topic Module K2 Content filter items with specific extrafield
By default the limit from the module's settings will be shown.
This means the module will always pull x items, regardless of their extrafields.

In order to apply certain filters and pull only x items which have a specific extrafield, you need a 3rd part extension.

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

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

  • Fábio Jordan
  • Fábio Jordan's Avatar Topic Author
  • Offline
  • Senior Member
  • Nothing like a good coffee to make a better web
More
7 years 8 months ago #157735 by Fábio Jordan
Hi, Krikor.

Thanks for the reply.

I'm gonna try to figure something else for that.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 8 months ago #157737 by Krikor Boghossian
Replied by Krikor Boghossian on topic Module K2 Content filter items with specific extrafield
You 're 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