The Built-In Code
I have created a search page for this site using the code that is part of the WonderCMS v3.6.0 package. It is currently hidden and only accessible if you enter the full URL of the page in your browser's address bar. The reasons for keeping it hidden are explained below. However, I believe that the feature could suit a lot of other WonderCMS sites so I thought it worth recording how I have implemented it.
Problems
The search page, implemented as described on
this page, showing some results.
There are some severe limitations to the usefulness of the search code found in WonderCMS v3.6.0. Most importantly, it only searches the top level of the menu structure. Sub-pages are invisible to it and the majority of content on this site is located on sub-pages.
In addition it will only work well if your site has been developed with a recent version of WonderCMS and not upgraded over a period of time through several earlier versions of the package. That's because the way sub-pages are stored has changed from version to version and because page content data is not always removed from the database when a page is marked as deleted on the Menu page of the Settings Modal. As a result if your site has had a long life with several updates of the WonderCMS platform then the site's database can have a lot of redundant and duplicate page data in it so, for example, pages supposedly deleted can appear in the search results.
It's also worth mentioning that there is no ordering of the results by relevance or date. That's because the search code does a simple field by field search of the site's database for the combination of characters you enter and the results appear in the order found in the database file. Depending on when a page was created, the retention of page data after deletion and how a page might have been moved through the menu structure, the search results order can appear somewhat random.
My Implementation
With the help of ChatGPT, I have managed to create a search page that looks reasonably good and may work well on the site's of others. However, I will wait for code that will search sub-pages and until I have a database that is clear of redundant content before I plan to make it available to visitors.
The first thing I did was to add three lines of code to my theme.php file. Somewhere in your theme you will have code along these lines:
Your version may have additional lines in it. Mine now has the three additional lines at rows 2-4 below:
The extra lines add the search box to any page named "Search" on the menu. It places it above the standard page content box.
I also added the following code to my theme's stylesheet:
This places the search box with the prefix "Enter your" centred on the page. The search box already has the word "Search" in it as standard.
Having uploaded the revised theme.php and style.css files I went to my site, logged in and added a menu item named "Search". I marked mine as "Invisible" as I didn't want it to be found while I experimented with it, but I did then visit the page. Having no content that I wanted to appear under the search box or the results when they appeared, I added the following code to the page content box:
This effectively makes it disappear, leaving only the search box neatly centred on the page.
Now you are ready to test the the search. Once you have entered a second character in the search box the results appear below it instantly, reducing in number the more characters you type.
Each result appears as two lines, a page title as a link and, below it, a 100 character extract from the page, with the search term beginning 20 characters along the line. The results are strict character counts so you often get part words at the beginning and end of the page extract.