Page 1 of 1

Need to add Itemid to search results link, to show menu

Posted: 16 Apr 2009, 00:02
by orangesparkz
Hi again,
I think this is a realatively easy question to answer, because Jan figured out the solution to a very similar problem. Posted here: viewtopic.php?f=1&t=3746

What I am trying to do is have the search results link to a page that displays the side menu.
Right now when you click any of the search results it links to a page with the gallery, but the side menu is gone. If I look at the URLs, I am missing the itemid.

Here's an example of a gallery page with the menu when viewing the gallery. This is what I am trying to achieve:
http://www.oliphantstudio.com/index.php ... &Itemid=5
This is the URL of where the search results send you - same gallery, but the sidemenu does not display
http://www.oliphantstudio.com/index.php ... =54:autumn
See how it is missing the &Itemid= ?

The file I have been working with is plugins/search/phocagallery.php
I believe the line that generates the link for the results is

Code: Select all

	if(isset($list2))
		{
			foreach($list2 as $key => $item)
			{   
				$list2[$key]->href = JRoute::_('index.php?option=com_phocagallery&view=category&id='. $item->id );
			}
I tired to apply a modified version of the php code from that previous post, with no luck. Here's one version I tried:

Code: Select all

$list2[$key]->href = JRoute::_('index.php?option=com_phocagallery&view=category&id='.JRequest::getVar('Itemid', 1, 'get', 'int'));
Do you know how I can add the php to generate the Itemid to this path?
Thank you! Thank you! Thank you!

Re: Need to add Itemid to search results link, to show menu

Posted: 16 Apr 2009, 13:54
by Jan
Hi, I think you need to the current Itemid but the Itemid of menu link to this category, and this can be very difficult to find it. But maybe this should find it:

Code: Select all

// -------------------------------------------------------------------- SEF PROBLEM
// Is there an Itemid for category
$items     = $menu->getItems('link', 'index.php?option=com_phocagallery&view=category&id='.$idOfCategory);
$itemscat= $menu->getItems('link', 'index.php?option=com_phocagallery&view=categories');

if(isset($itemscat[0])) {
    $itemid = $itemscat[0]->id;
    $link = link where you will use the $itemid for Itemid parameter
} else if(isset($items[0])) {
    $itemid = $items[0]->id;
    $link = link where you will use the $itemid for Itemid parameter
} else {
    $itemid = 0;
    $link = link where you will use the $itemid for Itemid parameter
}
// --------------------------------------------------------------------------------- 
What this code does? It search for the Itemid, if it not find the itemid of Category link then it will use Itemid of Categories link, if it doesn't find any of them, then it will not use any Itemid

So the links (in case the correct menu link Itemid will be found) should be fixed.

Jan

Re: Need to add Itemid to search results link, to show menu

Posted: 16 Apr 2009, 22:32
by orangesparkz
Thanks for you help. I am not sure I understand, unfortunately. :x
Do I put &Itemid=5 and &Itemid=31 (There's only two itemid's, for each page with side gallery menu) where you wrote [b']link where you will use the $itemid for Itemid parameter'[/b]. Like this? What about the 3rd else { statement?

Code: Select all

// Is there an Itemid for category
$items     = $menu->getItems('link', 'index.php?option=com_phocagallery&view=category&id='.$idOfCategory);
$itemscat= $menu->getItems('link', 'index.php?option=com_phocagallery&view=categories');

if(isset($itemscat[0])) {
    $itemid = $itemscat[0]->id;
    $link = &Itemid=5
} else if(isset($items[0])) {
    $itemid = $items[0]->id;
    $link = &Itemid=31
} else {
    $itemid = 0;
   $link = link where you will use the $itemid for Itemid parameter WHAT GOES HERE?
}
If this is correct, then where would I put the code in the page plugin/search/phocagallery.php?
Above the code that is generating the href? Like this?

Code: Select all

// -------------------------------------------------------------------- SEF PROBLEM
// Is there an Itemid for category
$items     = $menu->getItems('link', 'index.php?option=com_phocagallery&view=category&id='.$idOfCategory);
$itemscat= $menu->getItems('link', 'index.php?option=com_phocagallery&view=categories');

if(isset($itemscat[0])) {
    $itemid = $itemscat[0]->id;
    $link = link where you will use the $itemid for Itemid parameter
} else if(isset($items[0])) {
    $itemid = $items[0]->id;
    $link = link where you will use the $itemid for Itemid parameter
} else {
    $itemid = 0;
    $link = link where you will use the $itemid for Itemid parameter
}
// --------------------------------------------------------------------------------- 
		$db->setQuery( $query, 0, $limit );
		$list2 = $db->loadObjectList();
		$limit -= count($list2);

		if(isset($list2))
		{
			foreach($list2 as $key => $item)
			{   
				$list2[$key]->href = JRoute::_('index.php?option=com_phocagallery&view=category&id='. $item->id );
			}
		}

		$rows[] = $list2;
How does the php code
$list2[$key]->href = JRoute::_('index.php?option=com_phocagallery&view=category&id='. $item->id );
know to add on the itemid into that string?
I think I am confusing myself!
Did I explain this very well? I'm sorry. I am so new to php. I thought this would be a lot easier.
Let me know if I can be more specific on what I am trying to do

Re: Need to add Itemid to search results link, to show menu

Posted: 18 Apr 2009, 23:06
by Jan
Hi, I didn't try it so I don't know but I will take a look at it soon. And as I will look at it, I will change the plugin (in case of success) and will release new version.

Jan

Re: Need to add Itemid to search results link, to show menu

Posted: 27 Apr 2009, 17:49
by orangesparkz
Jan,
I was able to get the itemid to show by adding this code. It is a hack, I'm sure there is a much better way of doing this, but this works for me. Whenever I add a category I will have to go back into the page and add a case for it.
What we did was add a case for every category that told it which itemid that category was. Then added echo "&Itemid=$itemidpage"; at the end of the two lines of code that make the URL for the item.

page= components/com_search/views/search/tmpl/default_results.php

Code: Select all

<table class="contentpaneopen<?php echo $this->params->get( 'pageclass_sfx' ); ?>">
	<tr>
		<td>
		<?php
		foreach( $this->results as $result ) : ?>
			<fieldset>
				<div >
					<span class="small<?php echo $this->params->get( 'pageclass_sfx' ); ?>">
						<?php echo $this->pagination->limitstart + $result->count.'. ';?>
					</span>
					<?php if ( $result->href ) :
					
					
					switch ($result->catslug) {
   
   	case 58:
        $itemidpage=5;
        break;
   
        case 59:
        $itemidpage=5;
        break;
 	 
	 case 60:
        $itemidpage=31;
        break;
	
	case 77:
        $itemidpage=31;
        break;

	if ($result->browsernav == 1 ) : ?>
							<a href="<?php echo JRoute::_($result->href);echo "&Itemid=$itemidpage"; ?>">
						<?php else : ?>
							<a href="<?php echo JRoute::_($result->href); echo "&Itemid=$itemidpage"; ?>">
						<?php endif;
I hope this cheat will help someone else. Everyone's case will be different depending on their category's id number. Same with the $itempage number, will be different for everyone.
-orangesparkz

Re: Need to add Itemid to search results link, to show menu

Posted: 28 Apr 2009, 17:03
by Jan
Hi, see new version of Phoca Gallery Search Plugin:

https://www.phoca.cz/download/category/1 ... ery-plugin

Jan

Re: Need to add Itemid to search results link, to show menu

Posted: 08 May 2013, 12:12
by amoul
God I have been looking for this answer for so long.
Glad someone actually had an east fix for this.

WORKED LIKE A CHARM!!!!

just a suggestion for the future, but it might be a good idea to add a Module Parameter that allows you to add your item id, with a explanation of why this is a benefit.