分享

完全自定义纯代码打造你的wordpress站点侧边栏

 戈德斯特 2011-12-15

liveme导语

图片代码有问题请看原地址http://www./sidebarself.html

我们的管理后台有个“小工具”的选项,就是管理侧边栏栏目的,在那里调用比较方便快捷。但是有时候,那里的功能无法满足你想要的侧边栏功能,这时候你需要自己添加代码到sidebar.php去实现,问题来了,这时候你不好控制侧边栏栏目的顺序,这是很揪心的。

另外,在后台Widgets小工具调用的话,速度肯定不如直接在sidebar.php里面调用。所以,有些朋友就想完全按照自己的意愿去编写侧边栏。下面liveme给大家提供一个参考的方案和和一些调用代码,希望能帮到你。

1、调用搜索栏

如果你是调用wp原版的搜索栏框的话,代码:

<div style=”margin-left: 20px;”>
<?php include (TEMPLATEPATH . ‘/searchform.php’); ?>
</div>
如果你想自定义自己的搜索框,可以根据自己主题修改CSS就可以。
2、调用twitter

我之前已经写过一篇文章,wordpress侧边栏调用twitter,非插件,解决时间缓存问题 点击进去参考吧。

3、调用分类目录

代码也很简单:

<div class=”sidebar-box”>

<h3>live分类</h3>

<ul>

<?php wp_list_categories(‘show_count=0&title_li=’); ?>

</ul>

</div>

4、调用随机文章

标题文字版:

<ul>

<?php $my_query = new WP_Query(‘orderby=rand&showposts=6′);

while ($my_query->have_posts()) : $my_query->the_post();

?>

<li><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”点击打开 <?php the_title(); ?>”><?php the_title2() ?></a></li>

<?php endwhile; ?>

</ul>

缩略图版,这个需要使用一个缩略图插件WP-Thumbnails (点击下载),插件具体用法请进插件作者页面安装了这个插件后,直接调用下面代码就可以:

<?php if(function_exists(‘wp_thumbnails_for_random_posts’)) { wp_thumbnails_for_random_posts(‘num=9&width=75&height=75′); } ?>

5、调用标签云

<?php wp_tag_cloud(‘smallest=10&largest=10&number=40′); ?>

6、文章归档

<?php wp_get_archives(‘type=monthly’); ?>

7、友情链接(随机显示10条)

<?php wp_list_bookmarks(‘orderby=rand&limit=10′); ?>

8、调用读者墙

<ul class=“ffox_most_active”>
<?php if $counts : foreach ($counts as $count:
echo ‘<li>’ . ‘<a href=”‘. $count->comment_author_url . ‘” target=”_blank” title=”‘ . $count->comment_author . ‘ (‘. $count->cnt .‘层楼)”><img src=”http://www./avatar.php?gravatar_id=’.md5($count->comment_author_email).‘&size=32&d=identicon&r=G” alt=”‘ . $count->comment_author . ‘ (‘. $count->cnt . ‘层楼)” /></a></li>’;
endforeachendif;
?>
</ul>

9、调用最新文章

<?php get_archives(‘postbypost‘, 10); ?>

10、调用最新留言

<?php

global $wpdb;

$sql = “SELECT DISTINCT ID, post_title, post_password, comment_ID,

comment_post_ID, comment_author, comment_date_gmt, comment_approved,

comment_type,comment_author_url,

SUBSTRING(comment_content,1,30) AS com_excerpt

FROM $wpdb->comments

LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =

$wpdb->posts.ID)

WHERE comment_approved = ’1′ AND comment_type = ” AND

post_password = ”

ORDER BY comment_date_gmt DESC

LIMIT 10″;

$comments = $wpdb->get_results($sql);

$output = $pre_html;

foreach ($comments as $comment) {

$output .= “\n<li>”.strip_tags($comment->comment_author)

.”:” . ” <a href=\”" . get_permalink($comment->ID) .

“#comment-” . $comment->comment_ID . “\” title=\”on ” .

$comment->post_title . “\”>” . strip_tags($comment->com_excerpt)

.”</a></li>”;

}

$output .= $post_HTML;

echo $output;?>

暂时说这么多,如果你有更好的建议,可以留言和大家分享。

无觅相关文章插件,快速提升流量

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多