-  詳細內容 
-    
-   點擊數: 2319
如果你想讓某些文章是為了SEO而寫的。
讓搜尋引擎抓爬的,不讓其他人閱讀。
那你可以使用以下代碼,放入主題的functions.php
就會出現這個圖片,勾選之後就ok囉
 
 
 
  - function ludouseo_add_custom_box() {
-   add_meta_box('ludou_se_only', '搜尋引擎專屬', 'ludou_se_only', 'post', 'side', 'low');
-   add_meta_box('ludou_se_only', '搜尋引擎專屬', 'ludou_se_only', 'page', 'side', 'low');
- }
- add_action('add_meta_boxes', 'ludouseo_add_custom_box');
- function ludou_se_only() {
-   global $post;
-   
-   wp_nonce_field('ludou_se_only', 'ludou_se_only_nonce');
-   $meta_value = get_post_meta($post->ID, 'ludou_se_only', true);
-   if($meta_value)
-     echo ' "ludou-se-only" type="checkbox" checked="checked" value="1" /> SEO專用'; 
-   else
-     echo ' "ludou-se-only" type="checkbox" value="1" /> SEO專用'; 
- }
- function ludouseo_save_postdata($post_id) {
-   
-   if ( !isset( $_POST['ludou_se_only_nonce']))
-     return $post_id;
-   $nonce = $_POST['ludou_se_only_nonce'];
-   
-   if (!wp_verify_nonce( $nonce, 'ludou_se_only'))
-     return $post_id;
-   
-   if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
-       return $post_id;
-   
-   if ('page' == $_POST['post_type']) {
-     if ( !current_user_can('edit_page', $post_id))
-       return $post_id;
-   }
-   else {
-     if (!current_user_can('edit_post', $post_id))
-       return $post_id;
-   }
-   
-   if(!empty($_POST['ludou-se-only']))
-     update_post_meta($post_id, 'ludou_se_only', '1');
-   else
-     delete_post_meta($post_id, 'ludou_se_only');
- }
- add_action('save_post', 'ludouseo_save_postdata');
- function do_ludou_se_only() {
-   
-   if(is_singular()) {
-     global $post;
-     $is_robots = 0;
-     $ludou_se_only = get_post_meta($post->ID, 'ludou_se_only', true);
-     if(!empty($ludou_se_only)) {
-       
-       
-       $bots = array(
-             'spider',
-             'bot',
-             'crawl',
-             'Slurp',
-             'yahoo-blogs',
-             'Yandex',
-             'Yeti',
-             'blogsearch',
-             'ia_archive',
-             'Google'
-             );
-       $useragent = $_SERVER['HTTP_USER_AGENT'];
-       if(!empty($useragent)) {
-         foreach ($bots as $lookfor) {
-           if (stristr($useragent, $lookfor) !== false) {
-             $is_robots = 1;
-             break;
-           }
-         }
-       }
-       
-       
-       if(!$is_robots && !is_user_logged_in()) {
-         wp_die('您無權查看此文!');
-       }
-     }
-   }
- }
- add_action('wp', 'do_ludou_se_only');
已經登入的會員,是可以看到的喔!