久久精品水蜜桃av综合天堂,久久精品丝袜高跟鞋,精品国产肉丝袜久久,国产一区二区三区色噜噜,黑人video粗暴亚裔
站長百科 | 數(shù)字化技能提升教程 數(shù)字化時代生存寶典
首頁
數(shù)字化百科
電子書
建站程序
開發(fā)
服務(wù)器
辦公軟件
開發(fā)教程
服務(wù)器教程
軟件使用教程
運營教程
熱門電子書
WordPress教程
寶塔面板教程
CSS教程
Shopify教程
導(dǎo)航
程序頻道
推廣頻道
網(wǎng)賺頻道
人物頻道
網(wǎng)站程序
網(wǎng)頁制作
云計算
服務(wù)器
CMS
論壇
網(wǎng)店
虛擬主機
cPanel
網(wǎng)址導(dǎo)航
WIKI使用導(dǎo)航
WIKI首頁
最新資訊
網(wǎng)站程序
站長人物
頁面分類
使用幫助
編輯測試
創(chuàng)建條目
網(wǎng)站地圖
站長百科導(dǎo)航
站長百科
主機偵探
IDCtalk云說
跨境電商導(dǎo)航
WordPress啦
站長專題
網(wǎng)站推廣
網(wǎng)站程序
網(wǎng)站賺錢
虛擬主機
cPanel
網(wǎng)址導(dǎo)航專題
云計算
微博營銷
虛擬主機管理系統(tǒng)
開放平臺
WIKI程序與應(yīng)用
美國十大主機
編輯“
WordPress:The Loop in Action
”
人物百科
|
營銷百科
|
網(wǎng)賺百科
|
站長工具
|
網(wǎng)站程序
|
域名主機
|
互聯(lián)網(wǎng)公司
|
分類索引
Xxf3325
(
討論
|
貢獻
)
2008年4月22日 (二) 12:05的版本
(
差異
)
←上一版本
|
最后版本
(
差異
) |
下一版本→
(
差異
)
跳轉(zhuǎn)至:
導(dǎo)航
、?
搜索
警告:您正在編輯的是本頁面的舊版本。
如果您發(fā)布該更改,該版本后的所有更改都會丟失。
警告:
您沒有登錄。如果您做出任意編輯,您的IP地址將會公開可見。如果您
登錄
或
創(chuàng)建
一個賬戶,您的編輯將歸屬于您的用戶名,且將享受其他好處。
反垃圾檢查。
不要
加入這個!
==介紹== [[WordPress:The Loop|"The Loop"]]是指WordPress主程序中的一個術(shù)語。你可以在你的[[WordPress:Templates|模板文件]]中使用Loop來想訪問者顯示你的文章。你可以讓模板不帶有Loop,但這樣你就只能顯示來自一篇文章的數(shù)據(jù)了。 WordPress所做的第一件事就是檢查它所需要的所有文件是否存在。接下來,它按照[[WordPress:Registered_User_Features|blog 管理員]]定義的,從數(shù)據(jù)庫收集默認的設(shè)置。這包括每頁顯示的文章的數(shù)量,是否允許評論,等等。一旦這些默認的內(nèi)容確定后,WordPress就會檢查使用者要求什么。這個信息用來確定從數(shù)據(jù)庫中取出哪篇文章。s 如果使用者不要求特定的文章,分類,頁面或者日期,WordPress使用以前收集的默認值確定哪個文章準備給使用者閱讀。例如,如果blog管理員在[[WordPress:Administration_Panels|Administration]] > [[WordPress:Administration_Panels#Reading|Settings]] > [[WordPress:Settings_Reading_SubPanel|Reading]]設(shè)置中選擇每頁顯示5篇文章,那么WordPress就會從數(shù)據(jù)庫中取最新的5篇。如果使用者要求特定的文章,分類,頁面或者日期,那么WordPress就會根據(jù)這些信息來選擇從數(shù)據(jù)庫中取出哪篇''文章''。 一旦所有這些完成之后,WordPress就連接數(shù)據(jù)庫,得到需要的信息,然后在一個變量中儲存這個結(jié)果。進入這個變量的就是Loop,然后在模板中顯示變量的值。 默認情況下,如果訪問者沒有選擇特定的文章,頁面,分類或者日期,WordPress會使用<tt>index.php</tt>顯示所有內(nèi)容。在這個Loop的討論的第一部分,我們只集中討論<tt>index.php</tt>,和默認的blog顯示。接下來,一旦你懂得這些如何工作的時候,我們來研究Loop在別的模板文件中的作用。 ==世界上最簡單的索引頁面== 接下來的是具有所有功能的索引,可以顯示每個文章的內(nèi)容(僅僅是內(nèi)容),根據(jù)使用情況準備Loop,給你看這些的唯一目的就是表明這些對Loop的技能幾乎沒有必要,在你的<tt>index.php</tt>文件大多數(shù)內(nèi)容中,都是CSS, HTML,和 PHP聲明,可以讓Loop看起來漂亮些。 <pre> <?php get_header(); if (have_posts()) : while (have_posts()) : the_post(); the_content(); endwhile; endif; get_sidebar(); get_footer(); ?> </pre> ==默認 Loop== 接下來是一步一步的來看WordPress v1.5標準安裝,默認情況下,''默認'' 和 ''經(jīng)典''主題中l(wèi)oop用法。 === Loop開始=== 在默認<tt>index.php</tt>模板文件的頂部,是[[WordPress:The Loop|Loop]]代碼開始的地方。 <pre><?php if (have_posts()) : ?><br /> <?php while (have_posts()) : the_post(); ?></pre> #首先它用<tt>have_posts()</tt>功能檢查是否有新的文章. #如果有文章的話,一個PHP <tt>[http://www.php.net/while while]</tt>的loop就開始了。只要插入語為邏輯真,<tt>while</tt> loop就會繼續(xù)執(zhí)行。這樣只要函數(shù)<tt>have_posts()</tt> 返回真值,Loop就會繼續(xù)。 #函數(shù)<tt>have_posts()</tt>簡單的在文章集合中檢查下一個項目:如果有另外一個項目,返回true,如果沒有下一個項目,返回false . ===生成文章=== <tt>the_post()</tt>函數(shù)把文章集合中的現(xiàn)用的項目拿出來,并且讓它可以在Loop的循環(huán)中使用。如果沒有<tt>the_post()</tt>,很多主題中使用的[[WordPress:Template Tags|模板標簽]]都無法工作了。 一旦文章日期被設(shè)置可用,模板就能啟用對來訪者展示文章數(shù)據(jù)。 ====標題,日期和作者==== 下邊的 [[WordPress:Template Tags|模板標簽]]獲得當前文章的標題,還有發(fā)表的時間和誰發(fā)表了它。 <pre> <h2 id="post-<?php the_ID(); ?>"> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?></a></h2> <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small> </pre> ====文章內(nèi)容==== <tt>[[WordPress:Template_Tags/the_content|the_content()]]</tt>模板標簽顯示文章的內(nèi)容。 這是每個通過Loop的很重要的部分: <pre> <div class="entry"> <?php the_content('Read the rest of this entry &raquo;'); ?> </div> </pre> 如果你把'''more'''這個按鈕包含到[[WordPress:Write_Post_SubPanel#Quicktags|Quicktag]],然后象這樣<tt>[[WordPress:Customizing_the_Read_More|<!--more-->]]</tt>顯示出來, 在你的文章的正文部分,只有<em>above</em>這部分才會顯示給訪問者。這樣,如果你只是想讓你的首頁面顯示每篇文章的第一句或者前兩句話的話,只需要簡單的在每篇文章的第一行之后插入 <tt><!--more--></tt>就可以了。 當查看某個單一的文章的時候,<tt><!-- more --></tt>分隔符會被忽略。這樣如果讀者想閱讀全部內(nèi)容,而又在所有的文章中都加如<tt><!-- more --></tt>分隔符的話,會迫使讀者點擊每個單獨的文章。 ====詳細資料附==== 在每個文章內(nèi)容下邊,在<tt>index.php</tt>模板文件中,是顯示有關(guān)這個文章更多信息的地方,如分類,日期和評論信息。大家知道的[[WordPress:Post_Meta_Data_Section|文章meta數(shù)據(jù)部分]],如果你是一個已經(jīng)登陸的有充分權(quán)限的使用者,你可會看見"Edit This"連接,這多虧了<tt>[[WordPress:Template_Tags/edit_post_link|edit_post_link()]]</tt>模板標簽函數(shù)。 <pre> <p class="postmetadata"> Posted in <?php the_category(', ') ?> <strong>|</strong> <?php edit_post_link('Edit','','<strong>|</strong>'); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p> </pre> 如果評論被激活,或者是該文章有評論內(nèi)容,<tt>[[WordPress:Template_Tags/comments_popup_link|comments_popup_link()]]</tt>模板標簽將會顯示一個到評論內(nèi)容的連接。如果你使用了[[WordPress:Template_Tags/comments_popup_script|評論彈出窗口]],這個連接就會打開評論窗口,否則它就會直接跳轉(zhuǎn)到這篇文章的評論內(nèi)容。 如果訪問者在瀏覽文章索引(''i.e.:'' 在Loop中不止一篇文章),<tt>comments_popup_link()</tt>連接將會把讀者連接到這篇文章的單獨頁面。 ====自動尋找Trackback ==== <tt>[[WordPress:Template_Tags/trackback_rdf|trackback_rdf]]</tt>模板標簽的功能是輸出機讀代碼用于自動尋找[[WordPress:Glossary#Trackback|trackback]]。 <pre> <!-- <?php trackback_rdf(); ?> --> </pre> '''注意:'''<tt>trackback_rdf()</tt>標簽支持在自身旁邊使用[[WordPress:Commenting_Code|評論]]。它并非"關(guān)閉"的。 ===結(jié)束 Loop=== 下面是結(jié)束 Loop。在這之后,各種文章相關(guān)的模板標簽不再如如你想要的那樣工作了(如果它們在工作,它們會使用Loop的最后一篇文章).這意味著,如果你需要使用一個工作'''在 Loop內(nèi)'''的模板標簽,你需要把如下語句放進去。 <pre> <?php endwhile; ?> </pre> 在這個部分,在Loop結(jié)束后立即通過每個網(wǎng)頁顯示出向前還是向后的導(dǎo)航控制。 <pre> <div class="navigation"> <div class="alignleft"><?php posts_nav_link('','','&laquo; Previous Entries') ?></div> <div class="alignright"><?php posts_nav_link('','Next Entries &raquo;','') ?></div> </div> </pre> 如果blog設(shè)置成每頁顯示10篇文章,而且Loop收集到了25篇文章,這就會產(chǎn)生三個頁面:兩個10篇文章的頁面,還有一個五篇的頁面。導(dǎo)航連接允許訪問者通過文章收集跳轉(zhuǎn)到上一頁還是下一頁。 導(dǎo)航控制是<em>不包含</em>在Loop內(nèi)的,但是<em>包含在</em><tt>if</tt> 條件句內(nèi),這樣它們只能顯示是否有文章。導(dǎo)航函數(shù)本身也會檢查是否有一些基于現(xiàn)有Loop的,它們能連接的內(nèi)容,如果有可連接的內(nèi)容的話只顯示連接。 <pre> <?php else : ?> <h2 class="center">Not Found</h2> <p class="center"> <?php _e("Sorry, but you are looking for something that isn't here."); ?></p> </pre> <tt>else :</tt>語句決定了如果<tt>have_posts()</tt>返回false時做些什么。那就是說,'''else'''之后的部分只能在Loop沒有文章時才會被顯示。沒有文章顯示出來,舉例來說,訪問者要求某個特殊日子的內(nèi)容,但是那天沒有文章,或者是搜索但是沒有結(jié)果。 <pre> <?php endif; ?> </pre> 這個語句結(jié)束了這樣的條件句:"如果有文章這樣,如果沒有文章那樣".一旦條件語句結(jié)束了,默認的index.php模板包括了邊欄,最后是頁腳。 ==其它模板中的Loop== WordPress可以使用不同的模板文件,用不同的方式顯示你的blog。在默認WordPress主題中,有用于索引瀏覽的[[WordPress:Templates|模板文件]],分類瀏覽和文檔瀏覽,就象一個瀏覽單獨文章的模板。這些都會用到[[WordPress:The Loop|Loop]],但是這些都沒有太大的差距,就象[[WordPress:Template_Tags|模板標簽]]之間的不同用法似的。 至于那些沒有分開的模板文件的情況,WordPress使用默認時的<tt>index.php</tt>。如果訪問者請求閱讀一個單獨的文章時,WordPress會首先查找一個名字為<tt>single.php</tt>的文件。如果這個文件存在,它就會用來顯示這個文章。如果不存在,WordPress就會使用<tt>index.php</tt>來顯示文章。這叫做[[WordPress:Template Hierarchy|模板層次]]. 如果你正在制作你自己的[[WordPress:Using Themes|主題]],在默認主題中查看[[WordPress:Templates|模板文件]],作為參考,很有用。同樣,使用你的主題的<tt>index.php</tt>作為你的其他模板文件的模板也是很有用的。因為你創(chuàng)建了更多的模板文件,這樣做可能會帶給你一個已知的工作頁面,從這里開始作出更改。 ===不同的歸檔格式=== <em>archive</em>是歷史文章的集合。在默認時,文章在主索引中顯示的是最新的[http://mydatapages.com/chronological.html 按時間順序的]記錄。當訪問者點擊某個文檔連接時,或者他們手動請求某個特定時間時,(使用<nowiki>http://www.example.com/blog/index.php?m=200504</nowiki>或者 <nowiki>http://www.example.com/blog/2005/04</nowiki> 來選擇所有2005年4月后的文章),WordPress將顯示<em>archive</em>內(nèi)容。默認情況下,歸檔將使用<tt>index.php</tt>,然后和你的首頁一樣,只顯示出2005年四月后的文章。 當WordPress為訪問者準備[[WordPress:Creating_an_Archive_Index|歸檔界面]]時,它會在你現(xiàn)用的主題目錄中明確的尋找一個叫做<tt>archive.php</tt>的文件,如果你想在首頁上使歸檔的意思明確表達,那么把<tt>index.php</tt>復(fù)制到<tt>archive.php</tt>,并且按需求編輯<tt>archive.php</tt>文件。 例如,如果你只想在歸檔列表上顯示文章標題,不包含文章內(nèi)容,你可以使用如下代碼: <pre> <?php get_header(); ?> <div id="content" class="narrowcolumn"> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div class="post"> <h2 id="post-<?php the_ID(); ?>"> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2> <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small> </div> <?php endwhile; ?> <div class="navigation"> <div class="alignleft"> <?php posts_nav_link('','','&laquo; Previous Entries') ?> </div> <div class="alignright"> <?php posts_nav_link('','Next Entries &raquo;','') ?> </div> </div> <?php else : ?> <h2 class="center">Not Found</h2> <p class="center"><?php _e("Sorry, but you are looking for something that isn't here."); ?></p> <?php endif; ?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?> </pre> ===不同的分類格式=== 和歸檔界面一樣,WordPress為[[WordPress:Category_Templates|分類界面]]尋找分開的模板文件。如果訪問者點擊了一個分類連接,他們會看到分類外觀,WordPress會只從分類中準備帶有文章的Loop,限制每個blog默認設(shè)置下的文章的數(shù)目。 要想讓你的分類界面和索引界面不同的話,復(fù)制一個<tt>index.php</tt>文件并重命名為<tt>category.php</tt>,對于分類界面,向一個分配過的文章列出分類也許不是必須的,所以我們忽略這一步。取而代之的,我們在頁面頂部聲明分類: <pre> <?php get_header(); ?> <div id="content" class="narrowcolumn"> <p> <strong> <?php single_cat_title('Currently browsing '); ?> </strong><br /> <?php echo category_description(); ?> </p> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div class="post"> <h2 id="post-<?php the_ID(); ?>"> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?></a></h2> <small> <?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --> </small> </div> <?php endwhile; ?> <div class="navigation"> <div class="alignleft"> <?php posts_nav_link('','','&laquo; Previous Entries') ?> </div> <div class="alignright"> <?php posts_nav_link('','Next Entries &raquo;','') ?> </div> </div> <?php else : ?> <h2 class="center">Not Found</h2> <p class="center"><?php _e("Sorry, but you are looking for something that isn't here."); ?></p> <?php endif; ?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?> </pre> ===不同分類的不同格式=== 如在[[WordPress:Template Hierarchy|模板層次]]中敘述的,[[WordPress:Category_Templates|為每個分類創(chuàng)建分開的模板文件]]是可行的。只需要建立名字為<tt>category-<b><u>X</u></b>.php</tt>的文件,這里<b><u>X</u></b>是用數(shù)字表示的分類。仔細考慮你是否需要給某個分類建立全新的完整模板。 讓我們來看兩個分類,"Plants" 和 "Flowers",分類ID分別為3和4。在輸出的地方的每個文章標題旁邊,你都想要有個植物或者花的圖片,取決于哪個分類被顯示,你可以這樣: * 使用兩個分開的文件, <tt>category-3.php</tt> 和 <tt>category-4.php</tt>, 每個文件給每個文章標題使用不同的<tt>img</tt>標簽。 * 在你的默認<tt>category.php</tt>文件中使用條件判斷,來查看是否當前分類是"Plants"或者 "Flowers" (或者都不是), 然后顯示合適的圖片: <pre> <?php if (is_category('3') ): // we're in the Plants category, so show a plant ?> <img src='/images/plant.png' alt='a plant' /> <?php } elseif (is_category('4') ): // we're in the Flowers category, so show a flower ?> <img src='/images/flower.png' alt='a pretty flower' /> <?php endif; // end the if, no images for other other categories ?> </pre> 如果你添加了另外一個分類,"Cars",你想讓它用一個<em>引人注目</em>的方式顯示出來,那么一個分開的<tt>category-<b><u>X</u></b>.php</tt>則是你最合適的選擇。 === 不同分類的不同CSS === 很多使用者想給特定的分類建立單獨的CSS文件。這很容易實現(xiàn)。記住樣式表是在HTML文件中的<tt><head></tt>部分定義并且加載的。WordPress使用<tt>header.php</tt>文件,在默認<tt>header.php</tt>文件中,找到下列語句: <pre> <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" /> </pre> And change it to something like this: <pre> <?php if ( is_category('5') ) { // Load special CSS for "Cars" category ?> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/category-5.css" type="text/css" media="screen" />; <?php } else { ?> <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" /> <?php } ?> </pre> <strong>注意:</strong> 汽車分類模板使用<tt>category-5.css</tt>文件取代默認版面。在這個例子中,CSS文件在應(yīng)用的分類模板文件之后被命名,而不是真正的分類名。這樣你就明白 <tt>category-5.css</tt> 是和<tt>category-5.php</tt>文件聯(lián)系在一起的了. ===不同的單一文章格式=== 當瀏覽任意單一的文章(或者 [[WordPress:Glossary#Permalink|permalink]])的時候,如果有的話,WordPress會使用<tt>single.php</tt>。 在這個部分,在WordPress默認的single.php文件中,提供了有關(guān)當前文章的[[WordPress:Post_Meta_Data_Section|文章meta數(shù)據(jù)信息]]: <pre> <p class="postmetadata alt"> <small> This entry was posted on <?php the_time('l, F jS, Y') ?> at <?php the_time() ?> and is filed under <?php the_category(', ') ?>. You can follow any responses to this entry through the <?php comments_rss_link('RSS 2.0'); ?> feed. <?php if (('open' == $post->comment_status) && ('open' == $post->ping_status)) { // Both Comments and Pings are open ?> You can <a href="#respond">leave a response</a>, or <a href="<?php trackback_url(display); ?>">trackback</a> from your own site. <?php } elseif (!('open' == $post->comment_status) && ('open' == $post->ping_status)) { // Only Pings are Open ?> Responses are currently closed, but you can <a href="<?php trackback_url(display); ?> ">trackback</a> from your own site. <?php } elseif (('open' == $post->comment_status) && !('open' == $post->ping_status)) { // Comments are open, Pings are not ?> You can skip to the end and leave a response. Pinging is currently not allowed. <?php } elseif (!('open' == $post->comment_status) && !('open' == $post->ping_status)) { // Neither Comments, nor Pings are open ?> Both comments and pings are currently closed. <?php } edit_post_link('Edit this entry.','',''); ?> </small> </p> </pre> 這種信息—不論評論是公開還是關(guān)閉—是相當不適合放在一個索引上,歸檔或者分類界面的;那也是為什么只包含在<tt>single.php</tt>模板文件中的原因。 ==其他Loop技巧== 既然你已經(jīng)對WordPress Loop的基本使用有了一個全面的了解,我們開始介紹更多的Loop效果和技巧。 ===靜態(tài)首頁=== 你如何顯示一些blog中特別的<em>僅僅</em>存在于你的首頁上的東西呢?對,就是只在你的首頁或者主頁上的,站點上別的任何地方都看不到的。簡單!我們把這稱為''靜態(tài)首頁''。站點的首頁并不真的是靜態(tài)的。它只是使用了Loop讓它看起來如此罷了。 想讓這個Loop技巧實現(xiàn),使用[[WordPress:Conditional_Tags#The_Main_Page|is_home()]]條件式模板標簽函數(shù)。 在你的 <tt>index.php</tt>, 使用<tt>if ()</tt> 條件句來有條件的輸出附加內(nèi)容: <pre> <?php get_header(); ?> <?php if (is_home()) { // we're on the home page, so let's show a picture of our new kitten! echo "<img src='/images/new_kitty.jpg' alt='Our new cat, Rufus!' />"; // and now back to our regularly scheduled home page } ?> </pre> 如果訪問者請求某個具體文章,頁面,分類或者日期時,函數(shù)<tt>is_home()</tt>不會產(chǎn)生真值,這樣它只顯示在"主"頁上。 參見[[WordPress:Creating a Static Front Page|創(chuàng)建一個靜態(tài)首頁]]以獲得更多信息。 ===只顯示摘錄=== 顯示摘錄而不是全文的最簡單的方法,把所有的<tt>[[WordPress:Template_Tags/the_content|the_content]]()</tt>實例用<tt>[[WordPress:Template_Tags/the_excerpt|the_excerpt()]]</tt>代替,如果你沒有建立你的文章的外部摘錄,這個函數(shù)將自動的顯示文章的前120個詞。 <pre> <div class="entry"> <?php the_excerpt(); ?> </div> </pre> ===顯示摘錄或者全部文章取決于文章編號=== 某些情況下,如在文檔頁面上,如果只有一篇文章的話你可能想顯示全部的內(nèi)容,或者有多篇文章顯示摘錄。你可以自定義Loop來實現(xiàn)。 <pre> <?php if (have_posts()) : ?> <?php if (($wp_query->post_count) > 1) : ?> <?php while (have_posts()) : the_post(); ?> <!-- Do your post header stuff here for excerpts--> <?php the_excerpt() ?> <!-- Do your post footer stuff here for excerpts--> <?php endwhile; ?> <?php else : ?> <?php while (have_posts()) : the_post(); ?> <!-- Do your post header stuff here for single post--> <?php the_content() ?> <!-- Do your post footer stuff here for single post--> <?php endwhile; ?> <?php endif; ?> <?php else : ?> <!-- Stuff to do if there are no posts--> <?php endif; ?> </pre> ===Different Headers/Sidebars/Footers=== WordPress offers the <tt>get_header()</tt>, <tt>get_sidebar()</tt>, and <tt>get_footer()</tt> [[WordPress:Include Tags]] for use in your [[WordPress:Templates|template files]]. These functions make it easy to define a standard header/sidebar/footer which is easily editable. Any changes made to these files will immediately be made visible to viewers, without any work on your part. ===不同的頁眉/邊欄/頁腳=== WordPress在[[WordPress:Templates|模板文件]]中提供<tt>get_header()</tt>,<tt>get_sidebar()</tt>, 和<tt>get_footer()</tt> 幾個[[WordPress:Include Tags|包含標簽]]使用。這些函數(shù)讓定義標準的頁眉/邊欄/頁腳更加簡單。任何對這些文件的改動會立刻顯示給訪問者,你不用做任何工作。 But sometimes you might not <em>want</em> a sidebar. If you don't want a sidebar, simply exclude the call to the <tt>get_sidebar()</tt> function from your template. For example, the <tt>single.php</tt> template in the WordPress default theme does not include a sidebar. 有時你可能不<em>想</em>要邊欄。如果你不想要邊欄,只需簡單的把<tt>get_sidebar()</tt>函數(shù)的調(diào)用從模板中刪除。如,WordPress 默認主題中的模板不包括<tt>single.php</tt>。 To create your own <strong>different</strong> sidebar, you have two choices. # Include the sidebar contents directly into the template file on which you're working. If you want category-3 to have a different sidebar, edit <tt>category-3.php</tt> and include the necessary HTML and PHP to generate your distinctive sidebar. # Use the PHP <tt>[http://www.php.net/include include]</tt> function, to include another file. The WordPress <tt>get_sidebar()</tt> function <em>only</em> loads <tt>sidebar.php</tt>. If you make a file named <tt>sideleft.php</tt>, you would include it like this: <pre> <?php include(TEMPLATEPATH . '/sideleft.php'); ?> </pre> 眼建立你自己的<strong>不同的</strong> 邊欄,你有兩種選擇。 # 把邊欄內(nèi)容直接包含到你正在操作的模板文件中。如果你想要category-3 擁有不同的邊欄, 編輯<tt>category-3.php</tt>,把必須的HTML和PHP代碼包含進去來生成這個唯一的邊欄。 # 使用PHP的<tt>[http://www.php.net/include 包含]</tt> 函數(shù), 來包含另外一個文件。 WordPress <tt>get_sidebar()</tt> 函數(shù) <em>只</em> 加載<tt>sidebar.php</tt>. 如果你有個文件名為<tt>sideleft.php</tt>, 你可以象這樣把它涵蓋進去:: <pre> <?php include(TEMPLATEPATH . '/sideleft.php'); ?> </pre> Using the WordPress default [[WordPress:Template Hierarchy]], if you want to use the same elements on multiple or different templates, it's probably best to put them in separate template files and use the PHP <tt>include()</tt> function. If the element you're adding is specifically for one template file, it's probably best to include it directly in that template file. 使用WordPress默認的[[WordPress:Template Hierarchy|模板層次]],如果你想在多個或者不同的模板中使用相同的元素,你最好把它們放到分開的模板文件中,并使用PHP<tt>include()</tt>函數(shù)。如果這個你添加的元素是特別為某一模板使用的,最好是把它直接包含到那個模板中去。 ==Summary== We've just scratched the surface of what can be done with the Loop. As a reminder, the following are resources that will help you customize your own [[WordPress:The Loop|WordPress Loop]]. * [[WordPress:Templates|Template Files]] * [[WordPress:Template Tags]] * [[WordPress:Template Hierarchy]] * [[WordPress:Conditional Tags]] ==概要== We've just scratched the surface of what can be done with the Loop. As a reminder, the following are resources that will help you customize your own [[WordPress:The Loop|WordPress Loop]]. * [[WordPress:Templates|Template Files]] * [[WordPress:Template Tags]] * [[WordPress:Template Hierarchy]] * [[WordPress:Conditional Tags]] 我們剛才簡單說了下我們使用Loop能做些什么。作為提醒,下邊的內(nèi)容可能會幫助你自定義你自己的[[WordPress:The Loop|WordPress Loop]]。 * [[WordPress:Templates|模板文件]] * [[WordPress:Template Tags|模板標簽]] * [[WordPress:Template Hierarchy|模板層次]] * [[WordPress:Conditional Tags|條件式標簽]] ==Resources== * [http://www.obeattie.com/2006/05/02/wordpress-the-loop/ oBeattie : The Loop] * [http://www.themelab.com/2008/04/04/the-ultimate-guide-to-the-wordpress-loop/ The Ultimate Guide to the WordPress Loop] ==資源== * [http://www.obeattie.com/2006/05/02/wordpress-the-loop/ oBeattie : The Loop] * [http://www.themelab.com/2008/04/04/the-ultimate-guide-to-the-wordpress-loop/ WordPress Loop終極指南]
摘要:
請注意,您對站長百科的所有貢獻都可能被其他貢獻者編輯,修改或刪除。如果您不希望您的文字被任意修改和再散布,請不要提交。
您同時也要向我們保證您所提交的內(nèi)容是您自己所作,或得自一個不受版權(quán)保護或相似自由的來源(參閱
Wordpress-mediawiki:版權(quán)
的細節(jié))。
未經(jīng)許可,請勿提交受版權(quán)保護的作品!
取消
編輯幫助
(在新窗口中打開)
本頁使用的模板:
模板:WordPress導(dǎo)航
(
查看源代碼
)(受保護)
取自“
http://kktzf.com.cn/wiki/WordPress:The_Loop_in_Action
”