【问题标题】:Using WordPress plugins for custom post types?为自定义帖子类型使用 WordPress 插件?
【发布时间】:2015-10-27 07:56:02
【问题描述】:

我想为我的图片库添加一个简单的灯箱插件。图像正在像这样的名为 gallery-template 的模板中获取

<?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;
 ?>

我见过很多插件,但他们要求将图像添加到页面而不是从模板中获取它们,那么我怎样才能让它像这样工作呢?

【问题讨论】:

  • 有什么问题?你想让它做什么不做什么?
  • 只需将灯箱 jquery 加入队列,将 data-lightbox 添加到您的图像中,就可以了。

标签: javascript php jquery wordpress


【解决方案1】:

你可以在没有插件的情况下做到这一点。使用您想要的任何灯箱。我的例子是漂亮的照片。

<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;
 ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-15
    • 1970-01-01
    • 2017-04-04
    • 2016-12-21
    • 1970-01-01
    • 1970-01-01
    • 2017-01-03
    相关资源
    最近更新 更多