WordPress 博客侧栏内容调用标签代码

WordPress教程 8075

使用WordPress博客相当长一段时间了,一直用别人制作的主题总感觉不爽,要打出自己的品牌,样子得和别人不同,得树立自己的品牌风格。那就从制作WordPress博客主开始,而制作博客主题除了会CSS+DIV外,还需要熟悉WordPress博客相关的调用代码,本篇博客吧介绍WordPress博客侧栏相关内容的调用代码。

调用标签代码:

  • 分类目录:
    1
    
    <?php wp_list_cats('sort_column=name'); ?>
  • 文章归档:
    1
    
    <?php wp_get_archives('type=monthly'); ?>
  • 友情链接:
    1
    
    <?php get_links_list(); ?>
  • 标签云:
    1
    
    <?php wp_tag_cloud('smallest=8&largest=18&number=30&orderby=count&order=DESC'); ?>
  • 页面导航:
    1
    
    <?php wp_list_pages('title_li='); ?>
  • 最近文章:
    1
    2
    3
    4
    5
    6
    
    <?php query_posts('showposts=5'); ?> 
    <ul> 
    <?php while (have_posts()) : the_post(); ?> 
    <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> 
    <?php endwhile;?> 
    </ul>
  • 随机文章
    1
    2
    3
    4
    5
    
    <?php $rand_posts = get_posts('numberposts=10&orderby=rand'); foreach( $rand_posts as $post ): ?>
    <li><a href="<?php the_permalink(); ?>">
    <?php the_title(); ?></a>
    </li>
    <?php endforeach; ?>
  • 最新评论:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    
    <?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; 
    $output .= "\n<ul>"; 
    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 .= "\n</ul>"; 
    $output .= $post_HTML; 
    echo $output;?>
  • 管理登陆:
    1
    2
    3
    4
    5
    
    <?php wp_register(); ?> 
    <li><?php wp_loginout(); ?></li> 
    <li><a href="http://www.wordpress.org/">WordPress</a></li> 
    <?php wp_meta(); ?> 
    <li><a href="http://validator.w3.org/check?uri=referer">XHTML</a></li>
  • 搜索框:
    1
    2
    3
    4
    5
    6
    
    <form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
    <div>
    <input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="Go!" />
    </div>
    </form>

提示:搜索框涉及到样式,自主设定并替换。

提醒:部分调用需要用到<ul>代码标签</ul>标签。

精品推荐: