【问题标题】:wordpress gallery - how can I customize it/add jquery to it?wordpress 画廊 - 我如何自定义它/添加 jquery 到它?
【发布时间】:2012-05-29 17:03:29
【问题描述】:

您好,我正在尝试通过添加 jquery 来循环浏览我的图像而不是将其显示为单个图片链接来操作 wordpress 中的默认图库。但是,我似乎找不到要更改的文件 - 我想弄清楚如何自定义默认画廊(最好没有插件)。任何想法将不胜感激。

【问题讨论】:

    标签: jquery wordpress gallery


    【解决方案1】:

    您可以过滤默认画廊简码,并用您自己的简码函数替换它。

    add_filter( 'post_gallery', 'your_gallery_func', 10, 2);

    your_gallery_func 中,您需要模仿默认图库并提取 atts:

    /*
    * Extract default gallery settings
    */
    extract(shortcode_atts(array(
        'order'      => 'ASC',
        'orderby'    => 'menu_order ID',
        'id'         => $post->ID,
        'itemtag'    => 'dl',
        'icontag'    => 'dt',
        'captiontag' => 'dd',
        'columns'    => 3,
        'size'       => 'thumbnail',
        ), $attr));
    

    接下来,您需要获取帖子中附加的所有图片,如果没有则返回:

    $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
        if ( empty( $attachments ) )
            return '';
    

    接下来编写您想要输出的代码,将其分配给一个变量,然后在函数结束时返回它。

    这只是一个例子:

    /**
     * Open the gallery <div>
     */
    $output .= '<div id="gallery-'.$id.'" class="content gallery gallery-'.$id.'">'."\n";
    $output .= '<div id="thumbs" class="navigation">'."\n";
    
    /**
     * Loop through each attachment
     */
    foreach ( $attachments as $id => $attachment ) :
    
    /**
     * Open each gallery item
     */
    $output .= "\n\t\t\t\t\t<li class='gallery-item'>";
    $output .= '<a class="thumb" href="' .  $link[0] . '" title="' . $title . '">';
    $output .= '<img src="' . $img[0] . '" alt="' . $title . '" title="' . $title . '" />';
    $output .= '</a>';
    /**
     * Close individual gallery item
     */
    $output .= "\n\t\t\t\t\t</li>";
    
        endforeach;
    
    /**
     * Close gallery and return it
     */
     $output .= '</ul><!--.thumbs-->'."\n";
     $output .= '</div><!--#gallery-wrap-->'."\n";
    
        return $output;
    

    【讨论】:

      猜你喜欢
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多