Welcome, Guest. Please login or register.
March 21, 2010, 10:59:06 AM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
110578 Posts in 15968 Topics by 9313 Members
Latest Member: Gudrun
* Home Help Search Login Register
+  WebsiteBaker Community Forum
|-+  English
| |-+  Droplets (PHP code for use with Droplet module) & Snippets (raw PHP code) (Moderators: Argos, BerndJM)
| | |-+  Search News Posts Only From News Page
Pages: [1] Go Down Print
Author Topic: Search News Posts Only From News Page  (Read 1122 times)
gillweb

Offline Offline

Posts: 78



« on: October 28, 2007, 10:08:12 PM »

I can't say this is the PERFECT solution but it seems to work for me  grin

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:
$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:
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  afro
Logged
jar

Offline Offline

Posts: 62


« 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
Logged
thorn

Offline Offline

Posts: 861


WWW
« 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:
<form name="search" action="<?php echo WB_URL.'/search/index'.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.
Logged

¡ɹǝpun-uʍop ɥɔɐu ǝssǝnɹƃ
Pages: [1] Go Up Print 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!