2017-10-17 54 views
0

我有WordPress的問題,我有腳本,檢查實際頁面的作者 get_the_author_meta('ID');WordPress的get_the_author_meta顯示1

這項工作之大時,例如頁面

mydomain.com/author/admin/然後作者ID爲1(因爲管理員必須ID 1)

mydomain.com/author/author2/然後作者ID爲2(因爲管理員必須ID 2)

mydomain.com/author/other-author/然後作者ID爲3(因爲管理員必須ID 3)

,但是當我在MYDOMAIN .com/blog /顯示所有作者的帖子,然後get_the_author_meta('ID')是1(它應該是空的或0)。所以,我的名單這複雜的局面,這就是:

-All

-admin

-author2

- 其他 - 作者

,因爲當我們在所有類別(不指定的作者),然後get_the_author_meta('ID')說實際的作者是admin,所以我的頁面作者列表不起作用。

代碼:

function contributors() { 
global $wpdb; 

$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users ORDER BY display_name"); 
$actualauthor = get_the_author_meta('ID'); 
echo $actualauthor; 
echo "<li><a href=\"/blog/\""; 

if ($actualauthor == '') { 
    echo " style=\"font-weight:bold;\""; 
} 
echo ">Wszyscy</a></li>"; 
foreach($authors as $author) { 
echo "<li>"; 
echo "<a href=\"".get_bloginfo('url')."/?author="; 
echo $author->ID; 
echo "\""; 
if ($actualauthor == $author->ID) { 
    echo " style=\"font-weight:bold;\""; 
} 
echo ">"; 
the_author_meta('display_name', $author->ID); 
echo " ("; 
echo count_user_posts($author->ID); 
echo ")"; 
echo "</a>"; 
echo "</li>"; 
} 
} 
+0

問題不明確 –

+0

更新我的問題 – Dawid

+0

如果是進口的管理,那麼你得到一禁止指定筆者就意味着默認 –

回答

0

試試這個:

function contributors() { 
    global $wpdb; 

    $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users ORDER BY display_name"); 
    $actualauthor = get_the_author_meta('ID'); 
    echo $actualauthor; 
    echo "<li><a href=\"/blog/\""; 

    //Check if on blog page 
    if(!is_page('blog')){ 
     if ($actualauthor == '') { 
      echo " style=\"font-weight:bold;\""; 
     } 
    } 
    echo ">Wszyscy</a></li>"; 
    foreach($authors as $author) { 
    echo "<li>"; 
    echo "<a href=\"".get_bloginfo('url')."/?author="; 
    echo $author->ID; 
    echo "\""; 
    if ($actualauthor == $author->ID) { 
     echo " style=\"font-weight:bold;\""; 
    } 
    echo ">"; 
    the_author_meta('display_name', $author->ID); 
    echo " ("; 
    echo count_user_posts($author->ID); 
    echo ")"; 
    echo "</a>"; 
    echo "</li>"; 
    } 
    } 
0

@msbodetti那是不行的,但使用您的意見,我編輯的代碼,現在一切正常,選擇類別時,另外(那麼該頁面不是'博客'),那麼作者「all」就會變成粗體。這裏是代碼:

function contributors() { 
global $wpdb; 

$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users ORDER BY display_name"); 
$actualauthor = get_the_author_meta('ID'); 
$category = get_category(get_query_var('cat')); 
$cat_id = $category->cat_ID; 
echo "<li><a href=\"/blog/\""; 
if(is_page('blog') || $cat_id){ 
     echo " style=\"font-weight:bold;\""; 
} 
echo ">Wszyscy</a></li>"; 
foreach($authors as $author) { 
echo "<li>"; 
echo "<a href=\"".get_bloginfo('url')."/?author="; 
echo $author->ID; 
echo "\""; 
if ($actualauthor == $author->ID) { 
    if(!is_page('blog')){ 
     echo " style=\"font-weight:bold;\""; 
    } 
} 
echo ">"; 
the_author_meta('display_name', $author->ID); 
echo " ("; 
echo count_user_posts($author->ID); 
echo ")"; 
echo "</a>"; 
echo "</li>"; 
} 

}