站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
▼
建站程序
开发
服务器
办公软件
开发教程
▼
服务器教程
软件使用教程
运营教程
热门电子书
▼
CSS教程
WordPress教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
热点词条
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
WordPress:Tag Templates
”(章节)
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
跳转至:
导航
、
搜索
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
= 例子 = Now that you've figured out which template file in your theme's directory you need to modify, in order to make changes to the look of Category pages, let's look at some examples. In these examples, when it says "edit your template file", it means to edit the file you chose in the section above. 既然现在你已经了解需要更改你的主题目录中的哪个模板文件,为了更改类别页面的外观,让我们看看一些例子。在这些例子中,当显示"编辑你的模板文件"的时候,意思是编辑你从上面的部分中选择的文件。 == Adding Text to Category Pages == == 将文本添加到类别页面== === 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,如果我们是在查找类别A,我们会显示一些文本,如果我们不是在查找类别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>if</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 }其它的{ ?> <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]]: <pre> <p>Category: <?php single_cat_title(); ?></p> </pre> 另一种情况是将类别名放到页面的顶上方。如果这还不是你的模板的一部分,你可以在[[WordPress:The Loop|The Loop]]上执行这个操作,将这个部分添加到你的模板上: <pre> <p>类别: <?php single_cat_title(); ?></p> </pre> == Modifying How Posts are Displayed == == 更改文章的显示方式 == === Excerpts vs. Full Posts === === 摘录 vs. 完整的文章 === Perhaps you are looking to cut down on the size of your Category pages. You could do this by displaying excerpts rather than the entire content of each Post. To do this, you will just need to find where it says <tt style="font-weight:bold; color:#036">[[WordPress:Template Tags/the_content|the_content()]]</tt> inside [[WordPress:The Loop]] in your Template, and replace it with <tt style="font-weight:bold; color:#036">[[WordPress:Template Tags/the_excerpt|the_excerpt()]]</tt>. These will most likely be inside PHP tags: <pre> <?php the_excerpt(); ?> and <?php the_content(); ?> </pre> 也许你想要更改你的类别页面的大小。显示摘录而不是每篇文章的整个内容,你就可以做到这一点。你只要在你的模板的[[WordPress:The Loop|The Loop]]内找到显示为<tt style="font-weight:bold; color:#036">[[WordPress:Template Tags/the_content|the_content()]]</tt>的位置,并将其更改为<tt style="font-weight:bold; color:#036">[[WordPress:Template Tags/the_excerpt|the_excerpt()]]</tt>,即可。这些很有可能在PHP标签的内部: <pre> <?php the_excerpt(); ?> 和 <?php the_content(); ?> </pre> Conversely, if your Theme is currently displaying excerpts and you want full posts, replace <tt>the_exerpt</tt> with <tt>the_content</tt>. 与此相反,如果你的主题当前显示摘录,但是你想要显示完整的文章,将<tt>the_exerpt</tt>替换为<tt>the_content</tt>。 === Display Images Linking to Full Posts === === 显示图像链接到完整的文章=== Another thing that is interesting to do in a category archive page is to replace the post content with an image that links to your post. To do this, you will first need to put images into the Excerpt sections of your posts. Here's how to do that, for one post: 处理类别归档页面的另一个有趣的操作是使用链接到你的文章的图像代替文章内容。你首先要将图像放置到你的文章的摘录部分。下面是怎样将图像放到一篇文章的摘录部分: # Upload an image on the post editing screen. # Switch to the "Code" editor, rather than the "Visual" editor. # Use the Uploads / Browse tab to insert the image into your post. Make sure to insert the full-sized image, with no link. # Copy the inserted HTML <tt>img</tt> tag, and paste it into the "Optional Excerpt" section of the post editing screen. # Finish writing the post content (you can remove the image), and publish the post. #将一个图像上传到文章编辑界面。 #切换到"Code"编辑器,而不是"Visual"编辑器。 #使用上传/浏览标签将图像插入到你的文章。确定插入了完整大小的图像,没有链接。 #复制已插入的HTML<tt>img</tt>标签,并且将标签粘贴到文章编辑界面的"可选择的摘录" 部分。 #结束编写文章内容(你可以移除图像),并且发表文章。 Now you will need to modify your template. We'll use a trick: the [[WordPress:Template Tags/the_excerpt_rss|the_excerpt_rss()]] Template Tag does not put a paragraph tag around the excerpt. So we can use it to insert the <tt>img</tt> HTML and put it inside a link. Here's what you need to put into your Template, in place of using <tt>the_content</tt>: 现在你需要更改你的模板。我们会使用一种方法:[[WordPress:Template Tags/the_excerpt_rss|the_excerpt_rss()]]。模板标签没有将段落标签放置在摘录周围。因为我们使用模板标签插入<tt>img</tt> HTML并且将其放入链接内容。下面是我们需要放入模板中,取代<tt>the_content</tt>的内容: <pre> <a href="<?php the_permalink() ?>"> <?php the_excerpt_rss(); ?> </a> </pre> <pre> <a href="<?php the_permalink() ?>"> <?php the_excerpt_rss(); ?> </a> </pre> Caveat: using the excerpt this way '''may''' effect your RSS feed, because it places an img tag in the excerpt, instead of text. So if you are going to do this, you probably want to set your options so that the full posts are put in RSS feeds, rather than excerpts. 告诫:以这种方式处理摘录'''可能'''影响你的RSS feed,因为将img标签放入摘录而不是文本中。因此,如果你准备执行这个操作,你可能想要设置你的选项,这样完整的文章而不是摘录就会放入RSS feeds。 === What categories do you show to the visitors? === ===你想要向访客显示什么类别? === You can limit the categories in archive and other pages with this code: 你可以使用这个代码在归档和其它页面中限制类别: <pre> <?php query_posts('cat=1&showposts='.get_option('posts_per_page')); ?> </pre> <pre> <?php query_posts('cat=1&showposts='.get_option('posts_per_page')); ?> </pre> This is placed before the Loop. 这个代码放置在Loop之前。 You find more info about the query_posts() function parameters here: http://codex.wordpress.org/User:JamesVL/query_posts . 你可以在这个网站找到更多的有关query_posts()函数参数的信息:http://codex.wordpress.org/User:JamesVL/query_posts 。 The <tt>get_option('posts_per_page')</tt> part of the code uses your blog's options to show a limited number of posts. 代码的<tt>get_option('posts_per_page')</tt>部分使用你的博客选项显示有限数目的文章。 This code is very useful if you would like to separate the categories. With this code you can make multiple archives. For example: 如果你想要分开类别,这个代码非常有用。使用这个代码,你可以创建多个归档。例如: <pre> <?php if (have_posts()) : ?> <?php if (is_month()) {query_posts('year='.get_the_time('Y').'&monthnum='.get_the_time('m').'&author_name=admin&cat=1&showposts='.get_option('posts_per_page')); ?> <!-- Do stuff... -> <?php } ?> <?php while (have_posts()) : the_post(); ?> <!-- post's contents --> <?php endwhile; ?> <?php endif; ?> </pre> <pre> <?php if (have_posts()) : ?> <?php if (is_month()) {query_posts('year='.get_the_time('Y').'&monthnum='.get_the_time('m').'&author_name=admin&cat=1&showposts='.get_option('posts_per_page')); ?> <!-- Do stuff... -> <?php } ?> <?php while (have_posts()) : the_post(); ?> <!-- post's contents --> <?php endwhile; ?> <?php endif; ?> </pre> If you use this code in <tt>archive.php</tt> and navigate to <tt>http://yourblog.com/2008/02/</tt>, show you the <tt>admin</tt> user's post that is posted on 2008.02. in the "first" category. 如果你在<tt>archive.php</tt>中使用这个代码并且导航到<tt>http://yourblog.com/2008/02/</tt>,向你显示<tt>admin</tt>用户的文章,在2008.02发表,在"第一个"类别中。
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)