在博客中将图片链接到帖子

时间:2022-01-07 19:37:33

My posts have an image in them. They are shown in the homepage of my site. Each post has a picture, a description about the post, and a "more" button which takes the user to the full article.

我的帖子里面有一张图片。它们显示在我网站的主页上。每个帖子都有一张图片,一个关于帖子的描述,以及一个“更多”按钮,它将用户带到完整的文章。

My issue is that I want to make the image link to the full post. I want the image to function as the "more" button.

我的问题是我想将图像链接到完整的帖子。我希望图像作为“更多”按钮。

I have tried using jQuery, wrap() function, linking the image in the article itself, nothing has worked out so far.

我已经尝试过使用jQuery,wrap()函数,链接文章本身的图像,到目前为止还没有任何工作。

The code for the image is just:

图像的代码只是:

 <img src="random.jpg" class="YTimgs">

Does anybody know how I can get this to work? I have been working on this issue and have not found the correct solution. I hope someone helps me out. Or at least please point me in the right direction.

有谁知道我怎么能让这个工作?我一直在研究这个问题,但没有找到正确的解决方案。我希望有人帮助我。或者至少请指出我正确的方向。

Thanks a lot.

非常感谢。

2 个解决方案

#1


1  

Updated fiddle: http://jsfiddle.net/5md7p9L7/7/

更新小提琴:http://jsfiddle.net/5md7p9L7/7/

<img src="http://lorempixel.com/400/200/"/>
<a class="link" href="http://google.com" target="_blank">The picture and this text are both links to the same page :)</a>

jQuery

$('img').click(function(){
    var link =$(this).next().attr('href');
    window.open(link);   
});

#2


1  

Some of your images have class YTimg, others have YTimgs ... give it only one class:

你的一些图像有YTimg类,其他图像有YTimgs ...只给它一个类:

$(document).on("click", "img.YTimgs", function(){
    $(this).closest("div.post").find(".jump-link").find("a").trigger("click");
});

And this should do the tricky

这应该是棘手的

#1


1  

Updated fiddle: http://jsfiddle.net/5md7p9L7/7/

更新小提琴:http://jsfiddle.net/5md7p9L7/7/

<img src="http://lorempixel.com/400/200/"/>
<a class="link" href="http://google.com" target="_blank">The picture and this text are both links to the same page :)</a>

jQuery

$('img').click(function(){
    var link =$(this).next().attr('href');
    window.open(link);   
});

#2


1  

Some of your images have class YTimg, others have YTimgs ... give it only one class:

你的一些图像有YTimg类,其他图像有YTimgs ...只给它一个类:

$(document).on("click", "img.YTimgs", function(){
    $(this).closest("div.post").find(".jump-link").find("a").trigger("click");
});

And this should do the tricky

这应该是棘手的