站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
▼
建站程序
开发
服务器
办公软件
开发教程
▼
服务器教程
软件使用教程
运营教程
热门电子书
▼
CSS教程
WordPress教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
热点词条
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
WordPress:运转的The Loop
”(章节)
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
跳转至:
导航
、
搜索
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
==其它的模板中的Loop == WordPress可以使用不同的模板文件以不同的方式来显示你的博客。在WordPress默认主题中,有关于索引浏览,类别浏览和归档浏览的[[WordPress:Templates|模板文件]],也有一个浏览个人文章的模板。这些模板和模板文件都使用[[WordPress:The Loop]],但是使用的格式有所不同,而且对[[WordPress:Template_Tags|模板标签]]的使用也有所不同。 对于没有一个单独的模板文件的浏览,WordPress会默认使用<tt>index.php</tt>。如果一位访客需要一篇单一的文章,WordPress会首先查看一个名称为<tt>single.php</tt>的文件。如果这个文件存在的话,这个文件就会被用来向访客呈现文章。如果这个文件不存在,WordPress会使用<tt>index.php</tt>来向访客呈现文章。这叫做[[WordPress:Template Hierarchy|模板层级]]。 如果你正制作你自己的[[WordPress:Using Themes|主题]],看看默认主题中作为参考的[[WordPress:Templates|模板文件]]是很有用的。为你的其它模板文件使用你的主题的<tt>index.php</tt>作为一个模板,也很有用。执行了这些之后,你可能得到了一个已知的,并且正在运行的网页,当你创建更多的模板文件的时候,这个网页就会发生变化。 ===不同的归档样式=== 一个<em>归档</em>是对过去的文章的收集。在默认使用中,显示在你的主索引上的文章是最近[http://mydatapages.com/chronological.html 按时间顺序的]发表的文章。当访客点击你其中的一个归档链接的时候,或者如果访客手工操作要求一个特备的日期(<nowiki>http://www.example.com/blog/index.php?m=200504</nowiki> or <nowiki>http://www.example.com/blog/2005/04</nowiki> 选择从2005年四月开始的所有的文章),WordPress会显示一个<em>档案</em> 浏览。默认情况下,档案会使用<tt>index.php</tt>,因此档案看起来和你的首页是相同的,只显示从2005年四月开始的文章。 当WordPress为一名访客准备一个[[WordPress:Creating_an_Archive_Index|档案浏览]]的时候,WordPress特别要查找你当前主题目录中一个名为<tt>archive.php</tt>的文件。如果你想真实地消除首页中的档案的歧义,你只要复制<tt>index.php</tt>到<tt>archive.php</tt>,并且需要的话,编辑<tt>archive.php</tt>! 例如,如果你只想在你的文章档案列表上显示文章标题,而不是文章内容,你可能要使用以下的内容: <pre> <?php get_header(); ?> <div id="content" class="narrowcolumn"> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div class="post"> <h2 id="post-<?php the_ID(); ?>"> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2> <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small> </div> <?php endwhile; ?> <div class="navigation"> <div class="alignleft"> <?php posts_nav_link('','','&laquo; Previous Entries') ?> </div> <div class="alignright"> <?php posts_nav_link('','Next Entries &raquo;','') ?> </div> </div> <?php else : ?> <h2 class="center">Not Found</h2> <p class="center"><?php _e("Sorry, but you are looking for something that isn't here."); ?></p> <?php endif; ?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?> </pre> ===不同的类别样式=== 与档案浏览相似,WordPress为[[WordPress:Category_Templates|类别浏览]]查找一个单独的模板文件。如果一个访客点击你的博客上一个类别的一个链接,访客就会来到类别浏览。WordPress会给Loop准备来自那个类别的文章,并且根据博客的默认设置来限制文章的数目。 要使你的类别浏览与你的索引浏览有所区别,复制<tt>index.php</tt>并且将它重新命名为<tt>category.php</tt>。对于一个类别浏览,可能没有必要列出文章所在的类别,因此我们移除这个部分。反之,让我们在网页的顶上方公布类别: <pre> <?php get_header(); ?> <div id="content" class="narrowcolumn"> <p> <strong> <?php single_cat_title('Currently browsing '); ?> </strong><br /> <?php echo category_description(); ?> </p> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div class="post"> <h2 id="post-<?php the_ID(); ?>"> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?></a></h2> <small> <?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --> </small> </div> <?php endwhile; ?> <div class="navigation"> <div class="alignleft"> <?php posts_nav_link('','','&laquo; Previous Entries') ?> </div> <div class="alignright"> <?php posts_nav_link('','Next Entries &raquo;','') ?> </div> </div> <?php else : ?> <h2 class="center">Not Found</h2> <p class="center"><?php _e("对不起, 但是你找的东西,不在这儿。"); ?></p> <?php endif; ?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?> </pre> ===不同类别的不同样式=== 就如[[WordPress:Template Hierarchy|模板层级]]里所解释的那样, [[WordPress:Category_Templates|为每个类别创建单独的模板文件]]是可能的。只要命名文件<tt>category-<b><u>X</u></b>.php</tt>,其中<b><u>X</u></b>是类别的数字ID。认真考虑你是否需要为一个特别的类别准备一个全新的模板。 让我们来看看两个类别,"植物"和 "花",各自的类别ID是3和4。在每个文章标题旁边的输出中,取决于你正在显示的类别,你可能想要一颗植物或者一朵花的图片。你可以: *使用两个单独的文件,<tt>类别-3.php</tt> 和 <tt>类别-4.php</tt>,每个类别中每篇文章的标题都有一个不同的<tt>img</tt>标签。 *在你的默认的<tt>category.php</tt>文件中使用一个条件测试来看看当前的类别是"植物" 还是 "花朵"(或者都不是),并且显示适当的图像: <pre> <?php if (is_category('3') ): // 我们在植物类别,因此显示一颗植物 ?> <img src='/images/plant.png' alt='a plant' /> <?php } elseif (is_category('4') ): // 我们在花朵类别,因此显示一朵花?> <img src='/images/flower.png' alt='a pretty flower' /> <?php endif; // end the if, no images for other other categories ?> </pre> 如果你添加了另一个类别,"汽车",你想要以<em>非常</em>不同的方式来显示这个类别,那么一个分开的<tt>类别-<b><u>X</u></b>.php</tt>会更加地合适。 === 不同类别的不同的CSS === 许多用户想要为一个特别的类别创建单独的CSS文件。这一点也很容易实现。记住样式表是在HTML文件的<tt><head></tt>中定义和载入的,这一点很重要。WordPress可以为这个使用<tt>header.php</tt>文件。在默认<tt>header.php</tt>,找到这一行: <pre> <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" /> </pre> 将这个改为: <pre> <?php if ( is_category('5') ) { // Load special CSS for "Cars" category ?> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/category-5.css" type="text/css" media="screen" />; <?php } else { ?> <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" /> <?php } ?> </pre> <strong>注:</strong>汽车模板使用<tt>类别-5.css</tt>文件来覆盖默认设置。在这个例子中,CSS文件命名在类别模板文件之后,而不是正真的类别名,CSS文件将会用在类别模板文件中。因此,你知道<tt>category-5.css</tt>和<tt>category-5.php</tt>在一起。 ===不同的单个文章格式=== 当访问任何单一的文章(或者[[WordPress:Glossary#Permalink|permalink]]),WordPress会使用<tt>single.php</tt>。 来自WordPress默认single.php的这个部分,提供了关于当前文章的[[WordPress:Post_Meta_Data_Section|文章 meta 数据 信息]]: <pre> <p class="postmetadata alt"> <small> This entry was posted on <?php the_time('l, F jS, Y') ?> at <?php the_time() ?> and is filed under <?php the_category(', ') ?>. You can follow any responses to this entry through the <?php comments_rss_link('RSS 2.0'); ?> feed. <?php if (('open' == $post->comment_status) && ('open' == $post->ping_status)) { // 评论和 Pings都打开了 ?> You can <a href="#respond">leave a response</a>, or <a href="<?php trackback_url(display); ?>">trackback</a> from your own site. <?php } elseif (!('open' == $post->comment_status) && ('open' == $post->ping_status)) { // 只有 Pings 是打开的。 ?> Responses are currently closed, but you can <a href="<?php trackback_url(display); ?> ">trackback</a> from your own site. <?php } elseif (('open' == $post->comment_status) && !('open' == $post->ping_status)) { // 评论是打开的,但是Ping没有。 ?> You can skip to the end and leave a response. Pinging is currently not allowed. <?php } elseif (!('open' == $post->comment_status) && !('open' == $post->ping_status)) { // 评论和Ping都没有打开 ?> Both comments and pings are currently closed. <?php } edit_post_link('Edit this entry.','',''); ?> </small> </p> </pre> 这种形式的信息—不管评论是打开的还是关闭的—对于一个索引,归档,或者类别浏览是不合适的;这就是这种信息只包含在<tt>single.php</tt>模板文件中的原因。
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)