Community @ The Turning Gate

Support community for TTG plugins and products.

NOTICE

The Turning Gate's Community has moved to a new home, at https://discourse.theturninggate.net.

This forum is now closed, and exists here as a read-only archive.

  • New user registrations are disabled.
  • Users cannot create new topics.
  • Users cannot reply to existing topics.

You are not logged in.

#1 2020-01-05 13:48:54

chumby
Member
Registered: 2014-10-23
Posts: 188

Modified Search

Hi all,

I am trying to modify my search similar to the below site built in CE4.

https://kylelucy.com/search/

The code that was used in the PHPlugins file is below.  Anyone know what I need to do to get this working in Baklight 2? The orignal thread is at:

http://community.theturninggate.net/vie … hp?id=4747

function ttg_block_bottom( $style, $path ) {
    if (G_PATH == 'SEARCH') {    
        echo '
        <script>
        (function(){
            if(document.getElementById("content")!=undefined){            
                if(document.getElementById("content").innerHTML.indexOf("criteria")>-1){
                    document.getElementById("content").innerHTML="<p><cite>No photos matched your search criteria</cite></p>";
                } else {
                    document.getElementById("content").style.display="none";
                }
            }
        })();
        </script>
        ';
    }
} // END

Offline

#2 2020-01-05 14:47:39

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Modified Search

First, you’ll need to update the phplugins code. See the docs:
http://backlight.theturninggate.net/doc … _phplugins
And Daniel’s post in the forum:
http://community.theturninggate.net/vie … hp?id=8966

To replace the G_PATH part to identify the search page, see this post by Daniel
https://lab.danielleu.com/blog/adding-b … ery-pages/

