WordPress页面小工具添加:
第一步:在 Function.php加以下代码:
- if(function_exists('register_sidebar')){
- register_sidebar(array(
- 'name'=>'顶部',
- 'id' => 'banner-text',
- 'description' => '',
- 'before_widget' => '',
- 'after_widget' => '',
- 'before_title' => '',
- 'after_title' => '',
- ));
- }
第二步:在后台小工具"顶部"中加入需要的小工具
WordPress列表页面调用缩略图(文章第一张图)
第一步:在Function.php加以下代码:
- function thumb_img($soContent){
- $soImages = '~]*/ />~';
- preg_match_all( $soImages, $soContent, $thePics );
- $allPics = count($thePics[0]);
- if( $allPics > 0 ){
- echo $thePics[0][0];
- }
- else {
- echo "
- echo bloginfo('template_url');
- echo "/images/thumb.gif'>";
- }
- }
第二步:在列表模版页中加入:
- <span id='thumb'><a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php thumb_img($post->post_content); ?></a></span>
WordPress列表页面调用缩略图(特色图片)
第一步:在Function.php加以下代码:
add_theme_support( 'post-thumbnails' );
第二步:在列表模版页中加入:
- <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
- <?php if ( has_post_thumbnail() ) { ?>
- <?php the_post_thumbnail(); ?>
- <?php } else {?>
- <img src="<?php bloginfo('template_url'); ?>/images/thumb.gif" />
- <?php } ?>
- </a>
WordPress右侧彩色标签云:
在Function.php加以下代码:
- 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 $text>";
- }
- add_filter('wp_tag_cloud', 'colorCloud', 1);
WordPress无插件调用最新、热门、随机文章:
调用最新文章:
- <ul>
- <?php $post_query = new WP_Query(‘showposts=10′);
- while ($post_query->have_posts()) : $post_query->the_post();
- $do_not_duplicate = $post->ID; ?>
- <li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>
- <?php endwhile;?>
- </ul>
调用热门文章:
- <ul>
- <?php
- $post_num = 10; // 设置调用条数
- $args = array(
- ‘post_password’ => ”,
- ‘post_status’ => ‘publish’, // 只选公开的文章.
- ‘post__not_in’ => array($post->ID),//排除当前文章
- ‘caller_get_posts’ => 1, // 排除置頂文章.
- ‘orderby’ => ‘comment_count’, // 依評論數排序.
- ‘posts_per_page’ => $post_num
- );
- $query_posts = new WP_Query();
- $query_posts->query($args);
- while( $query_posts->have_posts() ) { $query_posts->the_post(); ?>
- <li><a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a></li>
- <?php } wp_reset_query();?>
- </ul>
调用随机文章:
- <ul>
- <?php
- global $post;
- $postid = $post->ID;
- $args = array( ‘orderby’ => ‘rand’, ‘post__not_in’ => array($post->ID), ‘showposts’ => 10);
- $query_posts = new WP_Query();
- $query_posts->query($args);
- ?>
- <?php while ($query_posts->have_posts()) : $query_posts->the_post(); ?>
- <li><a href=”<?php the_permalink(); ?>” rel=”bookmark” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a></li>
- <?php endwhile; ?>
- </ul>
新闻热点
疑难解答
图片精选