IT服務(wù)網(wǎng)
wordpress添加友情鏈接1
在主題文件的function.php 后面添加 /*添加友情鏈接*/ add_action('admin_init', 'wpjam_blogroll_settings_api_init'); function wpjam_blogroll_settings_api_init() { add_settings_field('wpjam_blogroll_setting', '友情鏈接', 'wpjam_blogroll_setting_callback_function', 'reading'); register_setting('reading','wpjam_blogroll_setting'); } function wpjam_blogroll_setting_callback_function() { echo '<textarea name="wpjam_blogroll_setting" rows="10" cols="50" id="wpjam_blogroll_setting" class="large-text code">' . get_option('wpjam_blogroll_setting') . '</textarea>'; } function wpjam_blogroll(){ $wpjam_blogroll_setting = get_option('wpjam_blogroll_setting'); if($wpjam_blogroll_setting){ $wpjam_blogrolls = explode("\n", $wpjam_blogroll_setting); echo '<p>友情鏈接:'; foreach ($wpjam_blogrolls as $wpjam_blogroll) { $wpjam_blogroll = explode("|", $wpjam_blogroll ); echo '<a target="_blank" href="'.trim($wpjam_blogroll[0]).'" title="'.esc_attr(trim($wpjam_blogroll[1])).'">'.trim($wpjam_blogroll[1]).'</a> '; } echo '</p>'; } } 后臺 > 設(shè)置 > 閱讀 界面,就有一個友情鏈接添加的輸入框。按照 鏈接 |標(biāo)題 的方式輸入所有的友情鏈接:多個換行即可 然后在前臺需要顯示的地方添加 <?php if (function_exists('wpjam_blogroll')) { wpjam_blogroll(); } ?> 如果只想在首頁顯示的話 <?php if (function_exists('wpjam_blogroll')&& (is_home()||is_front_page())) { wpjam_blogroll(); } ?> 如果要在新窗口打開的話,修改 wpjam_blogrol 函數(shù)里面的這一行就可以了 后臺打開短代碼,新建以下代碼 if (function_exists('wpjam_blogroll')&& (is_home()||is_front_page())) { wpjam_blogroll(); } add_shortcode( 'friendlink', 'wpjam_blogroll' ); 在前臺合適的位置加入短代碼或者簡碼,[friendlink] echo '<a target="_blank" href="'.trim($wpjam_blogroll[0]).'" title="'.esc_attr(trim($wpjam_blogroll[1])).'">'.trim($wpjam_blogroll[1]).'</a> '; |
關(guān)鍵詞列表
|