wordpress gallery - 如何自定义/添加jquery?

时间:2012-05-29 07:21:24

标签: jquery wordpress gallery

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

1 个答案:

答案 0 :(得分:0)

您可以过滤默认的图库短代码,并将其替换为您自己的短代码功能。

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;