天天看點

開源夏令營(8)

在wordpress中,所謂模闆标簽一般是指一篇文章的字段,比如一篇文章的标題,内容,作者,釋出日期,評論數等等.

輸出模闆标簽一般有兩種方式:the_yourtag() 和get_the_yourtag();

the_yourtag()會直接把标簽内容列印到html上面;

get_the_yourtag()會把标簽内容儲存到一個變量中,以供稍後的使用;

通常來說,the_yourtag()==echo get_the_yourtag();

例如拿标題來舉例,以下兩段代碼是等效的:

(代碼一)

<?php the_title(); ?>      

(代碼二)

<?php 
echo get_the_title();
?>
###注意the_permalink()對應的是get_permalink(),沒有 'the';      

模闆标簽大全:http://codex.wordpress.org/Template_Tags

常用的模闆标簽:

<?php the_content(); ?> 日志内容  
<?php the_title(); ?> 顯示一篇日志或頁面的标題  
<?php the_permalink() ?> 顯示一篇日志或頁面的永久連結/URL位址  
<?php the_category(',') ?> 顯示一篇日志或頁面的所屬分類  
<?php the_author(); ?> 顯示一篇日志或頁面的作者  
<?php the_ID(); ?> 顯示一篇日志或頁面的ID  
<?php edit_post_link(); ?> 顯示一篇日志或頁面的編輯連結  
<?php next_post_link('%link') ?> 下一篇日志的URL位址  
<?php previous_post_link('%link') ?> 上一篇日志的URL位址        

繼續閱讀