Host Unlimited Web Sites for Only $10 per Month! 主機無限網站的只有10元每月!
Powered by MaxBlogPress 本站由MaxBlogPress

WordPress的哈克# 2 :如何創建一個主存檔索引頁| JTPRATT的博客錯誤
JTPratt的博客錯誤





Home首頁 » Wordpress Hack #2: How To Create A Master Archive Index Page » WordPress的哈克# 2 :如何創建一個主存檔索引頁



Posted in: 張貼於:

博客安裝類形象WordPress的圖像類
1,603 views 1603意見


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 “哈克一通! ” 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.一定要註冊的簡易信息聚合飼料或訂閱通過電子郵件在頁面頂部。

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站點地圖搜尋搜尋器) ,所以真的沒有辦法獲得鳥類鳥瞰我的所有內容。 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個職位,時間與上次'和'未來'底部的鏈接的網頁。 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).如果您新增的前5線以下的最重要的是文件,其餘的代碼在“循環”的網頁(後標頭和前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> 

例如網頁模板 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).你可以看到在這個例子什麼你是一個上市的檔案的一個月,也按主題(類) 。 This really sucks doesn’t it!?這確實吸收它沒有! 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.我已經有了最看待前10名在我的側欄。 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 /> 

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" /> 

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.本人刪除了原始代碼我還在本月初黑客教程獲得檔案的一個月或主題有利於合檔案館檔案排序代碼。 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:標籤: , , ,

4 Responses to “Wordpress Hack #2: How To Create A Master Archive Index Page”第4響應“ WordPress的哈克# 2 :如何創建碩士存檔索引頁”

  1. fdas Has the following to say... fdas有下列說...

    most awful blogging mistake: automatic translation.最可怕的博客錯誤:自動翻譯。 it really SUCKS BIG TIME.真的吸收重大時刻。 I want to read your blog in english, idiot.我想讀您的博客的英文,白痴。

  2. admin 管理員 Has the following to say...有下列說...

    @fdas - I don’t use or have automatic translation on this blog - you have to click one of the translation icons to get a translated page. @ fdas -我不使用或擁有自動翻譯此博客-你必須按一下其中一個翻譯圖標獲得翻譯網頁。 Every single page is available by default in English.每一個單頁可默認為英文。

    The idiot is the person that leaves a blog comment like this and uses random characters and a fake email address (you) so I can’t contact you and get to root of the issue you were having, and fix it for others if there was one.在白痴的人,留下了博客這樣評論,並使用隨機字符和一個虛假的電子郵件地址(你) ,所以我不能與您聯繫,並獲得根本的問題是你有,並修正為他人是否有1 。

  3. DrBrian DrBrian Has the following to say...有下列說...

    Thanks for the info.謝謝您的信息。 After staring at the codex for an hour wondering why I didn’t have a “templates” box on my Write >> Page, I figured out that the 5 lines of code I ripped away from the top of the archives.php was the problem.經過盯著抄本一個小時不知道為什麼我沒有“模板”框中我的收件“ ”頁中,我想出的第5行的代碼我離爆炸上方的archives.php是問題。 = )研究

    For the record, page displays in perfect English for me and I can only figure that the other jerk followed a link from another site or something.為了記錄在案,頁面顯示在完美的英語對我和我只能數字,其他成績後,從另一個鏈接網站或東西。

    DrBrians last blog post.. DrBrians最後的博客帖子.. Pardon the Dust…對不起粉塵...

  4. Kim Has the following to say...有下列說...

    Thanks for all your work; I am addicted.感謝您的所有工作;我上癮。 Can’t believe that guy could see all your work then gripe at you.不能相信這個傢伙可以看到所有的工作然後抱住你。

    Kims last blog post..金最後的博客帖子.. Google Insights Tool谷歌的見解工具

Question or Comment??問題或意見? ? Spill it Now...溢油現在...

跳躍的喜悅以上的評論!

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!頂端commenters每個月列出的每個網頁上本網站的聯繫欄部件回到您的網址! 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!您的評論是有價值的,不僅給我們,而且所有的其他讀者的博客!


Click to add smilies to your post! 按一下以新增的笑臉到您的帖子! == [ ]^ = (= ( (= ( |= )研究= | 8= 0= ) 〜= 00= (= ; ;= ) ]= ; ; ;