Viewing 15 replies - 1 through 15 (of 20 total)
  • That is really cool. I am adding it now.

    Here is the answer if your blog is not in the root directory.

    <?
    $URI_prefix = "/blog/";
    $search_preterm = str_replace($URI_prefix,"",$_SERVER['REQUEST_URI']);
    $search_term = substr($_SERVER['REQUEST_URI'],1);
    $search_term = stripslashes($search_preterm);
    $search_term = urldecode(stripslashes($search_term));
    $search_url = 'https://davidblog.ws/blog/index.php?s=';
    $full_search_url = $search_url . $search_term;
    $full_search_url = preg_replace('/ /', '%20', $full_search_url);
    $full_page = implode("", file($full_search_url));
    print_r($full_page); die();
    ?>

    Change /blog/ to whatever subdirectory your blog is in.
    Also.. You may want your .htacess in your blog dir to call a slightly different 404.php file (I call 404blog.php) that way the search text is formatted correctly regardless of whether the original 404 occurs in your root or blog directory.
    Carl..
    Your problem is because the code on original page is styled (in some way) on the authors page. Therefore you need to strip the styling or just copy what is below.

    <?
    $search_term = substr($_SERVER['REQUEST_URI'],1);
    $search_term = urldecode(stripslashes($search_term));
    $search_url = 'https://davidblog.ws/blog/index.php?s=';
    $full_search_url = $search_url . $search_term;
    $full_search_url = preg_replace('/ /', '%20', $full_search_url);
    $full_page = implode("", file($full_search_url));
    print_r($full_page); die();
    ?>

    Thanks David! This is an awesome hack.

    Damn.. Neither peice of code is stripping tailing slashes..

    Hmm.. maybe not stripping a trailing slash is a good thing.

    https://carlbanks.triplehelix.info/firefox
    My posts have firefox in them, but it’s not returning anything.

    That is odd.
    It seems to be showing your 404.php file in the address.
    See this and compare https://davidblog.ws/blog/firefox
    404.php does not show up in the address so something is messed somewhere.
    Is the code you added to .htacess exactly like the example. I don’t think a full path to 404.php worked for me.

    Check out my above link to see how I am calling the search to a newly created search.php. ?? I think it gives the lost user an understanding of what is wrong.

    How did you do that?

    That’s a cool addition, David!

    I made the 404.php call search.php, which is almost identical to index.php except I added the red text at the top of the page..
    Here is the call to that page in 404.php:
    $search_url = 'https://davidblog.ws/blog/search.php?s=';
    That is the only line that is changed. The red text is added to a #topmain division where my breadcrumb is called.

    Sorry.. How exactly did you do that?
    I am slow, so please speak slowy. ??

    Ah.. Okay I understand. Pretty cool I will whip something up.

    So I don’t use the WP search function (I use free Atomz search), but since I just migrated by whole blog over from MT and changed the URLs I thought this would be pretty handy. I changed this so that it just spits out a searchable term that I automatically put into the search box on my 404 page.
    It goes like this:
    <?
    $search_term = substr($_SERVER['REQUEST_URI'],1);
    $find = array ("'.html'", "'[-/_]'") ;
    $replace = " " ;
    $new_search = preg_replace ( $find , $replace , $search_term );
    echo $new_search ;
    ?>

    (I should probably figure out a way for it to remove the directory in the URL it’s getting, but I’m lazy and this works OK. I tried a lot of variations on "'/.+/'" but I got nothing. Any suggestions? )
    You can see it in action with this old URL: https://orangepolitics.org/about/one_community_many_voices.html

    You could also check out Binary Bonzai’s Kubrick web kit…it has a great 404 and search page.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘404 Search Function for WordPress’ is closed to new replies.