Sign Up for OSTraining

Welcome, Guest
Username: Password: Remember me

TOPIC: page format for search results generated from a search box

page format for search results generated from a search box 11 months 1 week ago #50886

  • careytech
  • careytech's Avatar
  • OFFLINE
  • OSTycoon
  • Posts: 236
  • Karma: 0
I'm using the search module in a 2.5 Joomla project. When I enter a search word and hit Enter, the search results use the format of the page I'm currently on. In some cases I have module items above the component, and from those pages the search results (which is the main thing the user wants to see) fall quite a ways down the page.

I would like to direct the search results to always display according to the format set for a particular menu item. For instance, I created a hidden menu with a menu item of type "search results." It would be nice if I could get all searches to display their results on this page (or using the page format for this menu item).

Is there a way to direct the search results to use a particular page format?
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50888

  • tessa
  • tessa's Avatar
  • OFFLINE
  • Moderator
  • Posts: 4032
  • Thank you received: 138
  • Karma: 10
Hi Carey,

Is your site live? What is the link? :)
Warm Regards,

Tessa Mero



Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50889

  • careytech
  • careytech's Avatar
  • OFFLINE
  • OSTycoon
  • Posts: 236
  • Karma: 0
It is "live" as it is being developed here...

kohn.careytechstudios.com/

The home page is a great example as to how the search results fall below "the fold."
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50925

  • Nick
  • Nick's Avatar
  • NOW ONLINE
  • Administrator
  • Posts: 17192
  • Thank you received: 450
  • Karma: 64
Hi Randy,

It's not possible with the Joomla core search module.

I know you're interested in improving Joomla and are able to code, it would be a great addition to the search module if you coded an option where the users could input a URL/Menu item where the module would redirect to and display the results on the page. Would this be something you're interested in? If so, I'd be willing to help with it.

Kind regards,
Nick
Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50927

  • careytech
  • careytech's Avatar
  • OFFLINE
  • OSTycoon
  • Posts: 236
  • Karma: 0
Thanks Nick,

I'm willing to dig a bit deeper to see if I see a solution. And if I do see a solution, then I'd be happy to work with you to build/test that solution and submit it for inclusion.

I was going to dig deeper into the code, but I thought I'd ask here first, just-in-case there was a configuration detail I was missing.
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50929

  • Nick
  • Nick's Avatar
  • NOW ONLINE
  • Administrator
  • Posts: 17192
  • Thank you received: 450
  • Karma: 64
Do a test in your search module on a couple pages of your site.

For example, typing "test" in the search module on the home page and clicking enter, redirects to the following URL:
kohn.careytechstudios.com/component/sear...hrase=all&Itemid=101

On the About Us page it redirects to:
kohn.careytechstudios.com/component/sear...hrase=all&Itemid=124

Do you notice the only difference being the Itemid # (e.g. Itemid=124)? That item id # corresponds to the menu item id that the module was on when used.


Randy wrote:
I would like to direct the search results to always display according to the format set for a particular menu item. For instance, I created a hidden menu with a menu item of type "search results."
Find the ID of the menu item that you'd like to use then place it after:
kohn.careytechstudios.com/component/sear...chphrase=all&Itemid=

That should produce the result you're looking for.



So basically, to get the goal you're ultimately desiring:Randy wrote:
It would be nice if I could get all searches to display their results on this page (or using the page format for this menu item).
You would have to add an option to the module parameters for the menu item id that you'd like to use, then in the module code you'd have to check if the option is set, if so, use it rather than the menu item id of current menu item.

Does this help? Let me know if I can be of more help.

Kind regards,
Nick
Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50931

  • careytech
  • careytech's Avatar
  • OFFLINE
  • OSTycoon
  • Posts: 236
  • Karma: 0
Thanks. I did notice the itemId parameter but I did not make the connection that it was a menu item id.

I'll give it a look and get back to you.
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50932

  • Nick
  • Nick's Avatar
  • NOW ONLINE
  • Administrator
  • Posts: 17192
  • Thank you received: 450
  • Karma: 64
You're welcome, Randy! Just let me know if you need any help along the way. I have a relatively free weekend :)

Kind regards,
Nick
Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50933

  • careytech
  • careytech's Avatar
  • OFFLINE
  • OSTycoon
  • Posts: 236
  • Karma: 0
Got it.
  • I added a parameter/field within the config.xml file. It takes the id number for the target menu item.
  • Then I added the logic within the component's base controller.php file: get the parameter value and if it exists, post that id, else use the logic already there.

I realize that I need to add some defensive programming such as using the parameter value only if it is an int - and reusing some logic already there to make sure the menu item is set. But with these two changes I am able to redirect the search results to the menu item page that I set in the parameters.

So what next? How to prepare the solution and propose/submit it for the core?
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50936

  • Nick
  • Nick's Avatar
  • NOW ONLINE
  • Administrator
  • Posts: 17192
  • Thank you received: 450
  • Karma: 64
Excellent! Great job! :)

Just submit a patch to joomlacode.org/gf/project/joomla/tracker...owse&tracker_id=8549

Are you familiar with how to create a patch?

Kind regards,
Nick
Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50938

  • careytech
  • careytech's Avatar
  • OFFLINE
  • OSTycoon
  • Posts: 236
  • Karma: 0
No. Are there some instructions somewhere?
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50939

  • Nick
  • Nick's Avatar
  • NOW ONLINE
  • Administrator
  • Posts: 17192
  • Thank you received: 450
  • Karma: 64
