Membuat Auto Konten pada Halaman Pencarian WordPress
Aku kadang bingung ketika searching di googlepada sebuah kata kunci tertentu, ketika aku mengunjungi link yang dirujuk google eh ternyata di situs tersebut hanya terisi : Anda mencari dengan kata kunci : ..bla..bla..bla . Tanp ak onten yang kucari ada di situs tersebut. Cari informasi, ternyata di situs yang ber CMS wordpress itu mengunakan trik Generate auto content searching. Nah ini dia nih tutorialnya :
Sebelum kita lanjutkan saya ingin mengucapkan terima kasih kepada jevuska.com untuk Create Auto Generate Content on WordPress Search Page, menggunakan Google search API
Apa yang kita butuhkan ..?
Search Term Tagging 2 plugin
All in one SEO pack plugin
WP super cache plugin
recent Google searches widget plugin
DB cache reloaded plugin
kode pete warden , Anda dapat menemukannya di sini http://petewarden.typepad.com/searchbrowser/2009/09/why-i-switched-my-search-api-from-bing-to-google.html
Google search API key, Anda bisa mendapatkannya dari sini http://code.google.com/apis/ajaxsearch/signup.html
Instal dan aktifkan semua plugin, setting plugin Search term tagging 2 dengan pengaturan ini.
memilih Ya, link to search page in Convert search terms into link,
Yes pada Display Count for each search terms,
Yes in add list automatically right after post content,
Yes in save popular search terms as tags ( monthly ). click save changes
klik simpan perubahan
Ok berikutnya, buka file search.php di tema wordpres Anda.
tambahkan kode ini di atas file search.php atau sebelum "<?php get_header(); ?><?php get_header(); ?>"
<?php
define(‘GOOGLE_API_KEY’, ‘CHANGE WITH YOUR GOOGLE SEARCH API KEY’);
function pete_curl_get($url, $params)
{
$post_params = array();
foreach ($params as $key => &$val) {
if (is_array($val)) $val = implode(‘,’, $val);
$post_params[] = $key.’=’.urlencode($val);
}
$post_string = implode(‘&’, $post_params);
$fullurl = $url.”?”.$post_string;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_URL, $fullurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, ‘Mailana (curl)’);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function perform_google_web_search($termstring)
{
$start = 0;
$result = array();
while ($start<50)
{
$searchurl = ‘http://ajax.googleapis.com/ajax/services/search/web?v=1.0′;
$searchurl .= ‘&key=’.GOOGLE_API_KEY;
$searchurl .= ‘&start=’.$start;
$searchurl .= ‘&rsz=large’;
$searchurl .= ‘&filter=0′;
$searchurl .= ‘&q=’.urlencode($termstring);
$response = pete_curl_get($searchurl, array());
$responseobject = json_decode($response, true);
if (count($responseobject['responseData']['results'])==0)
break;
$allresponseresults = $responseobject['responseData']['results'];
foreach ($allresponseresults as $responseresult)
{
$result[] = array(
‘url’ => $responseresult['url'],
‘title’ => $responseresult['title'],
‘abstract’ => $responseresult['content'],
);
}
$start += 8;
}
return $result;
}
if (isset($_REQUEST['q'])) {
$termstring = urldecode($_REQUEST['q']);
} else {
$termstring = ”;
}
?>
kemudian tambahkan kode ini sebelum "<php endif;??>"
<?php
function CleanFileNameBan($result){
$bannedkey = array(“key1″,”key2″,”key3″,”admin”,”porno”); //insert the unwanted keywords which you wanted to filter.
$result = str_replace($bannedkey, ”,$result);
$result = trim($result);
return $result;
}
function delete_special_characters($result) { //function for Delete all special characters on title
$result = strip_tags($result);
$result = preg_replace(‘/&.+?;/’, ”, $result);
$result = preg_replace(‘/\s+/’, ‘ ‘, $result);
$result = preg_replace(‘|%([a-fA-F0-9][a-fA-F0-9])|’, ‘ ‘, $result);
$result = preg_replace(‘|-+|’, ‘ ‘, $result);
$result = preg_replace(‘/&#?[a-z0-9]+;/i’,”,$result);
$result = preg_replace(‘/[^%A-Za-z0-9 _-]/’, ‘ ‘, $result);
$result = trim($result, ‘ ‘);
return $result;
}
function change_sign($result) { //function to change space ( ) to minus (-) on permalink title
$result = strtolower($result);
$result = preg_replace(‘/&.+?;/’, ”, $result);
$result = preg_replace(‘/\s+/’, ‘-’, $result);
$result = preg_replace(‘|%([a-fA-F0-9][a-fA-F0-9])|’, ‘-’, $result);
$result = preg_replace(‘|-+|’, ‘-’, $result);
$result = preg_replace(‘/&#?[a-z0-9]+;/i’,”,$result);
$result = preg_replace(‘/[^%A-Za-z0-9 _-]/’, ‘-’, $result);
$result = trim($result, ‘-’);
return $result;
}?>
<?php $termstring = $s ?>
<?php if ($s!=”) {
$googleresults = perform_google_web_search($termstring);
//You can change <h4> code
print ‘<h4>Search Result ‘.$s.’</h4>’;
foreach ($googleresults as $result) {
print ‘<div>’;
print ‘<h4><a target=”_blank” href=”‘. get_settings(‘home’).’/search/’.change_sign(CleanFileNameBan(delete_special_characters($result['title']))).’”>’.CleanFileNameBan(delete_special_characters($result['title'])).’</a></h4>’;
print ‘<p>’.CleanFileNameBan(strip_tags($result['abstract'])).’</p>’;
print ‘<p style=”color:#666666″>’.$result['url'].’</p>’;
print ‘</div>’;
}
}
?>
Kemudian save file search.php. Sekarang yang perlu Anda lakukan adalah ketik saja kata kunci bertarget Anda ke formulir pencarian di blog Anda selama beberapa hari. dan jangan lupa untuk membuat posting harian.
bermanfaat banget gan
BalasHapuskunjungi juga http://bloggersaurus.net