站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
▼
建站程序
开发
服务器
办公软件
开发教程
▼
服务器教程
软件使用教程
运营教程
热门电子书
▼
CSS教程
WordPress教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
热点词条
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
WordPress:Category Templates
”(章节)
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
跳转至:
导航
、
搜索
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
== 给类别网页添加文本== === Static Text Above Posts === === 文章上面的静态文本 === Suppose you want some static text displayed before the list of Posts on your Category page(s). By "static", we mean text that remains the same, no matter which posts will be displayed below, and no matter which category is being displayed. Here is how to do it: above [[WordPress:The Loop]] section of your Template file, insert the following code: 假如你希望类别网页上的文本列表之前显示一些静态文本。"静态的",我们指的不管下面显示什么文章,不管正在显示什么类别,文本都是相同的。下面是我们怎样实现这个操作:在模板文件的[[WordPress:The Loop|The Loop]]部分上面,插入以下的代码: <pre><nowiki> <p> This is some text that will display at the top of the Category page. </p></nowiki></pre> <pre><nowiki> <p> 这些文本将要在类别网页的顶上方显示。 </p></nowiki></pre> === Different Text on Some Category Pages === === 相同的类别网页上不同的文本=== A slightly more complex possibility is that you want different text to display depending on which category page the visitor is viewing. Then you would add the "default" text to the main <tt>category.php</tt> file, and create special <tt>category-#.php</tt> files (with their own version of the text, as described in the Introduction) for each category that needs special text at the top. 一个稍微复杂的可能性是,根据访客正在访问哪个类别网页,你希望显示不同的文本。然后,你会向主要的<tt>category.php</tt>文件添加"默认"文件,并且为需要在顶上方显示特别的文本的类别创建特别的<tt>category-#.php</tt>文件(自身版本的文本,如介绍中所述)。 This does however create a lot of files in your theme directory, and can be avoided using the following code '''OUTSIDE''' the loop: 这的确在你的主题目录中创建了许多文件,而且可以避免在loop'''外'''使用下面的代码: <pre><nowiki> <?php if (is_category('Category A')) { ?> <p>This is the text to describe category A</p> <?php } elseif (is_category('Category B')) { ?> <p>This is the text to describe category B</p> <?php } else { ?> <p>This is some generic text to describe all other category pages, I could be left blank</p> <?php } ?> </nowiki></pre> <pre><nowiki> <?php if (is_category('Category A')) { ?> <p>这是描述类别A的文本</p> <?php } elseif (is_category('Category B')) { ?> <p>这是描述类别B的文本</p> <?php } else { ?> <p>这是一般的文本,用来描述所有其它的类别网页,我可以保留空白</p> <?php } ?> </nowiki></pre> This does the following. Checks to see if we are looking at Category A, if we are then show the first bit of text, but if we're not then check if we are looking at Category B. If we are then show that bit of text, and finally, if it is neither Category A or B, then show this default text. 这执行以下的操作。查看我们是否正在查找类别A,如果我们是在查找,那么显示一点文本,但是如果我们不是在查找,查看我们是否在查找类别B。如果我们是在查找,会显示一点文本,最后,如果我们不在查找类别A也不在查找类别B,那么就会显示这个默认文本。 === Text Displaying Only on First Page of Archive === === 只在归档首页显示文本=== Another thing that can happen is that if your Category contains more posts than will fit on one page (according to the Options for Blog Reading you have set in the Administration panels of your blog), the category archive will split into multiple pages. And maybe you only want to display your static text if the viewer is on the first page of results, or you want to display different text for the other pages. 另一种可能发生的情况是,如果你的类别包含了太多的的文章,一个网页上放不下(根据你在博客管理面板上设置的博客阅读选项),类别归档就会分为几个网页。而且如果访客在结果的首页上,你可能只想显示静态文本,或者你想要为其它的网页显示不同的文本。 To make this happen, you can use a PHP <tt>if</tt> statement, which looks at the value of the <tt>$paged</tt> WordPress variable (<tt>$paged</tt> is equal to the page number: 1 for the first page of results, 2 for the second page, etc.). It may sound complicated, but it's actually not too bad. Just put the following above [[WordPress:The Loop]]: 如果你希望上述情况发生,你可以使用一个PHP<tt>如果</tt>声明,查看<tt>$paged</tt>WordPress变数的参数值(<tt>$paged</tt>与网页数字相同:1代表结果的第一个网页,2代表第二个网页,等等)。这听起来很复杂,但是事实上并不太难。只要将下面的内容,放在[[WordPress:The Loop|The Loop]]的上面,即可: <pre> <?php if ( $paged < 2 ) { ?> <p>Text for first page of Category archive.</p> <?php } else { ?> <p>Text for subsequent pages of Category. Can be left out.</p> <?php } ?> </pre> <pre> <?php if ( $paged < 2 ) { ?> <p>类别归档的第一个网页的文本。</p> <?php } else { ?> <p>类别的下一个网页的文本。 可以不填。</p> <?php } ?> </pre> === Category Name === === 类别名 === Another possibility is to put the category name at the top of the page. If this is not already part of your template, you can add it by doing something like this, above [[WordPress:The Loop]]: 另一种可能性是将类别名放在网页的顶端。如果这还不是你的模板的一部分,你可以添加,通过在[[WordPress:The Loop|The Loop]]上执行: <pre> <p>Category: <?php single_cat_title(); ?></p> </pre> <pre> <p>Category: <?php single_cat_title(); ?></p> </pre>
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)