What do you currently use for localhost and for a text editor / IDE? I can point you in the right direction depending on what you use.

Kind regards,
Nick
Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50941

  • careytech
  • careytech's Avatar
  • OFFLINE
  • OSTycoon
  • Posts: 236
  • Karma: 0
My changes/testing are on a server, using a Joomla installation in one of my subdomains used for development and/or testing. My local machine is running XP.

Right now I'm rather vanilla with my coding process - using an FTP app and EditPlus to view/edit/save files.

I used to develop in C++ and Java, and for Java I used IntelliJ - and I understand that JetBrains (makers of IntelliJ) offers an IDE for PHP. I thought of getting back to an IDE, but I'm keeping busy with client work and have yet to dedicate the time to jump into that.
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50942

  • Nick
  • Nick's Avatar
  • NOW ONLINE
  • Administrator
  • Posts: 17192
  • Thank you received: 450
  • Karma: 64
Don't worry, I like simple too :)

Give Tortoise a try:
docs.joomla.org/Tortoise_SVN

Let me know if you have any questions along the way.

Kind regards,
Nick
Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50943

  • careytech
  • careytech's Avatar
  • OFFLINE
  • OSTycoon
  • Posts: 236
  • Karma: 0
Once again, thanks. I'll probably get to this over the weekend. If I have more questions about the process, I'll ask.

BTW, if I submit my suggested change and it is approved, is it likely to be rolled out in one of the next 2.5.x versions... or would an addition like this get deferred to 3.0.x?

If it is deferred beyond 2.5, I probably would try to wrap up this logic in a plugin to apply to my current 2.5 installations - and to share with others, of course.
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50944

  • Nick
  • Nick's Avatar
  • NOW ONLINE
  • Administrator
  • Posts: 17192
  • Thank you received: 450
  • Karma: 64
You're welcome!

I'm not sure to be honest. It could go either way. They just split the two and made the master branch as Joomla 3.0, so it would likely be added to Joomla 3.0, however I'm not 100% sure. It might still get in for Joomla 2.5.7 since it's a minor change.

For something so small, I would suggest adding to the core as a feature rather than creating a plugin. That's just a suggestion though.

Kind regards,
Nick
Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50947

  • careytech
  • careytech's Avatar
  • OFFLINE
  • OSTycoon
  • Posts: 236
  • Karma: 0
I agree that the ideal solution is to have a change in the core. But if it doesn't get into the core, then a plugin is better so that changes don't get overwritten with a Joomla upgrade.

The logic of such a plugin should be rather simple... If the component is com_search, and the plugin's parameter is set to a menu item, then change the value of the Itemid to that set by the plugin.

I'm reading the book Joomla Programming and that has helped a lot to explain how the page is built - and that enlightens me more about how to leverage plugins.

Will I see you at Joomla Day Chicago?
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50949

  • Nick
  • Nick's Avatar
  • NOW ONLINE
  • Administrator
  • Posts: 17192
  • Thank you received: 450
  • Karma: 64
Yes, that's true. If you need it right away, then a plugin is best. You're right.

Nice! I've heard that the book is a good read. I'll hopefully have an opportunity to read it some time this summer.

I likely won't be at Joomla Day Chicago, however our whole (or at least a big part of our) team might be at the upcoming Joomla World Conference. Any plans of possibly attending JWC? :)

Kind regards,
Nick
Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50954

  • careytech
  • careytech's Avatar
  • OFFLINE
  • OSTycoon
  • Posts: 236
  • Karma: 0
Yes, I'll be at JWC. Glad to know that I'll probably get to meet several of you in person.
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50956

  • Nick
  • Nick's Avatar
  • NOW ONLINE
  • Administrator
  • Posts: 17192
  • Thank you received: 450
  • Karma: 64
Great! Hopefully we'll meet there! :)

Kind regards,
Nick
Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50983

  • Nick
  • Nick's Avatar
  • NOW ONLINE
  • Administrator
  • Posts: 17192
  • Thank you received: 450
  • Karma: 64
Hi Randy,

Go to the current search module and look for "Set ItemID" :)

Someone just point this out to me that Joomla 2.5 already has the feature that we're looking for. I don't know how we missed it :P

Kind regards,
Nick
Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50984

  • careytech
  • careytech's Avatar
  • OFFLINE
  • OSTycoon
  • Posts: 236
  • Karma: 0
Thanks for letting me know before I posted a patch :-)

I think I saw that field before, but the term "Itemid" and the help text didn't clarify it well for me. Now if the field were labeled "menuid," I would have paid more attention. And by implementing my own solution, I found that there is a Joomla parameter field type that produces a selection list of all published menu items - nicer and less error prone than a text field.

I don't regret the exercise of coding a solution. I always get some gain and better understanding when I dig into the code.

Thanks again for pointing our this discovery.
Please become a member of OSTraining to reply to this post.

page format for search results generated from a search box 11 months 1 week ago #50990

  • Nick
  • Nick's Avatar
  • NOW ONLINE
  • Administrator
  • Posts: 17192
  • Thank you received: 450
  • Karma: 64
You're welcome, Randy! Sorry for pointing you in the wrong direction to begin with :)

At least you now have an opportunity to compare your code to what's there and see how someone else did it.

Kind regards,
Nick
Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

Sign Up for OSTraining

Copyright 2013 Open Source Training, LLC. All rights reserved.