我无意中在另一个stackexchange中发布了此问题的副本,但它被错误地标记为重复,并由使用弃用代码回答的另一个问题解决
因此,我将在Wordpress论坛上重新提问,那里可能有更多的专业知识
我正在尝试组合功能,但不知道如何实现
我正在成功地使用get\\u站点生成WP多站点子站点列表。
我希望还可以拉get\\u custom\\u logo来显示徽标,并为$site\\u description=get\\u bloginfo(“description”)之类的内容获取\\u bloginfo;
只是不知道如何合并GET。这起作用了
/** 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\');
谢谢你的帮助,谢谢
SO网友:Ittikorn S.
我假设您在多站点上使用的主题支持主题徽标功能。那么你可以简单地使用get_theme_mod(\'custom_logo\'). 请注意custom_logo 由主题开发人员命名,某些主题可能与其他主题不同。
<?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\');