get post meta php
<?php $meta_values = get_post_meta($post_id, $key, $single); ?>
缺省用法 數組
<?php $key_1_values = get_post_meta(76, 'key_1'); ?>
其餘示例 ide
僅檢索給定關鍵字的第一個值: wordpress
<?php $key_1_value = get_post_meta(76, 'key_1', true); ?>
更詳細的示例參見 post_meta函數示例頁面。 函數
參數 post
$post_id spa
(整數)(必需)但願從中獲得數據的文章的編號。用$post->ID獲取文章編號。 日誌
默認值:None code
$key 視頻
(字符)(必需)字符,字符中含有但願的meta值的名稱。
默認值:None
$single
(布爾值)(可選)若是默認值設爲true,函數返回單個字符形式的結果。若是爲false或爲設置,則函數返回自定義字段的數組。
默認值:false
返回的值
不管$single值是什麼,若是沒有指定關鍵字,函數將返回空的字符。
get_children()get_children( )檢索附件、版本、子頁面等信息,通常狀況下由父文章執行。
get_children( )與get_posts( )運行基本一致。
簡介
array|false $children =& get_children( mixed $args = "", constant $output = OBJECT);
返回的值
返回文章的關聯數組(由$output參數設置的變量類型),其中文章編號做爲數組的key,若是未找到相應文章返回false。
示例
$images =& get_children( 'post_type=attachment&post_mime_type=image' );
$videos =& get_children( 'post_type=attachment&
post_mime_type=video/mp4' );
if ( empty($images) ) {
// no attachments here
} else {
foreach ( $images as $attachment_id => $attachment ) {
echo wp_get_attachment_image( $attachment_id, 'full' );
}
}
// If you don't need to handle an empty result:
foreach ( (array) $videos as $attachment_id => $attachment ) {
echo wp_get_attachment_link( $attachment_id );
}
默認參數(2.7版本)
$defaults = array(
'post_parent' => 0, 'post_type' => 'any',
'numberposts' => -1,
'post_status' => 'any',
);
參數
參數徹底列表參見 get_posts()
在2.6版本中須要傳遞非空的post_type參數(也能夠是附件或頁面)。
$args
(混合)傳遞一個查詢類型的字符或數組後可設置若干參數(以下)。傳遞整數文章編號或文章對象,可檢索到該文章的子文章;傳遞空值則檢索最新文章或頁面的子文章或頁面。
$args['numberposts']
(整數)須要檢索的子文章數量。可選;默認值:-1(無限)
$args['post_parent']
(整數)傳遞日誌或頁面的編號以獲取其子文章。傳遞空值可獲取任意文章的子文章。可選;默認值:0 (任意父文章?)
$args['post_type']
(字符)文章列表中post_type列中的值,如附件,頁面或修改狀況;或者關鍵詞any。
默認值:any
$args['post_status']
(字符)文章列表中post_status列中的值,如已發佈,草稿或遺傳;或關鍵詞any。默認值:any
$args['post_mime_type']
(字符)徹底或不徹底的mime類型,如圖片,視頻,視頻/mp4,與文章的post_mime_type字段相匹配。
$output
(常量)由OBJECT, ARRAY_A, ARRAY_N中任一個函數所返回的數組項的變量類型。可選;默認值:OBJECT
<?php the_time('Y-m-d'); ?> 顯示的是 2011-10-1 這樣的,修改()中內容用如下字符替換能夠達到相應效果。 複製代碼代碼以下: <?php the_time('Y年m月d日'); ?> 則顯示 2011年10月1日 a表明小寫的英語的上下午,如am、pm A表明大寫的英語的上下午,如AM、PM d表明英語的日期(小於10仍爲兩位數寫法),如0五、12 D表明中文的星期,如5、七 F表明中文的月份(包括「月」這個字),如五月、十二月 g表明英語的小時(小於10爲一位數寫法),如五、12 G表明英語的小時(小於10仍爲兩位數寫法),如0五、12 h表明英語的分鐘(小於10爲一位數寫法),如五、12 H表明英語的分鐘(小於10仍爲兩位數寫法),如0五、12 j表明英語的日期(小於10爲一位數寫法),如0五、12 l表明中文的星期(包括「星期」這兩個字),如星期5、星期七 m表明英語的月份(小於10仍爲兩位數寫法),如0五、12 M表明英語的月份(以單詞的形式顯示),如Jun n表明英語的月份(小於10爲一位數寫法),如五、12 O表明英語的時區,如+0800 r表明完整的日期時間,如Tue, 06 Jun 2006 18:37:11 +0800 S表明日期的序數後綴,如st、th T表明英語的時區(以單詞的形式顯示),如CST w表明英語的星期,如五、7 W表明週數,如23 y表明兩位數年份,如0七、08 Y表明四位數年份,如200七、2008 z表明天數,如156