Antispambot()
使用該函式代替HTML標題,可以讓你的email地址不被過濾掉。
$email= 'mymail@mail.com'; echo'You can contact me at '. antispambot( $email) . ' any time'.
Human_time_diff()
該函式使用文章釋出日期為第一討論日期,當前日期為第二日期。
echo'This post was published '. human_time_diff( get_the_time( 'U'), current_time( 'timestamp') ) . ' ago';
Get_post_meta()
該功能很好用,但是卻不好操作,省略第二和第三引數,可以找出一篇文章的所有後設資料。
$all_meta= get_post_meta( 14 );
Wp_upload_bits()
直接上傳檔案功能,不需要你將檔案傳到資料夾或者WP媒體選項,非常方便。
$upload= wp_upload_bits( $file['name'], null, file_get_contents( $file['tmp_name'] ) );
Get_post_field()
該函式可以在單一文章中索檢單個欄位值。
This post has <!--?php echoget_post_field( 'comment_count', 4124 ) ?--> comments.
Wpautop()
該函式封裝段落內容。
<h2>What Our Users Say</h2> <!--?php echowpautop( $user_comment) ?-->
Wp_is_mobile()
該命名函式,在使用者使用移動裝置時會開啟檢測,顯示相應內容。
<!--?php if( wp_is_mobile() ) : ?--> Visit our website on your desktop fora richer user experience <!--?php endif?-->
DOING_AJAX
你可以使用該函式識別呼叫AJAX和常規工作。
if(defined('DOING_AJAX') && DOING_AJAX) { echo'done'; die() } else{ }
Wp_redirect()
設定URL重定向,並且設定狀態程式碼,也可以處理永久重定向。
// For a URL which is no longer in use wp_redirect( 'http://website.com/new-url/', 301 );
Paginate_links()
在文章列表最後顯示。前一個/下一個連結。WP-PageNavi替代頁碼。
global$wp_query; $big= 999999999; // need an unlikely integer echopaginate_links( array( 'base'=> str_replace( $big, '%#%', esc_url( get_pagenum_link( $big) ) ), 'format'=> '?paged=%#%', 'current'=> max( 1, get_query_var('paged') ), 'total'=> $wp_query->max_num_pages ) );
總結
在我們不知道的 WordPress 函式海洋,這只是很小的一部分。我也會繼續發掘分享,如果你有新發現,歡迎分享!
來自:慧都控制元件網
相關閱讀
評論(1)