找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
积分等级发帖收益的说明江阴论坛帮助汇总江阴论坛管理规则(必看)江阴论坛版主招聘中江阴论坛已运行
查看: 1418|回复: 0

[WordPress] 制作CMS型主题的实用代码

[复制链接]
发表于 2009-5-22 08:50:48 | 显示全部楼层 |阅读模式
显示favicon图标
  1. <link rel="shortcut icon" type="image/ico" href="<?php bloginfo('stylesheet_directory'); ?>/images/favicon.ico" />
复制代码
无插件调用最新文章的例表(20代表要调用的文章数)
  1. <?php wp_get_archives('type=postbypost&limit=20'); ?>
复制代码
最新评论的调用,把下面语句加入到functions.php文件的 ? > 之前
  1. function get_new_comment_list() {
  2. global $wpdb;
  3. $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";
  4. $comments = $wpdb->get_results($sql);
  5. $output = $pre_HTML;
  6. $output .= "\n<ul class="sidelist">";
  7. foreach ($comments as $comment) {
  8. $output .= "\n<li>". "<a href="" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID . "" title="发表于《".
  9. $comment->post_title . "》">" . strip_tags($comment->com_excerpt) ."</a></li>";}
  10. $output .= "\n</ul>";
  11. $output .= $post_HTML;
  12. echo $output;
  13. }
复制代码
调用方法:在所要显示的地方加上如下代码。
  1. <?php get_new_comment_list(); ?>
复制代码
显示指定分类的描述(1代表分类ID为1)
  1. <?php echo category_description(1); ?>
复制代码
按分类显示每个分类的最新文章,代码如下:(其中的1,3,4,5,6,7是你要显示的分类ID号)
  1. <?php $display_categories = array(1,3,4,5,6,7); foreach ($display_categories as $category) { ?>
  2. <div class="postlist">
  3. <?php query_posts("showposts=5&cat=$category"); $wp_query->is_category = false; $wp_query->is_archive = false; $wp_query->is_home = true; ?>
  4. <h3 class="posttitle"><span class="more"><a href="<?php echo get_category_link($category);?>">&#187; 查看更多</a></span><?php single_cat_title(); ?></h3>
  5. <ul>
  6. <?php if (have_posts()) : ?>
  7. <?php while (have_posts()) : the_post(); ?>
  8. <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
  9. <?php endwhile; ?>
  10. <?php else : ?><p class="center">此分类暂无内容</p>
  11. <?php endif; ?>
  12. </ul>
  13. </div>
  14. <?php } ?>
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|江阴人家

GMT+8, 2024-4-25 06:46 , Processed in 0.026299 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表