当前位置: 首页 > 图文教程 > 网页制作 > CMS技巧 > WordPress主题的index.php代码

CMS技巧
SupeV影音播客系统前台功能介绍
SupeV影音播客系统SupeV产品特点
SupeV影音播客系统后台功能
SupeV影音播客系统搭建视频站步骤
SupeV影音播客系统的其它特色功能
织梦网站内容管理系统(DedeCms)用户手册
DedeCms模板制作轻松学
Discuz论坛介绍及相关软件下载
在CMS中用Meta来标注版权信息
Dvbbs V8.2.0 RC1模板驱动机制
动易、新云和风讯后台模块的比较
轻松安装MM喜欢的Discuz!论坛表情包
博客程序Wordpress常用插件逐个介绍
KingCMS5.0从安装到设置使用教程
WordPress设置自己喜欢的标签云
制作WordPress的标签云页面的实例
优化Wordpress的速度的几个技巧
丢失wordpress登录密码后的解决方法
初用WordPress自动转换中文标点问题
WordPress插件:中文标题自动转换拼音

CMS技巧 中的 WordPress主题的index.php代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-03   浏览: 46 ::
收藏到网摘: n/a

<?php get_header(); ?>
 <div id="content" class="narrowcolumn">
 <?php if (have_posts()) : ?>
  <?php while (have_posts()) : the_post(); ?>
   <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h2>
    <small><?php the_time(__('F jS, Y', 'kubrick')) ?> <!-- by <?php the_author() ?> --></small>
    <div class="entry">
     <?php the_content(__('Read the rest of this entry &raquo;', 'kubrick')); ?>
    </div>
    <p class="postmetadata"><?php the_tags(__('Tags:', 'kubrick') . ' ', ', ', '<br />'); ?> <?php printf(__('Posted in %s', 'kubrick'), get_the_category_list(', ')); ?> | <?php edit_post_link(__('Edit', 'kubrick'), '', ' | '); ?>  <?php comments_popup_link(__('No Comments &#187;', 'kubrick'), __('1 Comment &#187;', 'kubrick'), __('% Comments &#187;', 'kubrick'), '', __('Comments Closed', 'kubrick') ); ?></p>
   </div>
  <?php endwhile; ?>
  <div class="navigation">
   <div class="alignleft"><?php next_posts_link(__('&laquo; Older Entries', 'kubrick')) ?></div>
   <div class="alignright"><?php previous_posts_link(__('Newer Entries &raquo;', 'kubrick')) ?></div>
  </div>
 <?php else : ?>
  <h2 class="center"><?php _e('Not Found', 'kubrick'); ?></h2>
  <p class="center"><?php _e('Sorry, but you are looking for something that isn&#8217;t here.', 'kubrick'); ?></p>
  <?php include (TEMPLATEPATH . "/searchform.php"); ?>
 <?php endif; ?>
 </div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

先说下三个函数get_header(); get_sidebar(); get_footer();分别输出各自的模板代码如header.php、sidebar.php、footer.php;相应的模板代码生成后加入相应位置。
第5行的if (have_posts()) : 为判断是否含有日志;
第7行的 while (have_posts()) : 为当有日志时,进行循环操作;the_post(); 为对单个循环中的一篇日志进行操作。
第9行:post_class();输出个性化的日志class——官方参考例如置顶文章回输出不同的class,可以加入参数自定义生成的类名如:post_class(’myclass’);;the_ID();生成日志id数字号。
第10行:the_permalink()为每篇日志对应内容页的链接,the_title();为日志标题;
第11行:the_time(__(’F jS, Y’, ‘kubrick’)为日志发布时间;
第14行:the_content(__(’Read the rest of this entry »’, ‘kubrick’));为日志内容;
第17行:the_tags(__(’Tags:’, ‘kubrick’) . ‘ ‘, ‘, ‘, ‘<br />’); 为日志所在标签;printf(__(’Posted in %s’, ‘kubrick’), get_the_category_list(’, ‘));为日志所在分类;
第20行: endwhile; 结束循环;
第23行: next_posts_link(__(’« Older Entries’, ‘kubrick’))上一篇日志链接;
第24行: previous_posts_link(__(’Newer Entries »’, ‘kubrick’)) ?>下一篇日志链接;
第27行: else : 为没有日志时候的情况,
第29行:php _e(’Not Found’, ‘kubrick’);为没有发现日志
第30行:php _e(’Sorry, but you are looking for something that isn’t here.’, ‘kubrick’);为相关提示;
第31行:include (TEMPLATEPATH . “/searchform.php”);插入搜索表单模板;
第33行:endif;结束判断。