Keyword

If K2 Content Module In Item View, Don't Show Current Item

More
6 years 11 months ago - 6 years 11 months ago #165539 by Lisa
Hi everyone,

I want to show the mod_k2_content module in Item View (to provide interesting other content to readers). You can imagine that it would be of little value to provide another preview/link to the current item. However, there's no filtering option for this built-in to K2.

I tried some stuff but I just don't get it to work. Here's what I tried - I'm in modules/mod_k2_content/helper.php (since this seems to be where the content query is filtered) and added the following between the filtering and the ordering (around line 200 in my version of K2):
			// hide items identical to current if in item view
			if($option=='com_k2' && $view=='item'){
				$query .= " AND i.id != ".$item->id;
			}

Anyone know why this doesn't work and if this is even the right approach? Or where else in the module code I could include a statement to compare the item IDs?

Thank you!!

PS.: Here's how a similar module does it for regular articles; not sure whether that helps:
					// check if the link is the same of the article activaly shown 
					$css_active = '';
					$option = $app->input->get('option');
					$view = $app->input->get('view');		
					if ($option === 'com_content' && $view === 'article') {
						$current_id = $app->input->getInt('id');
						if ($current_id == $item->id) {
							$css_active = ' active';
						}
					}
Last edit: 6 years 11 months ago by Lisa.

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

More
6 years 11 months ago #165540 by Lisa
Solved it! Boom!

Here you go:
...	$query .= " AND comments.published = 1";

	// hide items identical to current if in item view	
	$v_option = $application->input->get('option');
	$o_view = $application->input->get('view');		
	if ($v_option === 'com_k2' && $o_view === 'item') {
		$view_itemid = $application->input->getInt('id');
		$query .= " AND i.id != ".$view_itemid;
	}

	if (K2_JVERSION != '15')
	{ ...

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
6 years 11 months ago #165551 by Krikor Boghossian
Replied by Krikor Boghossian on topic If K2 Content Module In Item View, Don't Show Current Item
Nice one Lisa, Kudos :)

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