WordPress 模板制作笔记(首页边栏)
WordPress做博客首页基本跟分类目录一样使用分类目录模板就可以了如果是做 图片站,新闻等内容比较多的网站,就会有很多栏目,分很多区块,基本使用制作边栏的方法即可。
一般边栏有最新文章,热门文章,最新评论,制定分类文章等。
1 2 | //自定义菜单 register_nav_menus( array( 'menu' => __( 'menu', '' ), ) ); |
指定分类文章:
1 2 3 4 5 6 | <ul> <?php query_posts('cat=1&showposts=5'); ?>//cat是要调用的分类ID,showposts是需要显示的文章数量 <?php while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> <?php endwhile; wp_reset_query(); ?> </ul> |
最新评论:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | //最新评论 function h_comments($outer,$limit){ 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,comment_author_email, SUBSTRING(comment_content,1,22) 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 = '' AND user_id='0' AND comment_author != '$outer' ORDER BY comment_date_gmt DESC LIMIT $limit"; $comments = $wpdb->get_results($sql); foreach ($comments as $comment) { $output .= '<li class="re-comment"> <div class="re-avatar"> <img class="avatar avatar-35 photo" width="35" height="35" src="/wp-content/themes/dianyingbt/default-35.png" alt="访客默认头像" data-bd-imgshare-binded="1"/> </div> <div class="re-content"> <div class="re-author"><apan>'.strip_tags($comment->comment_author).':</apan></div> <div class="re-excerpt"> <a href="'. get_permalink($comment->ID) .'#comment-' . $comment->comment_ID . '" title="《'.$comment->post_title . '》上的评论" ><span class="s_desc">'. strip_tags($comment->com_excerpt).'</span></a></div></div></li> <div style="clear:both"></div> '; } $output = convert_smilies($output); echo $output; } |
最新评论调用:
1 | <?php h_comments($outer='博主',$limit='15'); ?> |
友情链接:
激活代码
1 2 3 4 | /* * See http://core.trac.wordpress.org/ticket/21307 */ add_filter( 'pre_option_link_manager_enabled', '__return_true' ); |
调用代码
1 | <?php wp_list_bookmarks('title_li=&categorize=0&orderby=updated&limit=100'); ?> |
WordPress添加彩色标签云
1调用标签云
1 2 3 4 5 6 7 | <?php wp_tag_cloud('smallest=12&largest=18&unit=px&number=0&orderby=count&order=DESC');?> //smallest表示标签的最小字号 //largest表示最大字号 //unit=px表示字体使用像素单位 //number=0表示显示所有标签,如果为40,表示显示40个 //orderby=count表示按照标签所关联的文章数来排列 //order=DESC表示降序排序(ASC表示升序排序,DESC表示降序排序) |
更多 wp_tag_cloud() 参数,请参考 WordPress文档 wp tag cloud
2边栏彩色tag函数
1 2 3 4 5 6 7 8 9 10 11 12 13 | //边栏彩色标签 function colorCloud($text) { $text = preg_replace_callback('|<a (.+?)>|i','colorCloudCallback', $text); return $text; } function colorCloudCallback($matches) { $text = $matches[1]; $color = dechex(rand(0,16777215)); $pattern = '/style=(\'|\”)(.*)(\'|\”)/i'; $text = preg_replace($pattern, "style="color:#{$color};$2;"", $text); return "</a><a $text>"; } add_filter('wp_tag_cloud', 'colorCloud', 1); |
WordPress调用同分类随机文章
1 2 3 4 5 6 7 8 9 10 11 12 | <?php $cat = get_the_category(); foreach($cat as $key=>$category){ $catid = $category->term_id; } $args = array('orderby' => 'rand','showposts' => 8,'cat' => $catid ); $query_posts = new WP_Query(); $query_posts->query($args); while ($query_posts->have_posts()) : $query_posts->the_post(); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endwhile;?> |
浅唱6(微信/QQ号:909912499),欢迎分享本文,转载请保留出处!部分内容来自网络,如有侵权请联系删除处理!
相关信息
本站提供代码修改,dedecms,WordPress仿站二次开发 / PHP网站建设以及SEO优化等网络营销推广等服务。
如有需要请加QQ: 909912499