Vous n'êtes pas identifié(e).
13 février 2024 Sortie de Dotclear 2.29
Pages : 1
Hello fellow DotClear users!
I am a recent user of DotClear, having found it after searching for alternatives to the abysmal Wordpress, and am thoroughly loving it so far.
It's clean, fast and - most importantly for me - doesn't try to 'help' and mangle my HTML/PHP code.
Because I'm still discovering DotClear this is possibly a bit of a newcomer question, but I've searched through this forum and the knowledgebase and can't seem to find the answer anywhere so would appreciate the benefit of other users' experience.
The problem is the in-built Search function used by the visitors to a DotClear site. This is the widget that sits in the sidebar of most themes and allows users to make word searches across the DotClear site.
This widget works just fine and there is no issue with it, but in testing my site the search is returning results for all the Entries (which I want) and all the Pages (which I don't want).
I've been through all the settings I can find and there doesn't seem to be a way to control it.
I've also looked through the code since I'm assuming at some point that widget must perform an SQL lookup on the attached database. If I can find that lookup I can easily reprogram it with a WHERE clause to ignore the Pages but I've not been able to locate that anywhere in the code so far.
So, simple question: Is there a way to filter what this Search widget hunts for?
Thank you in advance for any help you can give!
Hors ligne
Hi,
In your theme, create (if it doesn't exist, otherwise add the following code but the first two lines) a _public.php file with this content :
<?php
if (!defined('DC_RC_PATH')) { return; }
$core->addBehavior('coreBlogBeforeGetPosts',array('myBehaviors','coreBlogBeforeGetPosts'));
class myBehaviors
{
public static function coreBlogBeforeGetPosts($params)
{
global $core;
if ($core->url->type == 'search') {
// Search in posts only (excluding pages)
$params['post_type'] = array('post');
}
}
}
It should work
Dotclear addicted since 2004
Hors ligne
@Franck
Your PHP code worked perfectly and my Search widget will now only get results from the Post type.
Thank you so much!
Hors ligne
Hors ligne
Many thanks for that code, Franck. Just saved it in my archive.
BTW, searching through pages came with 2.8. It didn't happen with 2.7 as far as I remember. Please don't do the same "improvement" as Wordpress back then.
One of reasons why I changed from Wordpress to Dotclear back then was that with Wordpress 2.6, suddenly the search listed content in directories. For example, if I searched for "galleries" in my blog (which were 3 entries), it listed each single picture in my folder "galleries". I called it a bug, they called it feature. Search became completely useless over night.
I ♥ Dotclear.
Hors ligne
Pages : 1
Vous n'êtes pas identifié(e).