當用戶在我的網站上注冊時,系統會自動創建一個帖子(在自定義帖子型別下),該用戶被指定為該帖子的作者。這篇文章本質上是用戶的“個人資料頁面”。
任何用戶都可以看到任何其他用戶的個人資料頁面。但是,如果它屬于登錄用戶,我希望在個人資料頁面上顯示一個按鈕。
換句話說:如果登錄用戶是當前正在查看的帖子的作者(在前端),則顯示按鈕。
下面是我最接近實作我需要做的事情 - 我創建了一個帶有 css id 的按鈕#profile_edit_button并默認使用display:none. 下面的代碼“取消隱藏”按鈕,但在所有個人資料頁面上。它還會拋出以下錯誤:
警告:未定義變數 $user_session_id 警告:未定義變數 $author_id
我使用的代碼如下。任何指導將不勝感激。
if($user_session_id == $author_id) {
?>
<style type="text/css">
#profile_edit_button {
display: flex !important;
}
</style>;
<?php } ?>
uj5u.com熱心網友回復:
試試下面的代碼。代碼將進入您的活動主題functions.php 檔案。
function current_user_is_post_author(){
if( is_single() ){
global $post;
if( get_current_user_id() == $post->post_author ) { ?>
<style type="text/css">
#profile_edit_button {
display: flex !important;
}
</style>;
<?php } }
}
add_action( 'wp_head', 'current_user_is_post_author', 10, 1 );
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/329337.html
標籤:php css WordPress的 功能 元素
上一篇:空表頭
