Wordpress Hack #2: How To Create A Master Archive Index Page在WordPress哈克# 2 :如何创建一个主存档索引页
508 views - 508的意见-作Posted in: 张贴在:
508 views 508的意见
Please note: This page was originally written in English.请注意:此页中,原本以英文书写。
The original post can be viewed原来的文章可以看 here这里 . 。
Please note: This page was originally written in English.
The text has been translated using an online service such as Google or Babelfish.
The original post can be viewed here.
In your Wordpress blog do you have a sortable clean and easy way for visitors to access your previous posts? 在您的WordPress所博客你是否有排序的清洁及简单的方式可以让游客来存取您以前的职位? Other than the month based archive link in your sidebar, you may not have an archive index at all! 其他较一个月基于存档链接在您的工具栏,您可能没有存档索引在所有! It’s time you hacked your own Master Archive Index Page! 它的时间,你砍死自己的硕士存档索引页!
This is Wordpress Hack #2 in our 30 “Hack-a-Thon”!这是在WordPress哈克# 2 ,在我们的30名“黑客一来到Thon ” ! That’s right, I’m going to give you one说的权利,我要去给你一 Wordpress hack per day for 30 days 在WordPress哈克每天为30天 , and at the end of that time you will have pimped out your blog like you never would have believed possible! ,并在去年底,当时您将有pimped出您的博客一样,你绝对不会相信可能! Be sure to signup for the RSS feed or subscribe by email at the top of the page.一定要注册为RSS馈送,或订阅通过电子邮件在网页上方。
Out of the box the default Archives for Wordpress aren’t very sexy.出于对票房的预设档案的WordPress是不是很性感。 In fact, as I’ve mentioned in previous posts the word thing about Wordpress (to me) is the fact that the content seems hard to navigate, hard to get to, and downright self-defeating at times.事实上,正如我已经提到,在以往的职位,这个词的事情在WordPress (我)是事实的内容,似乎很难浏览,很难找到,并且简直是弄巧成拙,在倍。 Let’s take this blog as it stands right now as an example.让我们借这个博客,因为它主张的权利,现在作为一个例子。 The homepage has one full post and 9 excerpted posts.该网页有一个充分邮政和9摘录的职位。 The sidebar contains links to the last 10 posts, and most viewed posts, in addition to a link to categories and monthly archives.工具栏包含链接,到最后10个职位,最多人看的职位,另外还有一个连结到类别及每月档案。 I can also search, and those are my basic options for finding content.我也可以搜索,这些都是我的基本选择,寻找内容。 The custom pages I’ve setup also lead to some article series and categorized content.自定义的页面我已经安装,也导致一些文章系列和分类的内容。 I currently don’t have an HTML web page site map (just an XML sitemap for search crawlers), so there really is no way to get a birds eye view of all my content.我现在没有一个HTML网页网站地图(只是一个XML格式的Sitemap对于搜索的抓取工具) ,所以实在是没有办法得到鸟类俯瞰我的所有内容。 I’m rapidly approaching 100 posts, but at any give time you’re lucky to have more than 10-15 options for content as you surf around my blog.我迅速接近100个职位,但在任何时间,让你很幸运能有更多的选择,比10月15日为内容正如你冲浪靠近我的博客。
Your theme may or may not currently display any more than month based archive pages, which will just be links in your sidebar to the months of the year you had posts.您的主题可能会或不会显示,目前任何超过一个月基于存档页,这将只是链接在您的工具栏,以几个月的一年,你的职位。 Some themes also have a calendar.一些主题,也有一个日历。 All these normally do is use your “archive.php” in your theme directory as a template to bring up a list of posts the same way you index, search, category, or tag pages do - a list of up 10 to posts at a time with ‘previous’ and ‘next’ links at the bottom of the page.所有这些通常是使用您的“ archive.php ”在你的主题目录为模板,带来了一个清单的职位相同的方式,索引,搜寻,分类或标签上的页面做的-的名单了1 0个职位1时间与'前'和'下一个'底部的链接的网页。 In my experience, most themes don’t have a master archive page (or what the在我的经验,大部分的主题,没有一个硕士存档页(或什么 Wordpress Codex calls the “Archive Index”在WordPress食品法典委员会呼吁“存档索引” , although some have a “archives.php” file to create one from. ,虽然有些人有一个“ archives.php ”文件,以建立一个从。 Notice that this template file has an “s” on archives.php.请注意,此模板文件有一个“ S ”型对archives.php 。 Look in your theme directory, and you should have a file named “archives.php”.看看在您的主题目录,你应该有一个文件名为“ archives.php ” 。 If you do add the first 5 lines below at the very top of that file, and the rest of the code in “the loop” of that page (after the header and before the endwhile).如果您添加第一线,下面五在非常最重要的是文件,代码的其余部分在“循环”该网页(后页眉和前endwhile ) 。 If for some reason your theme doesn’t have an archives.php, just download a copy of your “page.php” file, rename and save it as “archives.php” and then add these code to it (then upload to your theme directory).如果由于某种原因,您的主题没有一个archives.php ,只需下载一份贵“ page.php ”文件,重新命名并保存为“ archives.php ” ,然后添加这些代码,它(然后上传到您的主题目录) 。
<?php /* Template Name: Master Archives Page */ ?> <h2>Archives by Month:</h2> <ul> <?php wp_get_archives('type=monthly'); ?> </ul> <br /> <h2>Archives by Subject:</h2> <ul> <?php wp_list_cats(); ?> </ul> < ? PHP中/ *模板名称:掌握档案页* / ? > <h2>快来档案月份: < /氢气> <ul> < ? PHP的wp_get_archives ( '类型=每月' ) ; ? > < / UL认证> <溴/ > <h2>快来档案主题: < /氢气> <ul> < ? PHP的wp_list_cats ( ) ; ? > < / UL认证>
Make sure you have the “Template Name” in the top.请确定您拥有“模板名称”在顶端。 Now upload this file to your theme directory, and in your Wordpress dashboard go to “Write -> Page”.现在上传此文件到您的主题目录,并在您的WordPress仪表板转到“收件-> ”页“ 。 On the right hand side you’ll see “page template” as in the image example here.在右手边,您会看到“网页模板”在形象,例如在这里。 Just select “Master Archives Page”.只要选择“师父档案的一页” 。 I’m going to call mine “Archived Posts Sitemap”.我要呼吁地雷“存档帖子网站” 。 I like that title because it says it’s an archive page with a sitemap.我喜欢这一标题,因为它说,这是一个存档网页与网站。 To me a sitemap is a great big categorized page of titles and links where you can get a the big picture of a site pretty quickly.在我看来,网站是一个伟大的大分类页的标题和链接,您可以在获得大画面的一个网站相当迅速。 That’s the impression I want to give people, unlike the monthly archive pages that just list posts and excerpts.这是给我的印象要给人的不同,每月存档网页刚刚名单员额和摘录。 The first time creating this page I’m not going to give it much content - just some introductory content.第一时间创造这个网页我不打算给它的内容-只是一些介绍性的内容。 Save this page and then reload your site in another tab or window.保存该网页,然后重新加载您的网站在另一个标签,或窗口。 You should see the name of this new page in your “Pages” in your sidebar.您应该看到的名称,这个新的一页,在您的“页”在您的工具栏。 Click on it to bring it up and you should have something like this:点击它,把它和你应该有一些是这样的:

You see in that example what you get is a listing of archives by month, and also by subject (category).你看到在这方面的例子您得到什么是一个上市的档案一个月,而且也受到( A类) 。 This really sucks doesn’t it!?这真是sucks为不! ? I mean come on, everyone already has both of these already in their sidebar - I do!我的意思来吧,大家都已经有这两项已经在其工具栏-我! There are basically two different ways to solve this problem, and actually these solutions can be combined.有基本上有两种不同的方法来解决这个问题,其实这些解决方案可以结合起来。 The first thing we can do is get a Wordpress plugin for archives to get more options on this page.第一件事,我们能做的就是获得wordpress插件档案,以获得更多的选择在此页中。 The second is to do a little hackng and add some code to the page to get the information out of the database we need to make sure visitor’s get all the options they need.二是做一些hackng ,并添加一些代码到网页上获得资讯的资料库我们需要确保访客的获得的所有选项他们的需要。
After reviewing my options - these are my thoughts…经检讨我的选择-这些都是我的想法…
I “could” use yesterday’s我“可以”利用昨天的 query_posts hack query_posts哈克 to list every post I have on the page - but that wouldn’t be very nice visually at all.要列出所有的职位我已在网页上-但不会很好的视觉在所有。 I think it would be great to give visitor’s most “most viewed” or “most popular” posts on this page.我认为这将是伟大,让访客的最“最多人看的”或“最热门”职位,在此页中。 I already have the most viewed top 10 in my sidebar.我已经有最多人看的十大在我的工具栏。 I use the我用 Lester Chan Plugin WP-PostViews莱斯特陈插件可湿性粉剂- postviews to get this.要获得此。 It will display the most viewed posts, or most viewed posts for a category.它将显示最多人看的职位,或最多人看的员额为一类。 I’m going to use it to display the top 25 most viewed posts.我会用它来显示排名前25的最多人看的职位。 That’s more than I have in my sidebar and should be very useful to visitor’s.说的比我更已在我的工具栏,并应是非常有益的访客的。 According to the根据该 WP_PostViews documentation wp_postviews文件 all I need to do is add this code “outside the loop” of my archives.php to add this to my Master Archives Index Page (since I already ahve WP_PostViews installed as a plugin in my Wordpress installation):我需要做的就是添加此代码“外循环”我的archives.php将此添加到我的掌握档案索引页(因为我已经有wp_postviews安装作为一个插件在我的WordPress安装) :
<h2>Top 25 Most Viewed Posts</h2> <?php if (function_exists('get_most_viewed')): ?> <?php get_most_viewed('both', 25) ?> <?php endif; ?> <br /><br /> <h2>快来前25位最多人看的职位, < /氢气> < ? PHP的,如果( function_exists ( ' get_most_viewed ' ) ) : ? > < ? PHP的get_most_viewed ( '都' , 25 ) ? > < ? PHP的endif ; ? > <溴/ > <br /> Since you have to use that code outside the loop, and I have a page heading just inside the loop on my archives.php, I decided to place this after the loop in my Master Archives Index page.既然你使用该程式码外循环,我有一个网页的标题,只是内环路对我的archives.php ,我决定把这个后回路在我的掌握档案索引页。 Another way to do this you might care for is by using the另一种方法,这样做你可能照顾是使用 using the Top Post plugin使用顶端后插件 by JohnTP to display the top post by category like he does on由johntp显示顶端后按类别一样,他对 his top posts page他的高层职位页 . 。 I decided to stick with what I have so far.我决定要坚持与我有这么远。
Doing a little more research I found two very similar Wordpress Archiving Plugins,做多一点研究,我发现两个非常相似的WordPress归档插件, SRG Clean Archives隶属SRG清洁档案 , and , Smart Archives智能档案 . 。 They basically do the same thing, just formatted a little differently.他们基本上做同样的事情,只是格式化有点不同。
Here’sa clean archives example where you’ll see that you get monthly archives with linked titles and post counts.以下是干净的档案为例,在这里您可以看到您获得每月档案与联系的标题,并张贴计数。 It also shows the day posted before and comment count after each linked title.它也显示了天前,张贴和评论计数后,每个联系的标题。

In the Smart Archives plugin example you’ll see an addition of a linked calendar above the posts by year and month.在智能式档案插件,例如,您就会看到一个,除了一个联系日历以上的职位由年份和月份。 The posts are also listed by month.职位,还列出了由一个月。 With this plugin you don’t get date posted or comment count.与此插件您没有获得张贴日期或评论。

In the end I wanted to go with something I thought was not only a bit more cool, but much more user-friedly.在年底我要到的东西,我以为不仅是较为凉爽,但仍有更多的用户friedly 。 I really wanted to use我真的想用 Exended Live Archive exended生活馆 because of the interface, but it’s not compatible with Wordpress 2.3+ at all.因为界面,但它的不兼容的WordPress 2.3 +所有。
In the end I went with在年底我去与 KG Archives公斤档案 for my Master Archives Index page because it has a handy drop down at the top where visitor’s can quickly choose to see one month or all months quickly of archived posts.我的硕士档案索引页,因为它有一个方便的下拉在顶部的地方访客的可以快速选择,看看一个月或全部个月内迅速存档的职位。 In addition this post lists the date posted and comment count for each as well.此外,这个职位列出张贴日期和评论计数为每个以及。

To place the KG Archives content on your Master Archive Index Page you just have to copy and paste the following code - but this time go back and “edit” your actual “page” in “Manage->Pages” where you wrote the intro content, and paste this beneath (in code view):把公斤的档案内容,在您的主存档索引页你一定要复制并粘贴以下代码-但这个时候回去的“编辑”您的实际“页”在“管理” - >页面“,而你写的内容简介,并粘贴此下方(在代码视图中) :
<kgarchives initialmonth="current" /> <kgarchives initialmonth="current" /> I removed the original code I added at the beginning of this hack tutorial to get archives by month or subject in favor of the KG Archives sortable archive code. i取消了原来的代码我已将在本月初哈克补习获得档案的一个月,或受有利于该公斤档案馆排序存档代码。 Based on all the options I presented to you in this post - you must decide which of all the layouts and plugins you like best for your archives index page.基于对所有可供选择的我向你在这个职位-您必须决定哪个所有的布局和插件您最喜欢您的档案索引页。 View my new检视我的新 Archived Posts Sitemap page here存档帖子网站的网页在这里 ! !
There are many other options in the readme file if you download this plugin, I chose to only display the current month at first.还有很多其他的选项在自述文件如果您下载此插件,我选择只显示当前每月第一。 Now I have a Master Archive Index Page where users can navigate all my past posts quickly and easily.现在我有一个硕士存档索引页,用户可以在浏览我所有的过去职位快速,轻松地。 They can even see all posts on one page if they choose.他们甚至可以看到所有的职位在同一页上,如果他们选择。 I’ve also listed my most popular posts.我也列出我最热门的职位。 If I keep adding pages, I may also expand my Archive Index to include a listing of all my parent and child pages at the very bottom.如果我不断加入的页面,我也可以扩大我的档案索引,包括一个上市我所有的父母与子女的页面在非常的底部。 Create your own archive index now!创建自己的存档索引现在! I gave you plenty of options, and as always if you have something to add or a question - please comment now!我给你充裕的选择空间,而且,与往常一样,如果你有一些新增或一个问题-请评论!
Tags:标签: archives档案 , , plugin插件 , , tutorial补习 , , wordpress-hacks在WordPress -骇客




















We Reward Comments!我们悬赏的评论!
We dofollow links, and get your latest blog post as a byline under every new comment from the "CommentLuv" plugin!我们dofollow联系,并获得最新的博客帖子作为一个署名下,每一个新的评论从“ commentluv ”插件! Top commenters for every month are listed on every page of this site in a sidebar widget linked back to your URL!顶端提意见,每一个月中列出的每一页上这个网站,在工具栏的小装置相连回到您的网址! We would like to reward you for becoming part of our community!我们想奖励你的一部分,成为我们的社会! Your comment is valuable not only to us, but also all the other readers of this blog!您的评论是有价值的,不仅给我们,而且所有其他的读者,这博客!