0

我尝试这个来获取作者昵称:

    <h2>Articoli di: <span class="nome-autore"><?php global $wpdb, $blog_id;

$blogs = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM wp_blogs ORDER BY blog_id" ) );

foreach ($blogs as $blog){

if(wp_count_posts == 0){
    switch_to_blog($blog->blog_id);} else 
    if(wp_count_posts > 0){

    echo $curauth->nickname; }?></span></h2>

然后这是元描述:

<p>Su di me: <span class="descrizione-autore">"<?php global $wpdb, $blog_id; $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM wp_blogs ORDER BY blog_id" ) );

foreach ($blogs as $blog){

if(wp_count_posts == 0){
    switch_to_blog($blog->blog_id);} else 
    if(wp_count_posts > 0){

    echo  the_author_meta( 'description' ); ?>"</span></p>

但问题是它显示了每个 blog_id 的所有昵称和描述。如何只选择一个值进行显示?

4

1 回答 1

0

您需要首先收集所有博客 ID,然后遍历它们。这是未经测试的

global $wpdb, $blog_id;

$blogs = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM wp_blogs ORDER BY blog_id" ) );

foreach ($blogs as $blog){

    switch_to_blog($blog->blog_id);

    $blogusers = get_users('orderby=nicename');

    foreach ($blogusers as $user) {
        echo '<li>' . $user->description . '</li>';
    }

    restore_current_blog();
}
于 2013-10-13T11:26:12.170 回答