我是新手,也有Wordpress的新手!,我为艺术家和设计师管理着一个多作家博客,所以,我只是在想这是不可能还是不可能!
我想做的是创建带有自定义打开图形的Facebook共享按钮,以在og:image中获取多个图像(作者头像和最近的9个最新帖子缩略图):image:/ mmmm也许我疯了吧? :)
我试图用下面的简单图像来解释
这就是我所做的,我不知道这是否是正确的方法!
我被困在这里,有什么建议,谢谢!
function ST4_get_FB_image() {
global $post;
$author = get_the_author_meta( 'ID' );
$profile = get_userdata($author);
$args = array( 'numberposts' => '9', 'author' => $profile->ID );
$recent_posts = wp_get_recent_posts($args);
while( $recent_posts->have_posts() ) {
$recent_posts->the_post() ;
if ( has_post_thumbnail() ) {
$post_thumbnail_id = get_post_thumbnail_id( $recent_posts->ID );
$post_thumbnail_img = wp_get_attachment_image_src( $post_thumbnail_id, array(100,100));
return $post_thumbnail_img[0];
}
}
wp_reset_postdata();
}
function ST4FB_header() {
global $post;
if ( is_author ( ) ) {
$author = get_the_author_meta( 'ID' );
$profile = get_userdata($author);
$url = get_author_posts_url($profile->ID);
$avatar = get_avatar($profile->ID, 200);
$artist_description = $description = get_the_author_meta('description', $profile->ID);
$post_featured_image = ST4_get_FB_image($post->ID);
$title = str_replace(' ', '%20', get_the_author_meta('display_name', $profile->ID));
$blog_title = get_bloginfo('name');
$content_all_images .='
<div class="row">
<div class="column">'.$avatar.'</div>
<div class="column">'.$post_featured_image.'</div>
</div>';
return $content_all_images;
?>
<style>
.column {
float: left;
width: 50%;
}
.row:after {
content: "";
display: table;
clear: both;
}
</style>
<?php
?>
<meta property="og:title" content="<?php echo $title; ?>" />
<meta name="description" content="<?php echo $artist_description; ?>" />
<meta property="og:url" content="<?php echo $url; ?>" />
<meta property="og:image" content="<?php echo $content_all_images; ?>"/>
<?php
}
}
add_action('wp_head', 'ST4FB_header');
function cgaz_vs_artists() {
if ( function_exists( 'ST4FB_header' ) ) {
$content .='
<div id="social-share">
<a href="https://www.facebook.com/sharer.php?u='.$url.'" target="_blank" class="facebook"><i class="fa fa-facebook"></i> <span>#CGArtZone_VS_Artists</span></a>
</div>';
return $content;
}
}
add_shortcode('cgaz_vs_artists', 'cgaz_vs_artists');