Specifically, this bit:

 if (strtolower($this->slug) == 'search') {

Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#3 2020-01-05 17:53:22

chumby
Member
Registered: 2014-10-23
Posts: 188

Re: Modified Search

Thanks for the Help again, Rod.

So I started with a fresh Backlight 2 install and followed the first link to get a my-phplugins.php working. 

I have read theough the second and third links from Dan, and have entered the code below in my-phplugins page - but its not working (ie a search just presents the normal not found output).  Have I missed a step in the code?  My site is at - www.tasmanianphotos.com

function ttg_block_bottom( $style, $path ) {
    if (strtolower($this->slug) == 'search') { 
        echo '
        <script>
        (function(){
            if(document.getElementById("content")!=undefined){            
                if(document.getElementById("content").innerHTML.indexOf("criteria")>-1){
                    document.getElementById("content").innerHTML="<p><cite>No photos matched your search criteria</cite></p>";
                } else {
                    document.getElementById("content").style.display="none";
                }
            }
        })();
        </script>
        ';
    }
} // END

Offline

#4 2020-01-05 23:37:29

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Modified Search

if you simply want to change the No Photos Message in Search, you can do that in the Backlight Language settings.
Settings > Languages > Manage Language
Scroll down to the Publisher area and change the wording.

But as to your code:

Start with the latest phplugins sample file (phplugins-pangolin-sample.php) as outlined in the Daniel’s post forum (link above)
ttg_block_bottom is not a hook in Backlight, see the available hooks in the sample file
Do not include the arguments ($style, $path). See Daniel’s forum post.

For the JavaScript, you probably need a different element ID (Backlight’s structure is different than CE4). Look through the search page’s source code to find it

And the if statement should come before the phplugins function. Something like this:

if (strtolower($this->slug) == 'search') {
function ttg_function() {
echo'....
';
}
}

Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#5 2020-01-06 05:00:26

Ben
Moderator
From: Melbourne, Australia
Registered: 2012-09-29
Posts: 4,399

Re: Modified Search

Another option would be to explain to us what you’re trying to achieve and we may be able to add the function natively. Is this an attempt to hide the list of matching albums?

Offline

#6 2020-01-06 06:05:03

chumby
Member
Registered: 2014-10-23
Posts: 188

Re: Modified Search

Thanks Rod and Ben,

Yes I am just using one album set/album - trying to build up a stock photo library much like Nico's at; https://phototheque.nicolaslogerot.com/

For the search I would like a user to just be presented with a message (number) on how many photos were found as well as actully displaying the thumnail photos found.  No mention of albums etc. is wanted. The ability to have some feedback text in on the search result page would be good also if nothing found.  ie "No images were found, try using a different search term".

Does that all make sense?  When I change the messages for albums in Settings > Languages > Manage Language - the message just comes back in on same, so that method is not working for me.

Thank you very much.

Cheers
Chumby

Offline

#7 2020-01-06 06:36:11

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Modified Search

When changing text in Languages, you sometimes need to close the browser and relaunch before you see the change. Or look in a different browser


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#8 2020-01-06 10:54:20

chumby
Member
Registered: 2014-10-23
Posts: 188

Re: Modified Search

Hi Rod,

No good - tried another browswer, but the album entries that I had deleted were back.

Will have a look at the tips/code you mention.  Hopefully I can work this out.

Appreciate the help.
Cheers
Chumby

Last edited by chumby (2020-01-09 17:20:58)

Offline

#9 2020-01-09 19:14:11

chumby
Member
Registered: 2014-10-23
Posts: 188

Re: Modified Search

Hi,

After reading through the posts and help, ahave come up with the code below - unfortunatley still not working.  The if wasn't working outside the function, Rod.

Any ideas on what I am still doing wrong on http://www.tasmanianphotos.com to simply get a "no photos found" type message to appear, without any reference to albums.

Appreciate the help as always.

Cheers
Chumby


function main_top() {  
       
    if (strtolower($this->slug) == 'search') 
        echo '
        
        <script>
        (function(){
            if(document.getElementById("search")!=undefined){            
                if(document.getElementById("search").innerHTML.indexOf("criteria")>-1){
                    document.getElementById("search").innerHTML="<p><cite>No photos matched your search criteria</cite></p>";
                } else {
                    document.getElementById("search").style.display="none";
                }
        })();
        </script>
        ';
    } // END

Offline

#10 2020-01-10 00:14:09

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Modified Search

looks like there are several errors in the javascript (everything between the <script>...</script> tags) like mismatched brackets and unexpected parentheses
Try pasting it into a validator
http://beautifytools.com/javascript-validator.php
https://codebeautify.org/jsvalidate


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#11 2020-01-10 08:25:46

chumby
Member
Registered: 2014-10-23
Posts: 188

Re: Modified Search

OK, thanks for letting me know of that tool, Rod.  I will paste the javascript code in there and see if I can make a better go of it.

Cheers,
Chumby

Offline

#12 2020-01-10 15:38:43

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Modified Search

Just wondering about something.
This bit:

   if(document.getElementById("search")

Is there an element on the search page that has the ID of “search”?
For that matter, does the search page have any of the other html structure the code seems to be looking for, like “criteria”

Again, if you need a different message to be displayed if no photos are found, then give changing that text in Language another try.
You’ll probably want to disable phplugins to avoid conflict.
And be sure to clear browser and template cache as well as closing and relaunching the browser.


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#13 2020-01-14 18:05:54

chumby
Member
Registered: 2014-10-23
Posts: 188

Re: Modified Search

Hi Rod,

As far as I can tell there is an ID Search element.  I found the below before the form when I inspect the page

<div id="search" class="fancybox-content" style="display: inline-block;">

The form code is at:

<div id="search" class="fancybox-content" style="display: inline-block;">
									<form action="/backlight/search/" method="GET">
								<input type="text" id="q" name="q" value="" placeholder="Enter search, then press Return...">
				<button class="fa_pseudo" type="submit"><span>Search</span></button>
			</form>    
			<button type="button" data-fancybox-close="" class="fancybox-button fancybox-close-small" title="Close"><svg xmlns="http://www.w3.org/2000/svg" version="1" viewBox="0 0 24 24"><path d="M13 12l5-5-1-1-5 5-5-5-1 1 5 5-5 5 1 1 5-5 5 5 1-1z"></path></svg></button></div>

So used "search" as  the reference.  Do no think what I am doing is right though as album messages still appear..

I have changed the messages in languages to blank for albums, but no matter what Ido - refresh or clear,  a message about albums always appears..  Have tried other browsers as well with still no luck.

Appreciate your help as always.

Cheers
Chumby

Offline

#14 2020-01-14 22:26:12

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Modified Search

In your original code, this:

if (G_PATH == 'SEARCH')

Is, I believe, looking for a page with a slug of “search”

The id="search" element you found actually looks to be for the search icon/button in the upper right of the page, in the top-pallet.

Try looking at the page code for an element that text can go into. I don’t know if there are any IDs in the content area of the page or not, since you’re using getElementByID. Look around the existing message.

You might need to use getElementsByClassName instead (I didn’t actually know that one, had to Google it) and be very specific with the css selector you use.

I still think that changing the Language setting is the way to go. I’ll see if I can duplicate the problem so that Ben has something to look at.


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#15 2020-01-15 02:19:37

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Modified Search

I just tried changing the in Settings > Languages > Manage Language > Publisher > No Photos Message and it worked fine for me.

This should work for you too.

Maybe a stupid question, but are you saving the settings after you make the change?

Is Backlight up to date?


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#16 2020-01-19 18:18:37

chumby
Member
Registered: 2014-10-23
Posts: 188

Re: Modified Search

Hi Rod,

Yes I change every message to do with albums to blank, go to the botom of the screen, hit save entires.  The I go back into Manage Language, scroll down to Publisher and the original album messages are still there, ie - Pulisher Search Albums Title = Albums, and No Albums Message = No albums matched your search criteria.

Is this what happens for you?

Thanks
Chumby.

Offline

#17 2020-01-20 00:01:24

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Modified Search

No.
After I make the change in languages and save it, I can go back to languages and the change is still there.

Something isn’t right and I think Ben will need to look into it.

Is your installation of Backlight up to date?


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#18 2020-01-20 06:17:08

chumby
Member
Registered: 2014-10-23
Posts: 188

Re: Modified Search

Hi Rod, Yes - all up to date.

If I change the text, the new text will save all ok.  It's just if I leave the input box blank (ie so there is no reference to albums at all), the message will default back to the text that was in there before my save. 

Is that what you are seeing?

Cheers
Chumby

Offline

#19 2020-01-20 06:37:54

Ben
Moderator
From: Melbourne, Australia
Registered: 2012-09-29
Posts: 4,399

Re: Modified Search

The localisation mechanism isn't designed to have empty fields. 
I have added an admin setting to set the search scope and presentation to Albums, Photos or Both.  This will be in the next major release of Backlight, but not likely within Backlight 2.

Offline

#20 2020-01-21 08:15:41

chumby
Member
Registered: 2014-10-23
Posts: 188

Re: Modified Search

Ok, thanks Ben.  Looking forward to the update / new release.

Any idea how to action a search feature now (as per Nico's site  https://phototheque.nicolaslogerot.com ) perhaps through PHPluins?

I am struggling with coming up with anything that works.

Cheers
Chumby

Offline

#21 2020-01-21 11:15:32

Daniel Leu
Moderator
Registered: 2012-10-11
Posts: 1,624
Website

Re: Modified Search

chumby wrote:

Any idea how to action a search feature now (as per Nico's site  https://phototheque.nicolaslogerot.com ) perhaps through PHPluins?

You can add a search form to any page you want. Just copy the form code from the search page.


Daniel Leu | Photography   
DanielLeu.com
My digital playground (eg, Backlight tips&tricks): lab.DanielLeu.com

Offline

#22 2020-01-21 14:32:11

chumby
Member
Registered: 2014-10-23
Posts: 188

Re: Modified Search

Hi Daniel,

Thanks for helping out.

It is the results page that is the issue - I would like to see a results page with no mention of galleries.... just simply a message "your search returned 10 photos..." or "your search returned 0 photos" - as per Nico's site.

Any ideas on this?

Cheers,
Martin

Offline

#23 2020-01-21 17:31:31

Daniel Leu
Moderator
Registered: 2012-10-11
Posts: 1,624
Website

Re: Modified Search


Daniel Leu | Photography   
DanielLeu.com
My digital playground (eg, Backlight tips&tricks): lab.DanielLeu.com

Offline

#24 2020-01-21 19:07:46

chumby
Member
Registered: 2014-10-23
Posts: 188

Re: Modified Search

Brilllant blog post Daniel!

Thank you for putting it together for us. I am sure that will help greatly.

Cheers
Martin

Offline

#25 2020-01-22 00:19:47

Daniel Leu
Moderator
Registered: 2012-10-11
Posts: 1,624
Website

Re: Modified Search

smile


Daniel Leu | Photography   
DanielLeu.com
My digital playground (eg, Backlight tips&tricks): lab.DanielLeu.com

Offline

Board footer

Powered by FluxBB