国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > CMS > Wordpress > 正文

菜鳥接觸wordpress遇到的一些問題

2024-09-07 00:50:48
字體:
來源:轉載
供稿:網友

WordPress頁面小工具添加:

第一步:在 Function.php加以下代碼:

  1. if(function_exists('register_sidebar')){ 
  2. register_sidebar(array
  3. 'name'=>'頂部'
  4. 'id' => 'banner-text'
  5. 'description' => ''
  6. 'before_widget' => ''
  7. 'after_widget' => ''
  8. 'before_title' => ''
  9. 'after_title' => ''
  10. )); 

第二步:在后臺小工具"頂部"中加入需要的小工具

WordPress列表頁面調用縮略圖(文章第一張圖)

第一步:在Function.php加以下代碼:

  1. function thumb_img($soContent){ 
  2. $soImages = '~]*/ />~'
  3. preg_match_all( $soImages$soContent$thePics ); 
  4. $allPics = count($thePics[0]); 
  5. if$allPics > 0 ){ 
  6. echo $thePics[0][0]; 
  7. else { 
  8. echo " 
  9. echo bloginfo('template_url'); 
  10. echo "/images/thumb.gif'>"

第二步:在列表模版頁中加入:

  1. <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' );

第二步:在列表模版頁中加入:

  1. <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"
  2. <?php if ( has_post_thumbnail() ) { ?> 
  3. <?php the_post_thumbnail(); ?> 
  4. <?php } else {?> 
  5. <img src="<?php bloginfo('template_url'); ?>/images/thumb.gif" /> 
  6. <?php } ?> 
  7. </a> 

WordPress右側彩色標簽云:

在Function.php加以下代碼:

  1. function colorCloud($text) { 
  2. $text = preg_replace_callback('|<a (.+?)>|i''colorCloudCallback'$text); 
  3. return $text
  4. function colorCloudCallback($matches) { 
  5. $text = $matches[1]; 
  6. $color = dechex(rand(0,16777215)); 
  7. $pattern = '/style=(/'|/")(.*)(/'|/")/i'
  8. $text = preg_replace($pattern"style=/"color:#{$color};$2;/""$text); 
  9. return "<a $text>"
  10. add_filter('wp_tag_cloud''colorCloud', 1); 

WordPress無插件調用最新、熱門、隨機文章:

調用最新文章:

  1. <ul> 
  2. <?php $post_query = new WP_Query(‘showposts=10′); 
  3. while ($post_query->have_posts()) : $post_query->the_post(); 
  4. $do_not_duplicate = $post->ID; ?> 
  5. <li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li> 
  6. <?php endwhile;?> 
  7. </ul> 

調用熱門文章:

  1. <ul> 
  2. <?php 
  3. $post_num = 10; // 設置調用條數 
  4. $args = array
  5. ‘post_password’ => ”, 
  6. ‘post_status’ => ‘publish’, // 只選公開的文章. 
  7. ‘post__not_in’ => array($post->ID),//排除當前文章 
  8. ‘caller_get_posts’ => 1, // 排除置頂文章. 
  9. ‘orderby’ => ‘comment_count’, // 依評論數排序. 
  10. ‘posts_per_page’ => $post_num 
  11. ); 
  12. $query_posts = new WP_Query(); 
  13. $query_posts->query($args); 
  14. while$query_posts->have_posts() ) { $query_posts->the_post(); ?> 
  15. <li><a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a></li> 
  16. <?php } wp_reset_query();?> 
  17. </ul> 

調用隨機文章:

  1. <ul> 
  2. <?php 
  3. global $post
  4. $postid = $post->ID; 
  5. $args = array( ‘orderby’ => ‘rand’, ‘post__not_in’ => array($post->ID), ‘showposts’ => 10); 
  6. $query_posts = new WP_Query(); 
  7. $query_posts->query($args); 
  8. ?> 
  9. <?php while ($query_posts->have_posts()) : $query_posts->the_post(); ?> 
  10. <li><a href=”<?php the_permalink(); ?>” rel=”bookmark” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a></li> 
  11. <?php endwhile; ?> 
  12. </ul> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南雄市| 南岸区| 石棉县| 吴旗县| 大冶市| 龙岩市| 南岸区| 玉林市| 塔城市| 通化县| 江永县| 大田县| 临清市| 黑山县| 平山县| 青川县| 南漳县| 宜兴市| 玛沁县| 台州市| 靖边县| 平遥县| 桦甸市| 宁乡县| 呈贡县| 泽普县| 柳林县| 广灵县| 江西省| 武强县| SHOW| 襄汾县| 嘉义县| 天门市| 万全县| 嘉义市| 龙陵县| 钟祥市| 宝清县| 嘉禾县| 富锦市|