站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
▼
建站程序
开发
服务器
办公软件
开发教程
▼
服务器教程
软件使用教程
运营教程
热门电子书
▼
CSS教程
WordPress教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
热点词条
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
WordPress:The Loop in Action
”(章节)
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
跳转至:
导航
、
搜索
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
==其它模板中的Loop== WordPress可以使用不同的模板文件,用不同的方式显示你的blog。在默认WordPress主题中,有用于索引浏览的[[WordPress:Templates|模板文件]],分类浏览和文档浏览,就象一个浏览单独文章的模板。这些都会用到[[WordPress:The Loop|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>archive</em>是历史文章的集合。在默认时,文章在主索引中显示的是最新的[http://mydatapages.com/chronological.html 按时间顺序的]记录。当访问者点击某个文档连接时,或者他们手动请求某个特定时间时,(使用<nowiki>http://www.example.com/blog/index.php?m=200504</nowiki>或者 <nowiki>http://www.example.com/blog/2005/04</nowiki> 来选择所有2005年4月后的文章),WordPress将显示<em>archive</em>内容。默认情况下,归档将使用<tt>index.php</tt>,然后和你的首页一样,只显示出2005年四月后的文章。 当WordPress为访问者准备[[WordPress:Creating_an_Archive_Index|归档界面]]时,它会在你现用的主题目录中明确的寻找一个叫做<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,限制每个blog默认设置下的文章的数目。 要想让你的分类界面和索引界面不同的话,复制一个<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("Sorry, but you are looking for something that isn't here."); ?></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>是用数字表示的分类。仔细考虑你是否需要给某个分类建立全新的完整模板。 让我们来看两个分类,"Plants" 和 "Flowers",分类ID分别为3和4。在输出的地方的每个文章标题旁边,你都想要有个植物或者花的图片,取决于哪个分类被显示,你可以这样: * 使用两个分开的文件, <tt>category-3.php</tt> 和 <tt>category-4.php</tt>, 每个文件给每个文章标题使用不同的<tt>img</tt>标签。 * 在你的默认<tt>category.php</tt>文件中使用条件判断,来查看是否当前分类是"Plants"或者 "Flowers" (或者都不是), 然后显示合适的图片: <pre> <?php if (is_category('3') ): // we're in the Plants category, so show a plant ?> <img src='/images/plant.png' alt='a plant' /> <?php } elseif (is_category('4') ): // we're in the Flowers category, so show a flower ?> <img src='/images/flower.png' alt='a pretty flower' /> <?php endif; // end the if, no images for other other categories ?> </pre> 如果你添加了另外一个分类,"Cars",你想让它用一个<em>引人注目</em>的方式显示出来,那么一个分开的<tt>category-<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> And change it to something like this: <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>category-5.css</tt>文件取代默认版面。在这个例子中,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)) { // Both Comments and Pings are open ?> 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)) { // Only Pings are Open ?> 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)) { // Comments are open, Pings are not ?> 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)) { // Neither Comments, nor Pings are open ?> Both comments and pings are currently closed. <?php } edit_post_link('Edit this entry.','',''); ?> </small> </p> </pre> 这种信息—不论评论是公开还是关闭—是相当不适合放在一个索引上,归档或者分类界面的;那也是为什么只包含在<tt>single.php</tt>模板文件中的原因。
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)