站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
▼
建站程序
开发
服务器
办公软件
开发教程
▼
服务器教程
软件使用教程
运营教程
热门电子书
▼
CSS教程
WordPress教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
热点词条
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
WordPress:Creating an Archive Index
”
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
Xxf3325
(
讨论
|
贡献
)
2008年6月2日 (一) 14:14的版本
(新页面: == Introduction == So you want a single page with links to all your archived entries, arranged <em>just so</em> to form the main gateway into your blog's past. With the WordPress 1.5 the...)
(差异) ←上一版本 |
最后版本
(
差异
) |
下一版本→
(
差异
)
跳转至:
导航
、
搜索
警告:您正在编辑的是本页面的旧版本。
如果您发布该更改,该版本后的所有更改都会丢失。
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
== Introduction == So you want a single page with links to all your archived entries, arranged <em>just so</em> to form the main gateway into your blog's past. With the WordPress 1.5 theme system, you can create template files to customize this archive gateway for each theme you use. Or, maybe you're just wondering how to use the <tt>archives.php</tt> template file that's included with the WordPress Default Theme. This article describes both those things. The method outlined here can also be used to make other specialized pages that are integrated with the WordPress theme system: a links page, site index, or anything else your heart desires. == Creating the Archive Index Template and Page == To set up a separate archive index in a way that plays with the Version 1.5 theme system, you'll need to create it as a [[WordPress:Pages | Page]], and assign it a special template. === The Template (archives.php) === Start off with a simple template called <tt>archives.php</tt>, stored in your theme's directory. The WordPress Default Theme includes such a template, and it makes a good starting point. Technically, the template can be called almost anything (see [[WordPress:Theme Development#Theme Templates|these two lists]] for names you should ''not'' use; these are special file names WordPress reserves for specific purposes). However, using a standard name for your template will make it easier to change your blog's theme or distribute your theme and template to the WordPress community. It's also possible to display a large archive index using one of the all-purpose templates (like index.php or category.php) and the [[WordPress:Conditional_Tags|is_page]] function, but again, taking advantage of the theme system's modularity makes it easier for others (and for you!) to edit your template later. For more information on creating templates, see [[WordPress:Template_Tags|Template Tags]], particularly [[WordPress:Template_Tags/wp_get_archives | wp_get_archives]]. === The Archives Page === ==== for WP 1.5 ==== Upload the archives.php in your theme directory (<tt>wp-content/themes/themename/</tt>). Then from the Admin Panel, [[WordPress:Pages#Creating_Pages|'''Write > Write Page''']], and choose '''Add a New Page''': # Give your new archives Page a suitable title like ''Archive Index''. Leave the Page content blank. # Under '''Custom Fields''', select '''_wp_page_template''' from the dropdown. Leave the Key field blank, and enter '''archives.php''' into the '''Value''' field. # Click '''Add Custom Field'''. # Voila! Your archive index can be accessed at <tt><nowiki>http://example.com/index.php?pagename=archive-index</nowiki></tt>. ==== for WP 1.5+ ==== Upload the archives.php in your theme directory (<tt>wp-content/themes/themename/</tt>). Then from the Admin Panel, [[WordPress:Pages#Creating_Pages|'''Write > Write Page''']] # Give your new archives Page a suitable title like ''Archive Index''. Leave the Page content blank. In the sidebar open the //Page templates// box, and select the //Archives// template. After saving it you will see a new item in your pages list, click on it, and enjoy! == Customizing Your Archives == There are a variety of techniques to customize your Archive Index page. Some involve incorporation of plugins or PHP code to create customized lists of archived posts, and others provide more interesting ways of displaying your archives. === List Archives By Year === You can set your archives up to be displayed by the year, such as: <div style="border:1px solid blue; width:40%; font-weight:110%; margin: 20px; padding:20px"> <span style="font-weight:bold;font-size:120%">Archives</span> <ul style="color:blue"> <li><u>2007</u></li> <li><u>2006</u></li> <li><u>2005</u></li> <li><u>2004</u></li> </ul> </div> To list your archives by year instead of by month, use the following code, in which a query to the database is made to collect and sort the posts by year, then display them as links with the [[WordPress:Template_Tags/get_year_link|get_year_link()]] template tag: <pre><ul><li><h2>Archives</h2> <ul> <?php $years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date DESC"); foreach($years as $year) : ?> <li><a href="<?php echo get_year_link($year); ?> "><?php echo $year; ?></a></li> <?php endforeach; ?> </ul> </li></ul></pre> For versions of WordPress before 2.1, use this for your '''$years''' query: <pre>$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date DESC");</pre> == Setting Up Redirects == If you're using [[WordPress:Using_Permalinks|Permalinks]], WordPress will generate a new set of [[WordPress:Pages#Creating_Pages|rewrite rules for your new Page]]. You may need to update your <tt>.htaccess</tt> file by hand, if WordPress is unable to do so automatically. See [[WordPress:Using_Permalinks|Using Permalinks]] for more information. These automatic rules are based on your Page title or "slug": If your Page is named Archive Index, you'll be able to see it at <tt><nowiki>http://example.net/your-wordpress-dir/archive-index/</nowiki></tt>. === Problems with Auto-generated .htaccess Files === If your archive index Page has a slug that's the same as part of your permalink structure - e.g., your Page is named Archives, and your permalinks are set up as <tt>/archives/%post-id%/</tt> or <tt>/archives/%year%/%monthnum%/%day%/%postname%/</tt> - WordPress will create conflicting rewrite rules. This can cause your monthly/category archives to be displayed using your archive index template. There are two ways to avoid this problem: # Use a different name for your archive index Page # Don't allow WordPress to automatically manage your .htaccess file. == Further Reading == === Useful Plugins === * [http://blindmuse.com/blog/2004/03/31/group-archives-by-year/ Group Archives By Year] * [http://www.engadgeted.net/archives/2005/02/10/wordpress-heat-map-plugin/ WordPress Heat Map] - Display your archive links with varying sizes or colors, depending on how many posts they contain. * [http://www.davidsaccess.com/?p=124 DC's Nicer Archives] - Create a list of archives that can be expanded from a bulleted list to a series of excerpts. * [[WordPress:http://www.wordpress.org/extend/plugins|WordPress Plugins]] - for more possibilites. === WordPress Support Forum Threads === * [http://wordpress.org/support/topic.php?id=18934 How to Use Archives.php of Ryan's Kubric Theme] * [http://wordpress.org/support/topic.php?id=24290 Year Archive Pulling Up Archives.php Page] === Interesting Examples of Archive Indexes === * [http://www.hitormiss.org/archives/ Hit or Miss] - Flickr-style weighted categories and keywords. * [http://www.engadgeted.net/archives/ Engadgeted] - The Heat Map plugin in action.
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)