站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
建站程序
开发
服务器
办公软件
开发教程
服务器教程
软件使用教程
运营教程
热门电子书
WordPress教程
宝塔面板教程
CSS教程
Shopify教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
WordPress主循环(loop)
”(章节)
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
跳转至:
导航
、
搜索
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
==Loop示例== '''为某一类别的文章作特别样式设计''' '''仅供WordPress 1.5版本''' 本示例使用WordPress 1.5版的语句规则,显示文章的标题(标题将被用作文章的[http://www.wordpress.la/codex-%E4%BD%BF%E7%94%A8WordPress%E5%9B%BA%E5%AE%9A%E9%93%BE%E6%8E%A5.html 固定链接])、类别和内容。这是一个仅有框架的简单实例;通过用[http://www.wordpress.la/codex-CSS.html CSS]进行样式设计,用户的模板中可以轻松显示更多信息。 为了更具有说明性,这个例子还为编号为3的类别中的文章做了特殊设计。需要用[http://www.wordpress.la/codex-%E6%A8%A1%E6%9D%BF%E6%A0%87%E7%AD%BE.html 模板标签]来完成这一设计。 <!-- -->标签是[[HTML]]评论标签;使用这个示例时这些标签都不会显示在web浏览器中。它们的存在目的就是解释以下代码。 <!-- Start the Loop. --> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <!-- The following tests if the current post is in category 3. --> <!-- If it is, the div box is given the CSS class "post-cat-three". --> <!-- Otherwise, the div box will be given the CSS class "post". --> <?php if ( in_category('3') ) { ?> <div class="post-cat-three"> <?php } else { ?> <div class="post"> <?php } ?> <!-- Display the Title as a link to the Post's permalink. --> < h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <!-- Display the Time. --> < small><?php the_time('F jS, Y'); ?></small> <!-- Display the Post's Content in a div box. --> <div class="entry"> <?php the_content(); ?> </div> <!-- Display a comma separated list of the Post's Categories. --> < p class="postmetadata">Posted in <?php the_category(', '); ?></p> </div> <!-- closes the first div box --> <!-- Stop The Loop (but note the "else:" - see next line). --> <?php endwhile; else: ?> <!-- The very first "if" tested to see if there were any Posts to --> <!-- display. This "else" part tells what do if there weren't any. --> < p>Sorry, no posts matched your criteria.</p> <!-- REALLY stop The Loop. --> <?php endif; ?> 注意:使用HTML代码时一定要在<?php ?>标签外使用。PHP代码(即使是大括号)都必须放在 <?php ?>标签内。即使在if和else语句中,用户也可以启动或停止PHP代码以点缀HTML代码。如上例所示。 '''删除某一分类的文章''' 供WordPress 1.5或更高版本 本示例可使特定分类不显示在页面上。基本用法基于上个示例。 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <!-- If the post is in the category we want to exclude, we simply pass to the next post. --> <?php if (in_category('3')) continue; ?> <div class="post"> < h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> < small><?php the_time('F jS, Y'); ?></small> <div class="entry"> <?php the_content(); ?> </div> <p class="postmetadata">Posted in <?php the_category(', '); ?></p> </div> <!-- closes the first div box --> <?php endwhile; else: ?> < p>Sorry, no posts matched your criteria.</p> <?php endif; ?> 注意:在主页中使用该示例时,需要为分类存档使用不同模板。否则仅仅在查看分类存档时,WordPress也会删除分类3中所有文章。 如果想使用同样的模板也可以通过 is_home()标签解决上述问题: ... <?php if (in_category('3') && is_home() ) continue; ?> ... 这样分类3中的文章就只会在主页上被删除。根据指定页面的特定条件是否为真,其他[http://www.wordpress.la/codex-%E6%9D%A1%E4%BB%B6%E6%A0%87%E7%AD%BE.html 条件标签]也可以控制输出结果。 请注意,即使文章不显示在主页上,但WordPress在统计所显示的文章总数时仍然将它计算在内——这就是说,如果设置在WordPress主页上显示7篇文章,其中2篇属于分类3,这样在主页上就只会显示5篇文章。在[http://www.wordpress.la/codex-WordPress%E5%B8%83%E5%B1%80%E5%92%8C%E8%AE%BE%E8%AE%A1FAQ.html 布局和设计FAQ]上可以找到更详细的说明,如果只是希望在the loop中删除一个类别,也可以使用 [http://www.wordpress.la/codex-%E6%A8%A1%E6%9D%BF%E6%A0%87%E7%AD%BE-query_posts%28%29.html query_posts]。
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)