Javascript 为自定义帖子类型使用WordPress插件?
我想为我的图像库添加一个简单的灯箱插件。图像是在一个名为gallery template的模板中获取的,如下所示Javascript 为自定义帖子类型使用WordPress插件?,javascript,php,jquery,wordpress,Javascript,Php,Jquery,Wordpress,我想为我的图像库添加一个简单的灯箱插件。图像是在一个名为gallery template的模板中获取的,如下所示 <?php $args=array('post_type' => 'gallery'); $query= new WP_Query($args); while ($query-> have_posts() ) : $query->the_post()?> <
<?php
$args=array('post_type' => 'gallery');
$query= new WP_Query($args);
while ($query-> have_posts() ) : $query->the_post()?>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
<h1 class="product_txt"><?php the_title();?></h1>
<a href=''><?php the_post_thumbnail( 'full', array( 'class' => 'product_img') );?></a>
</div>
<?php
endwhile;
?>
我见过很多插件,但他们要求将图像添加到页面中,而不是从模板中获取图像,因此我如何才能使其像这样工作?没有插件也可以这样做。使用任何你想要的灯箱。我的例子是普雷托
<script src="js/jquery.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" media="screen" charset="utf-8" />
<script src="js/jquery.prettyPhoto.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$("a[rel^='prettyPhoto']").prettyPhoto();
});
</script>
<?php
$args=array('post_type' => 'gallery');
$query= new WP_Query($args);
while ($query-> have_posts() ) : $query->the_post()?>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
<?php // Get image url
$attachment = wp_get_attachment_image_src( get_post_thumbnail_id($query->ID), 'full' );
$url = $attachment['0']; ?>
<h1 class="product_txt"><?php the_title();?></h1>
<a rel='prettyPhoto' href='<?php echo $url; ?>'><?php the_post_thumbnail( 'full', array( 'class' => 'product_img') );?></a>
</div>
<?php
endwhile;
?>
$(文档).ready(函数(){
$([rel^='prettypto']);
});
有什么问题吗?它没有做什么您希望它做的事情?只需将lightbox jquery排队,将数据lightbox
添加到您的图像中,就可以了。