1

I inadvertently posted a duplicate of this question in the other stackexchange - but it was MISTAKENLY marked as duplicated and solved by a different question answered using deprecated code

So I will reask in the Wordpress forum where there may be more expertise

I'm trying to combine functions - and don't know how it is done

I'm successfully using get_sites to produce a list of WP Multisite subsites.

I'm hoping to also pull get_custom_logo to display the logo, and get_bloginfo for things like $site_description = get_bloginfo( 'description' );

just don't know how to merge the gets. this is working

/** get sites */
function make_list_shortcode() {
$subsites = get_sites(
[
'public'  => 1,
'number'  => 500,
'orderby' => 'last_updated',
'order'   => 'DESC',
]
);
if ( ! empty ( $subsites ) ) {
$html = '<ul class="icon-bullets-greater">';
foreach( $subsites as $subsite ) {
$subsite_id = $subsite->blog_id;
$subsite_name = get_blog_details( $subsite_id )->blogname;
$subsite_link = get_blog_details( $subsite_id )->siteurl;
$subsite_domain = get_blog_details( $subsite_id )->domain;
$subsite_path = get_blog_details( $subsite_id )->path;
$html .= '<li style="list-style: none!important;" class="site-' . 
$subsite_id . '" ><a href="' . $subsite_link . '" target="_blank">' . 
$subsite_name . '</a> at ' . $subsite_domain . '' . $subsite_path . ' </li>';
}
$html .= '</ul>';
return $html;
}
}
add_shortcode('list_sites', 'make_list_shortcode');

appreciate any help, thanks

1

modifying to this, works thanks

// Switch to Blog switch_to_blog( $subsite->blog_id ); $site_description = get_bloginfo( 'description' ); restore_current_blog();

still working on calling the logos

0

I assumed the theme you are using on multi-site is supporting the Theme Logo feature. Then you could simply use get_theme_mod('custom_logo'). Please note that the custom_logo is named by the theme developer, some themes may be different than others.

<?php
/** get sites */

function make_list_shortcode()
    {
    $subsites = get_sites(['public' => 1, 'number' => 500, 'orderby' => 'last_updated', 'order' => 'DESC', ]);
    if (!empty($subsites))
        {
        $html = '<ul class="icon-bullets-greater">';
        foreach($subsites as $subsite)
            {
            $subsite_id = $subsite->blog_id;
            $subsite_name = get_blog_details($subsite_id)->blogname;
            $subsite_link = get_blog_details($subsite_id)->siteurl;
            $subsite_domain = get_blog_details($subsite_id)->domain;
            $subsite_path = get_blog_details($subsite_id)->path;

            // Switch to Blog
            switch_to_blog( $subsite->blog_id );
            $custom_logo_id = get_theme_mod( 'custom_logo' );
            $logo = wp_get_attachment_image_src( $custom_logo_id , 'full' );

            // Added the image tag and src path
            $html.= '<li style="list-style: none!important;" class="site-' . $subsite_id . '" ><img src="'.$logo.'" /><a href="' . $subsite_link . '" target="_blank">' . $subsite_name . '</a> at ' . $subsite_domain . '' . $subsite_path . ' </li>';
            }

        $html.= '</ul>';
        return $html;
        }
    }

add_shortcode('list_sites', 'make_list_shortcode');
  • thanks -- the switch_to_blog is breaking the layout no matter what I try there --- I'm wondering if restore_current_blog(); is required, but I can't figure out how/where to implement that – Trip Vendors Inc Sep 13 '18 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.