應該是用wp_thumbnails_for_homepage()來判斷吧,
創(chuàng)新互聯(lián)建站自成立以來,一直致力于為企業(yè)提供從網(wǎng)站策劃、網(wǎng)站設計、成都網(wǎng)站建設、成都網(wǎng)站設計、電子商務、網(wǎng)站推廣、網(wǎng)站優(yōu)化到為企業(yè)提供個性化軟件開發(fā)等基于互聯(lián)網(wǎng)的全面整合營銷服務。公司擁有豐富的網(wǎng)站建設和互聯(lián)網(wǎng)應用系統(tǒng)開發(fā)管理經(jīng)驗、成熟的應用系統(tǒng)解決方案、優(yōu)秀的網(wǎng)站開發(fā)工程師團隊及專業(yè)的網(wǎng)站設計師團隊。
wp_thumbnails_for_homepage()如果沒有生成圖片,就返回為假
if(!wp_thumbnails_for_homepage()){
?
a href="?php the_permalink() ?" rel="bookmark" title="?php the_title(); ?"img src="?php echo get_post_meta($post-ID, 't_images', true);?" alt="?php the_title(); ?" width="180" height="120" //a
?
}
注:以下內容在WP
3.4+上測試通過current_user_can()的正確用法current_user_can()文檔中有一句話要注意一下Do
not
pass
a
role
name
to
current_user_can(),
as
this
is
not
guaranteed
to
work
correctly.意思是說傳遞用戶角色名稱(如author、contributor)作為參數(shù)不能100%保證返回正確的結果,正確的用法是傳遞$capability,從這個函數(shù)的表面意思看,參數(shù)是權限比參數(shù)是角色名稱更靠譜。所以,要根據(jù)不同角色擁有的權限來判斷用戶角色,用戶權限可以在Roles
and
Capabilities中找到。判斷用戶是否為管理員(Administrator)if(
current_user_can(
'manage_options'
)
)
{
echo
'The
current
user
is
a
administrator';
}判斷用戶是否為編輯(Editor)if(
current_user_can(
'publish_pages'
)
!current_user_can(
'manage_options'
)
)
{
echo
'The
current
user
is
an
editor';
}判斷用戶是否為作者(Author)if(
current_user_can(
'publish_posts'
)
!current_user_can(
'publish_pages'
)
)
{
echo
'The
current
user
is
an
author';
}判斷用戶是否為投稿者(Contributor)if(
current_user_can(
'edit_posts'
)
!current_user_can(
'publish_posts'
)
)
{
echo
'The
current
user
is
a
contributor';
}判斷用戶是否為訂閱者(Subscriber)if(
current_user_can(
'read'
)
!current_user_can(
'edit_posts'
)
)
{
echo
'The
current
user
is
a
subscriber';
}用$current_user判斷$current_user是WordPress的一個全局變量,當用戶登錄后,這個里面就會有用戶的角色和權限信息。當WordPress的init
action執(zhí)行后,就可以安全的使用$current_user全局變量了。在模板文件中判斷登錄用戶是否為作者(Author)global
$current_user;
if(
$current_user-roles[0]
==
'author'
)
{
echo
'The
current
user
is
an
author';
}
在functions.php中判斷用戶是否為作者(Author)add_action(
'init',
'check_user_role'
);
function
check_user_role()
{
global
$current_user;
if(
$current_user-roles[0]
==
'author'
)
{
echo
'The
current
user
is
an
author';
}
}
之所以要使用add_action(
'init',
'check_user_role'
);是因為$current_user這個全部變量到init
action執(zhí)行時才完成賦值,既然要讀它的內容,至少要等到它的內容準備好后再讀取。functions.php的代碼先與init
action執(zhí)行,所以在functions.php中直接寫global
$current_user是無法獲取用戶信息的。詳細信息可以參考《WordPress
Actions加載順序》。檢查用戶角色之前,還可以先檢查一下用戶是否登錄
有時候需要判斷wordpress站點是否設置了偽靜態(tài),即后臺固定鏈接設置中的選擇了非”默認”的結構。
下面看一下判斷方法:
若是只寫get_option(‘permalink_structure’) 判斷是否是自定義結構。