WIKI使用導(dǎo)航
站長(zhǎng)百科導(dǎo)航
站長(zhǎng)專題
- 網(wǎng)站推廣
- 網(wǎng)站程序
- 網(wǎng)站賺錢
- 虛擬主機(jī)
- cPanel
- 網(wǎng)址導(dǎo)航專題
- 云計(jì)算
- 微博營(yíng)銷
- 虛擬主機(jī)管理系統(tǒng)
- 開(kāi)放平臺(tái)
- WIKI程序與應(yīng)用
- 美國(guó)十大主機(jī)
編輯“WordPress:The Loop in Action”
該編輯可以被撤銷。 請(qǐng)檢查下面的對(duì)比以核實(shí)您想要撤銷的內(nèi)容,然后發(fā)布下面的更改以完成撤銷。
最后版本 | 您的文本 | ||
第1行: | 第1行: | ||
==Introduction== | |||
[[WordPress:The Loop|"The Loop"]] is a term that refers to the main process of WordPress.? You use The Loop in your [[WordPress:Templates|template files]] to show posts to visitors.? You could make templates without The Loop, but you'd only be able to display data from one post. | |||
? | |||
==介紹== | ==介紹== | ||
[[WordPress:The Loop|"The Loop"]]是指WordPress主程序中的一個(gè)術(shù)語(yǔ)。你可以在你的[[WordPress:Templates|模板文件]]中使用Loop來(lái)想訪問(wèn)者顯示你的文章。你可以讓模板不帶有Loop,但這樣你就只能顯示來(lái)自一篇文章的數(shù)據(jù)了。 | [[WordPress:The Loop|"The Loop"]]是指WordPress主程序中的一個(gè)術(shù)語(yǔ)。你可以在你的[[WordPress:Templates|模板文件]]中使用Loop來(lái)想訪問(wèn)者顯示你的文章。你可以讓模板不帶有Loop,但這樣你就只能顯示來(lái)自一篇文章的數(shù)據(jù)了。 | ||
The first thing WordPress does is check that all the files it needs are present.? Next, it collects the default settings, as defined by the [[WordPress:Registered_User_Features|blog administrator]], from the database.? This includes things like the number of posts to display per page, whether commenting is enabled, and the like.? Once these defaults are established, WordPress checks to see what the user asked for.? This information is used to determine which posts to fetch from the database. | |||
WordPress所做的第一件事就是檢查它所需要的所有文件是否存在。接下來(lái),它按照[[WordPress:Registered_User_Features|blog 管理員]]定義的,從數(shù)據(jù)庫(kù)收集默認(rèn)的設(shè)置。這包括每頁(yè)顯示的文章的數(shù)量,是否允許評(píng)論,等等。一旦這些默認(rèn)的內(nèi)容確定后,WordPress就會(huì)檢查使用者要求什么。這個(gè)信息用來(lái)確定從數(shù)據(jù)庫(kù)中取出哪篇文章。s | WordPress所做的第一件事就是檢查它所需要的所有文件是否存在。接下來(lái),它按照[[WordPress:Registered_User_Features|blog 管理員]]定義的,從數(shù)據(jù)庫(kù)收集默認(rèn)的設(shè)置。這包括每頁(yè)顯示的文章的數(shù)量,是否允許評(píng)論,等等。一旦這些默認(rèn)的內(nèi)容確定后,WordPress就會(huì)檢查使用者要求什么。這個(gè)信息用來(lái)確定從數(shù)據(jù)庫(kù)中取出哪篇文章。s | ||
If the user didn't ask for a specific post, category, page, or date, WordPress uses the previously collected default values to determine which posts to prepare for the user.? For example, if the blog administrator has selected to display 5 posts per page in [[WordPress:Administration_Panels|Administration]] > [[WordPress:Administration_Panels#Reading|Settings]] > [[WordPress:Settings_Reading_SubPanel|Reading]], then WordPress will fetch the five most recent posts from the database.? If the user did ask for a specific post, category, page, or date, then WordPress will use that information to specify which ''post''(s) to fetch from the database. | |||
如果使用者不要求特定的文章,分類,頁(yè)面或者日期,WordPress使用以前收集的默認(rèn)值確定哪個(gè)文章準(zhǔn)備給使用者閱讀。例如,如果blog管理員在[[WordPress:Administration_Panels|Administration]] > [[WordPress:Administration_Panels#Reading|Settings]] > [[WordPress:Settings_Reading_SubPanel|Reading]]設(shè)置中選擇每頁(yè)顯示5篇文章,那么WordPress就會(huì)從數(shù)據(jù)庫(kù)中取最新的5篇。如果使用者要求特定的文章,分類,頁(yè)面或者日期,那么WordPress就會(huì)根據(jù)這些信息來(lái)選擇從數(shù)據(jù)庫(kù)中取出哪篇''文章''。 | 如果使用者不要求特定的文章,分類,頁(yè)面或者日期,WordPress使用以前收集的默認(rèn)值確定哪個(gè)文章準(zhǔn)備給使用者閱讀。例如,如果blog管理員在[[WordPress:Administration_Panels|Administration]] > [[WordPress:Administration_Panels#Reading|Settings]] > [[WordPress:Settings_Reading_SubPanel|Reading]]設(shè)置中選擇每頁(yè)顯示5篇文章,那么WordPress就會(huì)從數(shù)據(jù)庫(kù)中取最新的5篇。如果使用者要求特定的文章,分類,頁(yè)面或者日期,那么WordPress就會(huì)根據(jù)這些信息來(lái)選擇從數(shù)據(jù)庫(kù)中取出哪篇''文章''。 | ||
Once all this is done, WordPress connects to the database, retrieves the specified information, and stores the results in a variable.? It is The Loop that accesses this variable, and uses the values for display in your templates. | |||
一旦所有這些完成之后,WordPress就連接數(shù)據(jù)庫(kù),得到需要的信息,然后在一個(gè)變量中儲(chǔ)存這個(gè)結(jié)果。進(jìn)入這個(gè)變量的就是Loop,然后在模板中顯示變量的值。 | 一旦所有這些完成之后,WordPress就連接數(shù)據(jù)庫(kù),得到需要的信息,然后在一個(gè)變量中儲(chǔ)存這個(gè)結(jié)果。進(jìn)入這個(gè)變量的就是Loop,然后在模板中顯示變量的值。 | ||
By default, if the visitor did not select a specific post, page, category, or date, WordPress uses <tt>index.php</tt> to display everything.? For the first part of this discussion of The Loop we'll focus only on <tt>index.php</tt>, and the default display of your blog.? Later on, once you understand how things work, we'll investigate tricks with The Loop in other template files. | |||
默認(rèn)情況下,如果訪問(wèn)者沒(méi)有選擇特定的文章,頁(yè)面,分類或者日期,WordPress會(huì)使用<tt>index.php</tt>顯示所有內(nèi)容。在這個(gè)Loop的討論的第一部分,我們只集中討論<tt>index.php</tt>,和默認(rèn)的blog顯示。接下來(lái),一旦你懂得這些如何工作的時(shí)候,我們來(lái)研究Loop在別的模板文件中的作用。 | 默認(rèn)情況下,如果訪問(wèn)者沒(méi)有選擇特定的文章,頁(yè)面,分類或者日期,WordPress會(huì)使用<tt>index.php</tt>顯示所有內(nèi)容。在這個(gè)Loop的討論的第一部分,我們只集中討論<tt>index.php</tt>,和默認(rèn)的blog顯示。接下來(lái),一旦你懂得這些如何工作的時(shí)候,我們來(lái)研究Loop在別的模板文件中的作用。 | ||
==The World's Simplest Index Page== | |||
The following is a fully functional index which will display the contents (and just the contents) of each post, according to the conditions used to prepare The Loop.? The only purpose for showing you this is to demonstrate how little is actually necessary for the functioning of The Loop.? The bulk of the stuff in your <tt>index.php</tt> is CSS, HTML, and PHP declarations to make The Loop look pretty. | |||
<pre> | |||
<?php | |||
get_header(); | |||
if (have_posts()) : | |||
? while (have_posts()) : | |||
? ? ? the_post(); | |||
? ? ? the_content(); | |||
? endwhile; | |||
endif; | |||
get_sidebar(); | |||
get_footer(); | |||
?> | |||
</pre> | |||
Now, let's look at the bulk of the stuff that makes The Loop look pretty. | |||
==世界上最簡(jiǎn)單的索引頁(yè)面== | ==世界上最簡(jiǎn)單的索引頁(yè)面== | ||
第26行: | 第54行: | ||
?> | ?> | ||
</pre> | </pre> | ||
==The Default Loop== | |||
The following is a step-by-step look at the default usage of the Loop that comes with the ''default'' and ''classic'' theme in the standard installation of WordPress v1.5. | |||
==默認(rèn) Loop== | ==默認(rèn) Loop== | ||
接下來(lái)是一步一步的來(lái)看WordPress v1.5標(biāo)準(zhǔn)安裝,默認(rèn)情況下,''默認(rèn)'' 和 ''經(jīng)典''主題中l(wèi)oop用法。 | 接下來(lái)是一步一步的來(lái)看WordPress v1.5標(biāo)準(zhǔn)安裝,默認(rèn)情況下,''默認(rèn)'' 和 ''經(jīng)典''主題中l(wèi)oop用法。 | ||
===Begin The Loop=== | |||
Found at the top of the default <tt>index.php</tt> template file is the starting code for? [[WordPress:The Loop]]. | |||
<pre><?php if (have_posts()) : ?><br /> | |||
<?php while (have_posts()) : the_post(); ?></pre> | |||
#First it checks whether any posts were collected with the <tt>have_posts()</tt> function. | |||
#If there are any posts, a PHP <tt>[http://www.php.net/while while]</tt> loop is started.? A <tt>while</tt> loop will continue to execute as long as the condition in the parenthesis is logically true.? So as long as the function <tt>have_posts()</tt> returns a true value, The Loop will keep going. | |||
#The function <tt>have_posts()</tt> simply checks the next item in the collection of posts: if there's another item, return true; if there is no next item, return false. | |||
=== Loop開(kāi)始=== | === Loop開(kāi)始=== | ||
在默認(rèn)<tt>index.php</tt>模板文件的頂部,是[[WordPress:The Loop|Loop]]代碼開(kāi)始的地方。 | 在默認(rèn)<tt>index.php</tt>模板文件的頂部,是[[WordPress:The Loop|Loop]]代碼開(kāi)始的地方。 | ||
第37行: | 第78行: | ||
#如果有文章的話,一個(gè)PHP <tt>[http://www.php.net/while while]</tt>的loop就開(kāi)始了。只要插入語(yǔ)為邏輯真,<tt>while</tt> loop就會(huì)繼續(xù)執(zhí)行。這樣只要函數(shù)<tt>have_posts()</tt> 返回真值,Loop就會(huì)繼續(xù)。 | #如果有文章的話,一個(gè)PHP <tt>[http://www.php.net/while while]</tt>的loop就開(kāi)始了。只要插入語(yǔ)為邏輯真,<tt>while</tt> loop就會(huì)繼續(xù)執(zhí)行。這樣只要函數(shù)<tt>have_posts()</tt> 返回真值,Loop就會(huì)繼續(xù)。 | ||
#函數(shù)<tt>have_posts()</tt>簡(jiǎn)單的在文章集合中檢查下一個(gè)項(xiàng)目:如果有另外一個(gè)項(xiàng)目,返回true,如果沒(méi)有下一個(gè)項(xiàng)目,返回false . | #函數(shù)<tt>have_posts()</tt>簡(jiǎn)單的在文章集合中檢查下一個(gè)項(xiàng)目:如果有另外一個(gè)項(xiàng)目,返回true,如果沒(méi)有下一個(gè)項(xiàng)目,返回false . | ||
===Generating the Post=== | |||
The function <tt>the_post()</tt> takes the current item in the collection of posts and makes it available for use inside this iteration of The Loop.? Without <tt>the_post()</tt>, many of the [[WordPress:Template Tags]] used in your theme would not work. | |||
Once the post data is made available, the template can start showing post data to the visitor. | |||
===生成文章=== | ===生成文章=== | ||
<tt>the_post()</tt>函數(shù)把文章集合中的現(xiàn)用的項(xiàng)目拿出來(lái),并且讓它可以在Loop的循環(huán)中使用。如果沒(méi)有<tt>the_post()</tt>,很多主題中使用的[[WordPress:Template Tags|模板標(biāo)簽]]都無(wú)法工作了。 | <tt>the_post()</tt>函數(shù)把文章集合中的現(xiàn)用的項(xiàng)目拿出來(lái),并且讓它可以在Loop的循環(huán)中使用。如果沒(méi)有<tt>the_post()</tt>,很多主題中使用的[[WordPress:Template Tags|模板標(biāo)簽]]都無(wú)法工作了。 | ||
====Title, Date and Author==== | |||
The following [[WordPress:Template Tags|template tags]] get the current post's title, as well as the time it was posted and who posted it. | |||
<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> | |||
====標(biāo)題,日期和作者==== | ====標(biāo)題,日期和作者==== | ||
第51行: | 第104行: | ||
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small> | <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small> | ||
</pre> | </pre> | ||
====Post Content==== | |||
The <tt>[[WordPress:Template_Tags/the_content|the_content()]]</tt> template tag displays the content of the post. This is the meat and potatoes of each pass through The Loop: | |||
<pre> | |||
<div class="entry"> | |||
<?php the_content('Read the rest of this entry &raquo;'); ?> | |||
</div> | |||
</pre> | |||
If you include the [[WordPress:Write_Post_SubPanel#Quicktags|Quicktag]] button called '''more''', and shown as <tt>[[WordPress:Customizing_the_Read_More|<!--more-->]]</tt>, in the body of your post, only the portion <em>above</em> that line will be displayed to viewers.? So, if you only want your front page to show the first sentence or two of every post, simply insert <tt><!--more--></tt> after the first line into every post you make. | |||
====文章內(nèi)容==== | ====文章內(nèi)容==== | ||
第60行: | 第123行: | ||
</pre> | </pre> | ||
如果你把'''more'''這個(gè)按鈕包含到[[WordPress:Write_Post_SubPanel#Quicktags|Quicktag]],然后象這樣<tt>[[WordPress:Customizing_the_Read_More|<!--more-->]]</tt>顯示出來(lái), 在你的文章的正文部分,只有<em>above</em>這部分才會(huì)顯示給訪問(wèn)者。這樣,如果你只是想讓你的首頁(yè)面顯示每篇文章的第一句或者前兩句話的話,只需要簡(jiǎn)單的在每篇文章的第一行之后插入 <tt><!--more--></tt>就可以了。 | 如果你把'''more'''這個(gè)按鈕包含到[[WordPress:Write_Post_SubPanel#Quicktags|Quicktag]],然后象這樣<tt>[[WordPress:Customizing_the_Read_More|<!--more-->]]</tt>顯示出來(lái), 在你的文章的正文部分,只有<em>above</em>這部分才會(huì)顯示給訪問(wèn)者。這樣,如果你只是想讓你的首頁(yè)面顯示每篇文章的第一句或者前兩句話的話,只需要簡(jiǎn)單的在每篇文章的第一行之后插入 <tt><!--more--></tt>就可以了。 | ||
When viewing a single post, the <tt><!-- more --></tt> delimiter is skipped.? So putting the <tt><!-- more --></tt> delimiter into all your posts forces readers to click through to each individual post if they want to read the whole thing. | |||
當(dāng)查看某個(gè)單一的文章的時(shí)候,<tt><!-- more --></tt>分隔符會(huì)被忽略。這樣如果讀者想閱讀全部?jī)?nèi)容,而又在所有的文章中都加如<tt><!-- more --></tt>分隔符的話,會(huì)迫使讀者點(diǎn)擊每個(gè)單獨(dú)的文章。 | 當(dāng)查看某個(gè)單一的文章的時(shí)候,<tt><!-- more --></tt>分隔符會(huì)被忽略。這樣如果讀者想閱讀全部?jī)?nèi)容,而又在所有的文章中都加如<tt><!-- more --></tt>分隔符的話,會(huì)迫使讀者點(diǎn)擊每個(gè)單獨(dú)的文章。 | ||
====Additional Details==== | |||
Beneath each post's content in the <tt>index.php</tt> template file is a place to display more information about the post, such as the categories, date, and comment information.? Known as the [[WordPress:Post_Meta_Data_Section|post meta data section]], if you're a logged in user of sufficient privilege (or the post's author), you will also see an "Edit This" link, thanks to the <tt>[[WordPress:Template_Tags/edit_post_link|edit_post_link()]]</tt> template tag function. | |||
<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> | |||
====詳細(xì)資料附==== | ====詳細(xì)資料附==== | ||
第73行: | 第148行: | ||
</pre> | </pre> | ||
如果評(píng)論被激活,或者是該文章有評(píng)論內(nèi)容,<tt>[[WordPress:Template_Tags/comments_popup_link|comments_popup_link()]]</tt> | ? | ||
If commenting is enabled, or if the post has comments, the <tt>[[WordPress:Template_Tags/comments_popup_link|comments_popup_link()]]</tt> template tag will display a link to the comments.? If you're using the [[WordPress:Template_Tags/comments_popup_script|comments popup window]], this link will open the comments window; otherwise it will jump right to this post's comments. | |||
? | |||
If the visitor is viewing an index of posts (''i.e.:'' more than one post in The Loop), the <tt>comments_popup_link()</tt> link will take the reader to this post's individual page. | |||
? | |||
如果評(píng)論被激活,或者是該文章有評(píng)論內(nèi)容,<tt>[[WordPress:Template_Tags/comments_popup_link|comments_popup_link()]]</tt>模板標(biāo)簽將回顯示一個(gè)到評(píng)論內(nèi)容的連接。如果你使用了[[WordPress:Template_Tags/comments_popup_script|評(píng)論彈出窗口]],這個(gè)連接就會(huì)打開(kāi)評(píng)論窗口,否則它就會(huì)直接跳轉(zhuǎn)到這篇文章的評(píng)論內(nèi)容。 | |||
如果訪問(wèn)者在瀏覽文章索引(''i.e.:'' 在Loop中不止一篇文章),<tt>comments_popup_link()</tt>連接將會(huì)把讀者連接到這篇文章的單獨(dú)頁(yè)面。 | 如果訪問(wèn)者在瀏覽文章索引(''i.e.:'' 在Loop中不止一篇文章),<tt>comments_popup_link()</tt>連接將會(huì)把讀者連接到這篇文章的單獨(dú)頁(yè)面。 | ||
====Trackback Autodiscovery==== | |||
The <tt>[[WordPress:Template_Tags/trackback_rdf|trackback_rdf]]</tt> template tag's function is to output machine-readable code used for [[WordPress:Glossary#Trackback|trackback]] auto-discovery. | |||
<pre> | |||
<!-- | |||
<?php trackback_rdf(); ?> | |||
--> | |||
</pre> | |||
'''Note:''' The <tt>trackback_rdf()</tt> tag is supposed to be used with [[WordPress:Commenting_Code|comments]] around it.? It is not "turned off". | |||
====自動(dòng)尋找Trackback ==== | ====自動(dòng)尋找Trackback ==== | ||
第87行: | 第178行: | ||
'''注意:'''<tt>trackback_rdf()</tt>標(biāo)簽支持在自身旁邊使用[[WordPress:Commenting_Code|評(píng)論]]。它并非"關(guān)閉"的。 | '''注意:'''<tt>trackback_rdf()</tt>標(biāo)簽支持在自身旁邊使用[[WordPress:Commenting_Code|評(píng)論]]。它并非"關(guān)閉"的。 | ||
===Ending The Loop=== | |||
The following ends The Loop.? After this, the various post-related template tags will not work as expected (or if they do, they will use the last post from The Loop). This means, that if you need to use a template tag that works '''within The Loop''', you need to put it in before this point. | |||
<pre> | |||
<?php endwhile; ?> | |||
</pre> | |||
===結(jié)束 Loop=== | ===結(jié)束 Loop=== | ||
下面是結(jié)束 Loop。在這之后,各種文章相關(guān)的模板標(biāo)簽不再如如你想要的那樣工作了(如果它們?cè)诠ぷ?它們會(huì)使用Loop的最后一篇文章).這意味著,如果你需要使用一個(gè)工作'''在 Loop內(nèi)'''的模板標(biāo)簽,你需要把如下語(yǔ)句放進(jìn)去。 | 下面是結(jié)束 Loop。在這之后,各種文章相關(guān)的模板標(biāo)簽不再如如你想要的那樣工作了(如果它們?cè)诠ぷ?它們會(huì)使用Loop的最后一篇文章).這意味著,如果你需要使用一個(gè)工作'''在 Loop內(nèi)'''的模板標(biāo)簽,你需要把如下語(yǔ)句放進(jìn)去。 | ||
<pre> | <pre> | ||
<?php endwhile; ?> | <?php endwhile; ?> | ||
</pre> | |||
This section, immediately after the end of The Loop, displays navigation controls to move forward and backward by each web page. | |||
<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> | </pre> | ||
第100行: | 第206行: | ||
</div> | </div> | ||
</pre> | </pre> | ||
? | |||
If the blog is set to display 10 posts per page, and the conditions used by The Loop collect 25 posts, there will be three pages to navigate: two pages of 10 posts each, and one page of 5 posts.? The navigation links will allow the visitor to move forward and backward through the collection of posts. | |||
? | |||
如果blog設(shè)置成每頁(yè)顯示10篇文章,而且Loop收集到了25篇文章,這就會(huì)產(chǎn)生三個(gè)頁(yè)面:兩個(gè)10篇文章的頁(yè)面,還有一個(gè)五篇的頁(yè)面。導(dǎo)航連接允許訪問(wèn)者通過(guò)文章收集跳轉(zhuǎn)到上一還是下一頁(yè)。 | |||
? | |||
The navigation controls are included <em>outside</em> The Loop, but <em>inside</em> the <tt>if</tt> condition, so that they only show up if there are any posts.? The navigation functions themselves also check whether or not there is anything to which they will link, based on the current Loop, and only display links if there's something to link. | |||
? | |||
<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> | |||
The <tt>else :</tt> clause determines what to do if <tt>have_posts()</tt> (from way up at the top) is false.? That is to say, the stuff after the '''else''' will only be executed/displayed if The Loop had zero posts. No posts show up if, for example, the visitor requested a specific day for which no posts were made or a search was performed that produced no results. | |||
? | |||
<pre> | |||
? <?php endif; ?> | |||
</pre> | |||
This ends the conditional test of "if there are posts do this, else if there are no posts, do that".? Once the conditional test is finished, the default index.php template next includes the sidebar, and finally the footer. | |||
導(dǎo)航控制是<em>不包含</em>在Loop內(nèi)的,但是<em>包含在</em><tt>if</tt> 條件句內(nèi),這樣它們只能顯示是否有文章。導(dǎo)航函數(shù)本身也會(huì)檢查是否有一些基于現(xiàn)有Loop的,它們能連接的內(nèi)容,如果有可連接的內(nèi)容的話只顯示連接。 | 導(dǎo)航控制是<em>不包含</em>在Loop內(nèi)的,但是<em>包含在</em><tt>if</tt> 條件句內(nèi),這樣它們只能顯示是否有文章。導(dǎo)航函數(shù)本身也會(huì)檢查是否有一些基于現(xiàn)有Loop的,它們能連接的內(nèi)容,如果有可連接的內(nèi)容的話只顯示連接。 | ||
第116行: | 第240行: | ||
</pre> | </pre> | ||
這個(gè)語(yǔ)句結(jié)束了這樣的條件句:"如果有文章這樣,如果沒(méi)有文章那樣".一旦條件語(yǔ)句結(jié)束了,默認(rèn)的index.php模板包括了邊欄,最后是頁(yè)腳。 | 這個(gè)語(yǔ)句結(jié)束了這樣的條件句:"如果有文章這樣,如果沒(méi)有文章那樣".一旦條件語(yǔ)句結(jié)束了,默認(rèn)的index.php模板包括了邊欄,最后是頁(yè)腳。 | ||
==The Loop In Other Templates== | |||
WordPress can use different template files for displaying your blog in different ways.? In the default WordPress theme, there are [[WordPress:Templates|template files]] for the index view, category view, and archive view, as well as a template for viewing individual posts.? Each of these uses [[WordPress:The Loop]], but does so with slightly different formatting, as well as different uses of the [[WordPress:Template_Tags|template tags]]. | |||
==其它模板中的Loop== | ==其它模板中的Loop== | ||
WordPress可以使用不同的模板文件,用不同的方式顯示你的blog。在默認(rèn)WordPress主題中,有用于索引瀏覽的[[WordPress:Templates|模板文件]],分類瀏覽和文檔瀏覽,就象一個(gè)瀏覽單獨(dú)文章的模板。這些都會(huì)用到[[WordPress:The Loop|Loop]],但是這些都沒(méi)有太大的差距,就象[[WordPress:Template_Tags|模板標(biāo)簽]]之間的不同用法似的。 | WordPress可以使用不同的模板文件,用不同的方式顯示你的blog。在默認(rèn)WordPress主題中,有用于索引瀏覽的[[WordPress:Templates|模板文件]],分類瀏覽和文檔瀏覽,就象一個(gè)瀏覽單獨(dú)文章的模板。這些都會(huì)用到[[WordPress:The Loop|Loop]],但是這些都沒(méi)有太大的差距,就象[[WordPress:Template_Tags|模板標(biāo)簽]]之間的不同用法似的。 | ||
For any view which does not have a separate template file, WordPress will use <tt>index.php</tt> by default.? If a visitor requests a single post, WordPress will first look for a file named <tt>single.php</tt>.? If that file exists, it will be used to present the post to the visitor.? If that file does not exist, WordPress will use <tt>index.php</tt> to present the post to the visitor. This is called the [[WordPress:Template Hierarchy]]. | |||
至于那些沒(méi)有分開(kāi)的模板文件的情況,WordPress使用默認(rèn)時(shí)的<tt>index.php</tt>。如果訪問(wèn)者請(qǐng)求閱讀一個(gè)單獨(dú)的文章時(shí),WordPress會(huì)首先查找一個(gè)名字為<tt>single.php</tt>的文件。如果這個(gè)文件存在,它就會(huì)用來(lái)顯示這個(gè)文章。如果不存在,WordPress就會(huì)使用<tt>index.php</tt>來(lái)顯示文章。這叫做[[WordPress:Template Hierarchy|模板層次]]. | 至于那些沒(méi)有分開(kāi)的模板文件的情況,WordPress使用默認(rèn)時(shí)的<tt>index.php</tt>。如果訪問(wèn)者請(qǐng)求閱讀一個(gè)單獨(dú)的文章時(shí),WordPress會(huì)首先查找一個(gè)名字為<tt>single.php</tt>的文件。如果這個(gè)文件存在,它就會(huì)用來(lái)顯示這個(gè)文章。如果不存在,WordPress就會(huì)使用<tt>index.php</tt>來(lái)顯示文章。這叫做[[WordPress:Template Hierarchy|模板層次]]. | ||
If you are making your own [[WordPress:Using Themes|Theme]], it's often helpful to look at the [[WordPress:Templates|template files]] from the default Theme as a point of reference.? It's also helpful to use your theme's <tt>index.php</tt> as a template for your other template files.? Doing so may give you a known and working page from which to begin making changes as you create more template files. | |||
如果你正在制作你自己的[[WordPress:Using Themes|主題]],在默認(rèn)主題中查看[[WordPress:Templates|模板文件]],作為參考,很有用。同樣,使用你的主題的<tt>index.php</tt>作為你的其他模板文件的模板也是很有用的。因?yàn)槟銊?chuàng)建了更多的模板文件,這樣做可能會(huì)帶給你一個(gè)已知的工作頁(yè)面,從這里開(kāi)始作出更改。 | 如果你正在制作你自己的[[WordPress:Using Themes|主題]],在默認(rèn)主題中查看[[WordPress:Templates|模板文件]],作為參考,很有用。同樣,使用你的主題的<tt>index.php</tt>作為你的其他模板文件的模板也是很有用的。因?yàn)槟銊?chuàng)建了更多的模板文件,這樣做可能會(huì)帶給你一個(gè)已知的工作頁(yè)面,從這里開(kāi)始作出更改。 | ||
當(dāng)WordPress為訪問(wèn)者準(zhǔn)備[[WordPress:Creating_an_Archive_Index| | ===Different Archive Format=== | ||
An <em>archive</em> is a collection of historical posts.? In the default usage, the posts displayed on your main index are recent [http://mydatapages.com/chronological.html chronological] postings.? When a visitor clicks on one of your archive links, or if they manually request a specific date (<nowiki>http://www.example.com/blog/index.php?m=200504</nowiki> or <nowiki>http://www.example.com/blog/2005/04</nowiki> to select all posts from April, 2005), WordPress will display an <em>archive</em> view.? By default, the archive will use <tt>index.php</tt>, and thus look the same as your front page, just displaying the posts from April 2005. | |||
? | |||
===不同的文檔格式=== | |||
<em>archive</em>是歷史文章的集合。在默認(rèn)時(shí),文章在主索引中顯示的是最新的[http://mydatapages.com/chronological.html 按時(shí)間順序的]記錄。當(dāng)訪問(wèn)者點(diǎn)擊某個(gè)文檔連接時(shí),或者他們手動(dòng)請(qǐng)求某個(gè)特定時(shí)間時(shí),(使用<nowiki>http://www.example.com/blog/index.php?m=200504</nowiki>或者 <nowiki>http://www.example.com/blog/2005/04</nowiki> 來(lái)選擇所有2005年4月后的文章),WordPress將顯示<em>archive</em>內(nèi)容。默認(rèn)情況下,文檔將使用<tt>index.php</tt>,然后和你的首頁(yè)一樣,只顯示出2005年四月后的文章。 | |||
? | |||
When WordPress prepares an [[WordPress:Creating_an_Archive_Index|archive view]] for a visitor, it specifically looks for a file named <tt>archive.php</tt> in your current theme's directory.? If you'd like to visually disambiguate archives from your front page, simply copy <tt>index.php</tt> to <tt>archive.php</tt>, and edit <tt>archive.php</tt> as necessary! | |||
? | |||
當(dāng)WordPress為訪問(wèn)者準(zhǔn)備[[WordPress:Creating_an_Archive_Index|文檔界面]]時(shí),它會(huì)在你現(xiàn)用的主題目錄中明確的尋找一個(gè)叫做<tt>archive.php</tt>的文件,如果你想在首頁(yè)上使文檔的意思明確表達(dá),那么把<tt>index.php</tt>復(fù)制到<tt>archive.php</tt>,并且按需求編輯<tt>archive.php</tt>文件。 | |||
? | |||
For example, if you want to show only post titles, and no post content, for your list of archives, you could use something like this: | |||
例如,如果你只想在文檔列表上顯示文章標(biāo)題,不包含文章內(nèi)容,你可以使用如下代碼: | |||
<pre> | <pre> | ||
第158行: | 第297行: | ||
<?php get_footer(); ?> | <?php get_footer(); ?> | ||
</pre> | </pre> | ||
===Different Category Format=== | |||
Like the archive views, WordPress looks for a separate template file for [[WordPress:Category_Templates|category views]].? If a visitor clicks on a link for a category in your blog, they will be taken to the category view.? WordPress will prepare The Loop with posts from that category only, limiting the number of posts per the blog's default settings. | |||
===不同的分類格式=== | ===不同的分類格式=== | ||
和文檔界面一樣,WordPress為[[WordPress:Category_Templates|分類界面]]尋找分開(kāi)的模板文件。如果訪問(wèn)者點(diǎn)擊了一個(gè)分類連接,他們會(huì)看到分類外觀,WordPress會(huì)只從分類中準(zhǔn)備帶有文章的Loop,限制每個(gè)blog默認(rèn)設(shè)置下的文章的數(shù)目。 | |||
要想讓你的分類界面和索引界面不同的話,復(fù)制一個(gè)<tt>index.php</tt> | To make your category view different from your index view, copy <tt>index.php</tt> and rename it <tt>category.php</tt>.? For a category view, it's probably not necessary to list the categories to which a post is assigned, so let's remove that portion.? Instead, let's announce the category at the top of the page: | ||
? | |||
要想讓你的分類界面和索引界面不同的話,復(fù)制一個(gè)<tt>index.php</tt>文件并命名為<tt>category.php</tt>,對(duì)于分類界面,向一個(gè)分配過(guò)的文章列出分類也許不是必須的,所以我們忽略這一步。取而代之的,我們?cè)陧?yè)面頂部聲明分類: | |||
<pre> | <pre> | ||
第201行: | 第345行: | ||
<?php get_footer(); ?> | <?php get_footer(); ?> | ||
</pre> | </pre> | ||
===Different Formats for Different Categories=== | |||
As explained in the [[WordPress:Template Hierarchy]], it is possible to [[WordPress:Category_Templates|create separate template files for each category]].? Simply name the file <tt>category-<b><u>X</u></b>.php</tt>, where <b><u>X</u></b> is the numerical ID of the category.? Consider carefully whether you need a whole new template for a specific category. | |||
===不同分類的不同格式=== | ===不同分類的不同格式=== | ||
如在[[WordPress:Template Hierarchy|模板層次]]中敘述的,[[WordPress:Category_Templates|為每個(gè)分類創(chuàng)建分開(kāi)的模板文件]]是可行的。只需要建立名字為<tt>category-<b><u>X</u></b>.php</tt>的文件,這里<b><u>X</u></b>是用數(shù)字表示的分類。仔細(xì)考慮你是否需要給某個(gè)分類建立全新的完整模板。 | 如在[[WordPress:Template Hierarchy|模板層次]]中敘述的,[[WordPress:Category_Templates|為每個(gè)分類創(chuàng)建分開(kāi)的模板文件]]是可行的。只需要建立名字為<tt>category-<b><u>X</u></b>.php</tt>的文件,這里<b><u>X</u></b>是用數(shù)字表示的分類。仔細(xì)考慮你是否需要給某個(gè)分類建立全新的完整模板。 | ||
Let's look at two categories, "Plants" and "Flowers", with category IDs 3 and 4, respectively.? Next to each post title in the output you want to have picture of either a plant, or a flower, depending on which category is being displayed.? You could: | |||
* Use two separate files, <tt>category-3.php</tt> and <tt>category-4.php</tt>, each with a different <tt>img</tt> tag for each post title. | |||
* Use a conditional test inside your default <tt>category.php</tt> file to check whether the current category is "Plants" or "Flowers" (or neither), and display the appropriate image: | |||
<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> | |||
讓我們來(lái)看兩個(gè)分類,"Plants" 和 "Flowers",分類ID分別為3和4。在輸出的地方的每個(gè)文章標(biāo)題旁邊,你都想要有個(gè)植物或者花的圖片,取決于哪個(gè)分類被顯示,你可以這樣: | 讓我們來(lái)看兩個(gè)分類,"Plants" 和 "Flowers",分類ID分別為3和4。在輸出的地方的每個(gè)文章標(biāo)題旁邊,你都想要有個(gè)植物或者花的圖片,取決于哪個(gè)分類被顯示,你可以這樣: | ||
第218行: | 第378行: | ||
<?php endif; // end the if, no images for other other categories ?> | <?php endif; // end the if, no images for other other categories ?> | ||
</pre> | </pre> | ||
If you added another category, "Cars", which you wanted to display in a <em>significantly</em> different way, then a separate <tt>category-<b><u>X</u></b>.php</tt> would be more appropriate. | |||
如果你添加了另外一個(gè)分類,"Cars",你想讓它用一個(gè)<em>引人注目</em>的方式顯示出來(lái),那么一個(gè)分開(kāi)的<tt>category-<b><u>X</u></b>.php</tt>則是你最合適的選擇。 | 如果你添加了另外一個(gè)分類,"Cars",你想讓它用一個(gè)<em>引人注目</em>的方式顯示出來(lái),那么一個(gè)分開(kāi)的<tt>category-<b><u>X</u></b>.php</tt>則是你最合適的選擇。 | ||
=== Different CSS For Different Categories === | |||
Many users want to create separate CSS files for a specific category.? This, too, can be easily accomplished.? It is important to remember that stylesheets are defined and loaded in the <tt><head></tt> section of the HTML document.? WordPress uses the <tt>header.php</tt> file for this.? In the default <tt>header.php</tt>, find this line: | |||
<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>Note:</strong> The Cars template uses the <tt>category-5.css</tt> file to override the default layout.? In this example the CSS file is named after the category template file to which it will be applied, rather than the actual name of the category.? Thus, you know that <tt>category-5.css</tt> goes with <tt>category-5.php</tt>. | |||
=== 不同分類的不同CSS === | === 不同分類的不同CSS === | ||
第236行: | 第415行: | ||
<strong>注意:</strong> 汽車分類模板使用<tt>category-5.css</tt>文件取代默認(rèn)版面。在這個(gè)例子中,CSS文件在應(yīng)用的分類模板文件之后被命名,而不是真正的分類名。這樣你就明白 <tt>category-5.css</tt> 是和<tt>category-5.php</tt>文件聯(lián)系在一起的了. | <strong>注意:</strong> 汽車分類模板使用<tt>category-5.css</tt>文件取代默認(rèn)版面。在這個(gè)例子中,CSS文件在應(yīng)用的分類模板文件之后被命名,而不是真正的分類名。這樣你就明白 <tt>category-5.css</tt> 是和<tt>category-5.php</tt>文件聯(lián)系在一起的了. | ||
===Different Single Post Format=== | |||
When viewing any single post (or [[WordPress:Glossary#Permalink|permalink]]), WordPress will use <tt>single.php</tt>, if present. | |||
This portion, from the WordPress default single.php, provides the [[WordPress:Post_Meta_Data_Section|post meta data information]] about the current post: | |||
===不同的單一文章格式=== | ===不同的單一文章格式=== | ||
當(dāng)瀏覽任意單一的文章(或者 [[WordPress:Glossary#Permalink|permalink]]) | 當(dāng)瀏覽任意單一的文章(或者 [[WordPress:Glossary#Permalink|permalink]])的時(shí)候,WordPress會(huì)使用<tt>single.php</tt>。如果有的話。 | ||
? | |||
在這個(gè)部分,在WordPress默認(rèn)的single.php文件中,提供了有關(guān)當(dāng)前文章的[[WordPress:Post_Meta_Data_Section|文章meta數(shù)據(jù)信息]]: | 在這個(gè)部分,在WordPress默認(rèn)的single.php文件中,提供了有關(guān)當(dāng)前文章的[[WordPress:Post_Meta_Data_Section|文章meta數(shù)據(jù)信息]]: | ||
<pre> | <pre> | ||
第277行: | 第462行: | ||
</p> | </p> | ||
</pre> | </pre> | ||
This sort of information -- whether comments are open or closed -- is largely inappropriate on an index, archive, or category view; which is why it's only included in the <tt>single.php</tt> template file. | |||
? | |||
這種信息—不論評(píng)論是公開(kāi)還是關(guān)閉—是相當(dāng)不適合放在一個(gè)索引,文檔或者分類界面的;那也是為什么只包含在<tt>single.php</tt>模板文件中的原因。 | |||
? | |||
==Other Loop Tricks== | |||
Now that you have a good introduction to the basic uses for the WordPress Loop, let's introduce you to some more Loop effects and tricks. | |||
==其他Loop技巧== | ==其他Loop技巧== | ||
現(xiàn)在你已經(jīng)對(duì)WordPress Loop的基本使用有了一個(gè)全面的了解,我們開(kāi)始介紹更多的Loop效果和技巧。 | |||
? | |||
===Static Front Page=== | |||
? | |||
How can you display something special <em>only</em> on the front page of your blog? That's right, only on the front page or home page, and have it not be seen anywhere else on your site. Easy! We call this the ''static front page''.? The front or first page of your site isn't really static.? It's just using the Loop to make it look that way. | |||
? | |||
To make this Loop trick work, use the [[WordPress:Conditional_Tags#The_Main_Page|is_home()]] conditional template tag function. | |||
===靜態(tài)首頁(yè)=== | ===靜態(tài)首頁(yè)=== | ||
第287行: | 第483行: | ||
想讓這個(gè)Loop技巧實(shí)現(xiàn),使用[[WordPress:Conditional_Tags#The_Main_Page|is_home()]]條件式模板標(biāo)簽函數(shù)。 | 想讓這個(gè)Loop技巧實(shí)現(xiàn),使用[[WordPress:Conditional_Tags#The_Main_Page|is_home()]]條件式模板標(biāo)簽函數(shù)。 | ||
In your <tt>index.php</tt>, use an <tt>if ()</tt> test to conditionally output additional content: | |||
在你的 <tt>index.php</tt>, 使用<tt>if ()</tt> 條件句來(lái)有條件的輸出附加內(nèi)容: | 在你的 <tt>index.php</tt>, 使用<tt>if ()</tt> 條件句來(lái)有條件的輸出附加內(nèi)容: | ||
第299行: | 第497行: | ||
</pre> | </pre> | ||
The function <tt>is_home()</tt> will only produce a true value if the visitor is not requesting a specific post, page, category, or date, so it only shows up on the "home" page. | |||
? | |||
如果訪問(wèn)者請(qǐng)求某個(gè)特殊文章,頁(yè)面,分類或者日期時(shí),函數(shù)<tt>is_home()</tt>不會(huì)產(chǎn)生真值,這樣它只顯示在"主"頁(yè)上。 | |||
? | |||
For more information, see [[WordPress:Creating a Static Front Page]]. | |||
參見(jiàn)[[WordPress:Creating a Static Front Page|創(chuàng)建一個(gè)靜態(tài)首頁(yè)]]以獲得更多信息。 | 參見(jiàn)[[WordPress:Creating a Static Front Page|創(chuàng)建一個(gè)靜態(tài)首頁(yè)]]以獲得更多信息。 | ||
===Excerpts Only=== | |||
The easiest way to display excerpts, instead of the full content, of posts, replace all instances of <tt>[[WordPress:Template_Tags/the_content|the_content]]()</tt> with <tt>[[WordPress:Template_Tags/the_excerpt|the_excerpt()]]</tt>.? If you have not created explicit excerpts for your posts, this function will automatically display the first 120 words of the post. | |||
<pre> | |||
<div class="entry"> | |||
<?php the_excerpt(); ?> | |||
</div> | |||
</pre> | |||
===只顯示摘錄=== | ===只顯示摘錄=== | ||
第310行: | 第520行: | ||
</div> | </div> | ||
</pre> | </pre> | ||
===Showing Excerpts or Full Post Depending Upon Number of Posts=== | |||
In some circumstances, for example on archive pages, you may want to show the full post if there is only one post or excerpts if there are multiple posts. You can customize the loop to do this. | |||
===顯示摘錄或者全部文章取決于文章編號(hào)=== | ===顯示摘錄或者全部文章取決于文章編號(hào)=== | ||
第340行: | 第553行: | ||
</pre> | </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. | |||
===不同的頁(yè)眉/邊欄/頁(yè)腳=== | ===不同的頁(yè)眉/邊欄/頁(yè)腳=== | ||
WordPress在[[WordPress:Templates|模板文件]]中提供<tt>get_header()</tt>,<tt>get_sidebar()</tt>, 和<tt>get_footer()</tt> 幾個(gè)[[WordPress:Include Tags|包含標(biāo)簽]]使用。這些函數(shù)讓定義標(biāo)準(zhǔn)的頁(yè)眉/邊欄/頁(yè)腳更加簡(jiǎn)單。任何對(duì)這些文件的改動(dòng)會(huì)立刻顯示給訪問(wèn)者,你不用做任何工作。 | WordPress在[[WordPress:Templates|模板文件]]中提供<tt>get_header()</tt>,<tt>get_sidebar()</tt>, 和<tt>get_footer()</tt> 幾個(gè)[[WordPress:Include Tags|包含標(biāo)簽]]使用。這些函數(shù)讓定義標(biāo)準(zhǔn)的頁(yè)眉/邊欄/頁(yè)腳更加簡(jiǎn)單。任何對(duì)這些文件的改動(dòng)會(huì)立刻顯示給訪問(wèn)者,你不用做任何工作。 | ||
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. | |||
有時(shí)你可能不<em>想</em>要邊欄。如果你不想要邊欄,只需簡(jiǎn)單的把<tt>get_sidebar()</tt>函數(shù)的調(diào)用從模板中刪除。如,WordPress 默認(rèn)主題中的模板不包括<tt>single.php</tt>。 | 有時(shí)你可能不<em>想</em>要邊欄。如果你不想要邊欄,只需簡(jiǎn)單的把<tt>get_sidebar()</tt>函數(shù)的調(diào)用從模板中刪除。如,WordPress 默認(rèn)主題中的模板不包括<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代碼包含進(jìn)去來(lái)生成這個(gè)唯一的邊欄。 | # 把邊欄內(nèi)容直接包含到你正在操作的模板文件中。如果你想要category-3 擁有不同的邊欄, 編輯<tt>category-3.php</tt>,把必須的HTML和PHP代碼包含進(jìn)去來(lái)生成這個(gè)唯一的邊欄。 | ||
# 使用PHP的<tt>[http://www.php.net/include 包含]</tt> 函數(shù), 來(lái)包含另外一個(gè)文件。 WordPress <tt>get_sidebar()</tt> 函數(shù) <em>只</em> 加載<tt>sidebar.php</tt>. 如果你有個(gè)文件名為<tt>sideleft.php</tt>, 你可以象這樣把它涵蓋進(jìn)去:: | # 使用PHP的<tt>[http://www.php.net/include 包含]</tt> 函數(shù), 來(lái)包含另外一個(gè)文件。 WordPress <tt>get_sidebar()</tt> 函數(shù) <em>只</em> 加載<tt>sidebar.php</tt>. 如果你有個(gè)文件名為<tt>sideleft.php</tt>, 你可以象這樣把它涵蓋進(jìn)去:: | ||
第352行: | 第577行: | ||
<?php include(TEMPLATEPATH . '/sideleft.php'); ?> | <?php include(TEMPLATEPATH . '/sideleft.php'); ?> | ||
</pre> | </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默認(rèn)的[[WordPress:Template Hierarchy|模板層次]],如果你想在多個(gè)或者不同的模板中使用相同的元素,你最好把它們放到分開(kāi)的模板文件中,并使用PHP<tt>include()</tt>函數(shù)。如果這個(gè)你添加的元素是特別為某一模板使用的,最好是把它直接包含到那個(gè)模板中去。 | 使用WordPress默認(rèn)的[[WordPress:Template Hierarchy|模板層次]],如果你想在多個(gè)或者不同的模板中使用相同的元素,你最好把它們放到分開(kāi)的模板文件中,并使用PHP<tt>include()</tt>函數(shù)。如果這個(gè)你添加的元素是特別為某一模板使用的,最好是把它直接包含到那個(gè)模板中去。 | ||
==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]] | |||
我們剛才簡(jiǎn)單說(shuō)了下我們使用Loop能做些什么。作為提醒,下邊的內(nèi)容可能會(huì)幫助你自定義你自己的[[WordPress:The Loop|WordPress Loop]]。 | 我們剛才簡(jiǎn)單說(shuō)了下我們使用Loop能做些什么。作為提醒,下邊的內(nèi)容可能會(huì)幫助你自定義你自己的[[WordPress:The Loop|WordPress Loop]]。 | ||
第363行: | 第605行: | ||
* [[WordPress:Conditional Tags|條件式標(biāo)簽]] | * [[WordPress:Conditional Tags|條件式標(biāo)簽]] | ||
==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.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終極指南] | * [http://www.themelab.com/2008/04/04/the-ultimate-guide-to-the-wordpress-loop/ WordPress Loop終極指南] |