首页 文章

如何将缩略图图像链接到wordpress中的父博客

提问于
浏览
0

我正在显示由显示的用户在各自的 Profiles 页面上发布的最新10张图片(buddypress ..我正在使用此代码来提取图片:

$ media = get_posts(array(

'author'=> bp_displayed_user_id(),

'post_type'=>'附件',

'numberposts'=> 10,

'post_mime_type'=>'image / jpeg'));

foreach($ media as $ image){

list($ src)= wp_get_attachment_image_src($ image-> ID,'thumbnail');

echo'img src =“' . $ src . '”>';}

他们工作正常,但在这里我无法将图像链接到相应的博客文章..他们只是显示没有链接的图像..我想将所有这些图像链接到它的父母博客帖子..

谢谢..您的自愿帮助将受到高度赞赏..

1 回答

  • 0

    尝试下面的代码 .

    $media = get_posts(array(
    
        'author' => bp_displayed_user_id(),
    
        'post_type' => 'attachment',
    
        'numberposts' => 10,
    
        'post_mime_type' => 'image/jpeg' ));
    
        foreach ($media as $image) {
    
        list($src) = wp_get_attachment_image_src( $image->ID, 'thumbnail');
       #To add full image in the link
    
        list($fullImage) = wp_get_attachment_image_src( $image->ID, 'full');
    
        $parent = get_post_ancestors( $image->ID ); #Fetching the parent of the attachment
    
        $permalink = get_permalink($parent[0]); #Getting the permalink of the parent.
    
    
        echo '<a href="'.$fullImage.'"><img src="'.$src.'" ></a>';}
    

    Source, Codex

    Enjoy. Happy Coding.

相关问题