许多企业网站的左下方都有一个下拉的友情链接,这个该怎么实现呢?其实很简朴,在主题的function.php文件中添加以下代码:
function dropdown_links(){global $wpdb;
$sql = "SELECT link_url, link_name, link_description FROM $wpdb->links WHERE link_visible = 'Y' Order By link_name";
$results = $wpdb->get_results($sql);
if (!$results) {
return; }
$output ='<form action="" name="dd">
<select name="dd2" onchange="document.location=dd.dd2.options[selectedIndex].value" >
<option value="">Select ... </option>';
foreach ($results as $row) {
$the_link = '#';
if (!empty($row->link_url)){
$the_link = wp_specialchars($row->link_url);
}
$desc = wp_specialchars($row->link_description, ENT_QUOTES);
$name = wp_specialchars($row->link_name, ENT_QUOTES);
$title = $desc;
if ('' != $title) {
$title = ' title="' . $title . '"';
}
$alt = ' alt="' . $name . '"';
$output .= '<option value="'. $the_link .'">'.$name.'</option>';
}
$output .= '</select></form>';
echo $output;
}
然后在利用下拉友情链接的处所添加:
<?php dropdown_links(); ?>即可,css样式你可以凭据本身的喜好来自行界说,OK !
WordPress下载
WordPress v3.5.2 简体中文版下载
界面预览本文转自:
分享到