1 (edited by legmet 2016-10-11 14:35:56)

Topic: Search blog's post content

use this snippet if you want search blog's post by content or title


results for ' .$_POST['name']. ' :'; echo '
    '; foreach($pages as $page) { $content = strtolower(Pages::content($page['slug'])); $title = strtolower($page['title']); if (strpos($title , $name) !== false OR strpos($content , $name) !== false) { echo '
  • '; echo '' .$page['title']. ''; echo '
  • '; $counter++; } } echo '
'; if ($counter === 0) { echo '

no matches found

'; } else { echo '

found ' .$counter. '

'; } } ?>

Re: Search blog's post content

Are you sure this is working?

It does not seem to work on my blog (http://barichello.coffee/blog).

Try "attention", for example. It is in the content on the body of the first post but the script returns 0 matches.

barichello's Website

3 2016-10-13 12:22:07

Re: Search blog's post content

you are right it does not return searching phrase

this line: $content = strtolower(Pages::content($page['slug'])); should return page content

i will think about it

4 2016-10-13 12:24:13

Re: Search blog's post content

barichello wrote:

Are you sure this is working?

It does not seem to work on my blog (http://barichello.coffee/blog).

Try "attention", for example. It is in the content on the body of the first post but the script returns 0 matches.


are you sure you have copied above code ?
it works for me

5 2016-10-13 12:27:41

Re: Search blog's post content

try change:

$content = strtolower(Pages::content($page['slug']));

to :

$content = strtolower(Page::content($page['slug']));


Pages to Page

6 2016-10-18 17:12:57

Re: Search blog's post content

Thank you! smile

barichello's Website

7

Re: Search blog's post content

it works I guess wink