WordPress 中文文档
Separating Categories
出自WordPress Chinese 中文文档
目录 |
Your posts are filed in different categories. Category information is freqently displayed in the post meta data section near your post or under the heading title. Different WordPress Themes highlight the post meta data section in different areas.
The display of the post categories is generated through the use of the ttthe_category()/tt template tag. And you have the ability to style how these categories are displayed.
Finding Your Categories Tag
The placement of your categories tag may be in one place on the front page and in one or more different places in your single post page, so you may have to do some hunting to find your various categories tags. You might also want to style one differently from the others, but you still have to find them.
The post meta data featuring your categories tag in your Theme is usually found on the ttindex.php/tt, ttsingle.php/tt, or sometimes in the ttsidebar.php/tt template files. Open one or more of these template files and search for:
pre?php the_category() ?/pre
Once you have found it, take another look at a generated web page of your site and determine how exactly you might want to change this information.
The ttthe_category()/tt template tag instructs the database to get the information regarding the post categories and display it at that point in your template file. By default, it displays the list of categories with a space between each one. You can change this by adding the parameter inside of the tag. Let's begin with simple separators by playing with the category names: WordPress, Computers, and Internet News.
Simple Separators
If you would like to have commas between the categories, the tag should read:
pre?php the_category(',') ?/pre
And it would look like this:
div style=font-size: 105%; color: blue; font-weight:bold; margin:20px; padding: 20px; border:solid 1px blueWordPress, Computers, Internet News/div
If you would like to have an arrow, the tag would look like this:
pre?php the_category(' ') ?/pre
div style=font-size: 105%; color: blue; font-weight:bold; margin:20px; padding: 20px; border:solid 1px blueWordPress Computers Internet News/div
If you would like to have a bullet, the tag would look like this:
pre?php the_category(' amp;bull; ') ?/pre
div style=font-size: 105%; color: blue; font-weight:bold; margin:20px; padding: 20px; border:solid 1px blueWordPress bull; Computers bull; Internet News/div
If you would like the pipe ( | ) between the categories, the tag would look like this:
pre?php the_category(' | ') ?/pre
div style=font-size: 105%; color: blue; font-weight:bold; margin:20px; padding: 20px; border:solid 1px blueWordPress | Computers | Internet News/div
Adding Text to Your Categories
Would you like to make your post meta data look a little more textual, informal and part of a paragraph rather than a list. You can add an and to go between the categories like this:
prepYou can read related subjects in the ?php the_category(' and ') ? categories./p/pre
div style=font-size: 105%; font-weight:bold; margin:20px; padding: 20px; border:solid 1px blueYou can read related subjects in the span style=color:blueWordPress/span and span style=color:blueComputers/span and span style=color:blueInternet News/span categories./div
Or you can give them more of a choice and change the and to an or:
div style=font-size: 105%; font-weight:bold; margin:20px; padding: 20px; border:solid 1px blueYou can read related subjects in the span style=color:blueWordPress/span or span style=color:blueComputers/span or span style=color:blueInternet News/span categories./div
The possibilities are endless. Have fun and use your imagination!

