wordpress判斷 wordpress判斷文章緩存更新

Wordpress 判斷字段內(nèi)容

應(yīng)該是用wp_thumbnails_for_homepage()來判斷吧,

創(chuàng)新互聯(lián)建站自成立以來,一直致力于為企業(yè)提供從網(wǎng)站策劃、網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計、電子商務(wù)、網(wǎng)站推廣、網(wǎng)站優(yōu)化到為企業(yè)提供個性化軟件開發(fā)等基于互聯(lián)網(wǎng)的全面整合營銷服務(wù)。公司擁有豐富的網(wǎng)站建設(shè)和互聯(lián)網(wǎng)應(yīng)用系統(tǒng)開發(fā)管理經(jīng)驗、成熟的應(yīng)用系統(tǒng)解決方案、優(yōu)秀的網(wǎng)站開發(fā)工程師團隊及專業(yè)的網(wǎng)站設(shè)計師團隊。

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

?

}

WordPress:如何判斷登錄用戶的角色

注:以下內(nèi)容在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%保證返回正確的結(jié)果,正確的用法是傳遞$capability,從這個函數(shù)的表面意思看,參數(shù)是權(quán)限比參數(shù)是角色名稱更靠譜。所以,要根據(jù)不同角色擁有的權(quán)限來判斷用戶角色,用戶權(quán)限可以在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的一個全局變量,當(dāng)用戶登錄后,這個里面就會有用戶的角色和權(quán)限信息。當(dāng)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í)行時才完成賦值,既然要讀它的內(nèi)容,至少要等到它的內(nèi)容準(zhǔn)備好后再讀取。functions.php的代碼先與init

action執(zhí)行,所以在functions.php中直接寫global

$current_user是無法獲取用戶信息的。詳細信息可以參考《WordPress

Actions加載順序》。檢查用戶角色之前,還可以先檢查一下用戶是否登錄

wordpress判斷是否啟用偽靜態(tài)或固定鏈接類型

有時候需要判斷wordpress站點是否設(shè)置了偽靜態(tài),即后臺固定鏈接設(shè)置中的選擇了非”默認”的結(jié)構(gòu)。

下面看一下判斷方法:

若是只寫get_option(‘permalink_structure’) 判斷是否是自定義結(jié)構(gòu)。

當(dāng)前標(biāo)題:wordpress判斷 wordpress判斷文章緩存更新
分享路徑:http://www.muchs.cn/article34/dohcpse.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗、網(wǎng)站制作App開發(fā)、服務(wù)器托管、全網(wǎng)營銷推廣、網(wǎng)站收錄

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站