Author Topic: Search News Posts Only From News Page  (Read 4389 times)

Offline gillweb

  • Posts: 83
Search News Posts Only From News Page
« on: October 28, 2007, 10:08:12 PM »
I can't say this is the PERFECT solution but it seems to work for me  :-D

Make a new CODE page that is hidden name "search news" (i added it as a child page of my news page).  Add this code to this page
Code: [Select]
$string = @$_POST['string'];
$query = "SELECT * FROM mod_news_posts WHERE content_long LIKE '%$string%'";
$result = mysql_query($query);
$rows=mysql_num_rows($result);

if ($rows == 0) { echo" No Results"; }

   $error = mysql_error();
      if (!$result = mysql_query($query)) {
           print "$error";
       }

while($data = mysql_fetch_object($result)){
$title = $data->title;
$link = $data->link;
$short= $data->content_short;

echo '<p>';
echo '<b>'.$title.'</b><br />';
echo ''.$short.' ';
echo '<a href="'.WB_URL.'/pages/'.$link.PAGE_EXTENSION.'">Read More...</a></p>';

}
Then add a Code sectin to you main news page where you want your search box to show and enter this code:
Code: [Select]
echo "<br /><center><form method=\"post\" action=\"";
echo WB_URL;
echo "/pages/news/search-news";
echo PAGE_EXTENSION;
echo  "\">";
echo "<input type=\"text\" maxlength=\"64\" name=\"string\" />&nbsp;&nbsp;&nbsp;";
echo "<input type=\"submit\" value=\"Search News\" />";
echo "</form></center><br />";
You should be good to go now  :mrgreen:

jar

  • Guest
Re: Search News Posts Only From News Page
« Reply #1 on: June 27, 2008, 10:55:16 AM »
i have a error


Fatal error: Cannot redeclare search_highlight() (previously declared in /home/tusirom1/public_html/framework/frontend.functions.php:70) in /home/tusirom1/public_html/framework/frontend.functions.php on line 92

Offline thorn

  • Posts: 980
  • Gender: Male
    • Projects
Re: Search News Posts Only From News Page
« Reply #2 on: June 27, 2008, 07:12:16 PM »
Hello,

there is a handy - yet not(?) documented - new search-feature since wb2.7:
see http://www.websitebaker2.org/forum/index.php/topic,10058.msg59052.html#msg59052

To search in news-postings only you can do this to add a search-box: (if the news-pages appears as http://www.example.org/pages/news.php)
Code: [Select]
<form name="search" action="<?php echo WB_URL.&#39;/search/index&#39;.PAGE_EXTENSION; ?>" method="get">
  <input type="hidden" name="search_path" value="/news">
  <input type="text" name="string" value="search" /><br />
  <input type="submit" value="Search" /><br />
  <input type="radio" name="match" id="match_all" value="all" checked="checked" /><label for="match_all">All Words</label>
  <input type="radio" name="match" id="match_any" value="any" /><label for="match_any">Any Words</label>
  <input type="radio" name="match" id="match_exact" value="exact" /><label for="match_exact">Exact Match</label>
</form>

thorn.

 

postern-length