2014-12-07 83 views
0

我有一个WordPress的网站,我在页面上显示图像。 当你点击一个图像时,我想要一个弹出窗口来显示与图像相关的图像和内容。 每个图像和内容都是一个帖子。 我试图使用代码:点击图片显示图片和弹出内容

$post_id = get_the_ID(); 
$post = get_post($post_id, ARRAY_A); 
$title = $post['post_title']; 

获取内容的标题。 然后,我需要使用jQuery,所以当你点击图片的标题(以及内容)显示。 我在哪个文件中放置jQuery代码? 如何链接图像,所以onclick()它显示弹出?

+0

你需要在这里尝试一些东西....你可以创建一个隐藏的div与信息和使用jquery显示内容点击时,像延迟关闭窗口。要么或者使用ajax来获取内容。 – David 2014-12-08 01:00:02

+0

你有我如何使用jquery显示点击内容的例子吗?我不知道如何做到这一点? – LTech 2014-12-08 09:37:25

回答

0

将此代码添加到您的模板的底部。

<script type="text/javascript"> 

jQuery(document).ready(function(){ // wait until all document html loaded 

    jQuery('.unhide').click(function(){ // attach a function to elements with the class "unhide" 
     jQuery(this).closest('.holder').find('.hidden').show(); // Look for the closest parent of this item with the class "holder" and find the hidden div, show it 
     jQuery(this).closest('.holder').find('.hidden').delay(800).hide(1000); // find the same element and close after delay, take 1000 ms to close. 
    }); 

}); 
</script> 

的jsfiddle:http://jsfiddle.net/5hrcsguu/1/,它假定父项目包含隐藏的内容和一个按钮,单击事件使用

简单的例子。 http://api.jquery.com/有每个功能的例子。除此之外,您需要了解的仅仅是使用js的脚本标记,并使用jQuery而不是使用的$符号。