最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

multisite - Display site description instead of site name

programmeradmin4浏览0评论

I'm wondering how to display all the network sites in WP Multisite by displaying site description instead of site name. Below is the code provided by the expert in WP in this community. It's now displaying site name. What code should I change in order to make the list displaying all the sites with site description?

function wpse365255_print_sites() {
    $args = array(
        'number' => 10000, // if you've got more than 10,000 sites, 
                           //you can increase this
        'public'        => 1,
        'spam'          => 0,
        'deleted'       => 0,
        'archived'      => 0,
        'site__not_in'  => array( 1, 2 ), 
        // this will exclude sites with ID 1 and 2
    );
    $sites = get_sites( $args ); // will return an array of WP_Site objects 
    $list = '';
    foreach ( $sites as $site ) {
        $details = get_blog_details( $site->blog_id );
        if ( ! empty( $details ) ) {
            $list .= '<li>';
            $list .= '<a href="' . $details->siteurl . '">';
            $list .= $details->blogname;
            $list .= '</a>';
            $list .= '</li>';
        }
    }
    if ( ! empty( $list ) ) {
        echo '<ul>' . $list . '</ul>';
    }
}

I tried to change the blogname to blogdescription but the site description not showing up. I look forward to answers from the experts here. Thank you!

I'm wondering how to display all the network sites in WP Multisite by displaying site description instead of site name. Below is the code provided by the expert in WP in this community. It's now displaying site name. What code should I change in order to make the list displaying all the sites with site description?

function wpse365255_print_sites() {
    $args = array(
        'number' => 10000, // if you've got more than 10,000 sites, 
                           //you can increase this
        'public'        => 1,
        'spam'          => 0,
        'deleted'       => 0,
        'archived'      => 0,
        'site__not_in'  => array( 1, 2 ), 
        // this will exclude sites with ID 1 and 2
    );
    $sites = get_sites( $args ); // will return an array of WP_Site objects 
    $list = '';
    foreach ( $sites as $site ) {
        $details = get_blog_details( $site->blog_id );
        if ( ! empty( $details ) ) {
            $list .= '<li>';
            $list .= '<a href="' . $details->siteurl . '">';
            $list .= $details->blogname;
            $list .= '</a>';
            $list .= '</li>';
        }
    }
    if ( ! empty( $list ) ) {
        echo '<ul>' . $list . '</ul>';
    }
}

I tried to change the blogname to blogdescription but the site description not showing up. I look forward to answers from the experts here. Thank you!

Share Improve this question edited May 8, 2020 at 7:41 Jornes asked May 8, 2020 at 6:55 JornesJornes 7535 gold badges12 silver badges31 bronze badges 1
  • You may try changing $details->blogname to get_blog_option( $site->blog_id, 'blogdescription') – 西門 正 Code Guy - JingCodeGuy Commented May 8, 2020 at 10:03
Add a comment  | 

1 Answer 1

Reset to default 2

get_blog_option() return blog info by supplying blog id and blog option name. So you may try changing the blog name variable from

$details->blogname to get_blog_option( $site->blog_id, 'blogdescription')

in the loop

Becauae get_blog_details() does not add the description from option to its output object. So it let is needed to manually fetch additional information.

By default, the get_blog_details() only returns the following details of the site

  • blogname
  • siteurl
  • post_count
  • home
发布评论

评论列表(0)

  1. 暂无评论