在WordPress中使用标题文本设置花哨的框标题

Set fancybox title using caption text in wordpress

本文关键字:标题 设置 文本 WordPress      更新时间:2023-09-26

Fancybox 有一个 title 属性,该属性从标题标签中获取值

  jQuery.fn.getTitle = function() { 
var arr = jQuery("a.fancybox");
jQuery.each(arr, function() {
    var title = jQuery(this).children("img").attr("title");
    jQuery(this).attr('title',title);
})

}

我希望能够复制标题而不是标题的属性

         <dl class="gallery-item">
        <dt class="gallery-icon portrait">
            <a href="***.jpg" class="fancybox" rel="fancybox" title="">
                              <img  src="*****.jpg" alt="item name"></a>
        </dt>
        <dd class="wp-caption-text gallery-caption">
             item name
        </dd>
         </dl>

到目前为止,我已经尝试将标题更改为

          jQuery( this ).children("img").next().text();
                  and 
         jQuery( this ).parent("dt").next().text();  

但这并没有帮助。任何其他使其工作的方法。

我遇到了同样的问题。让它像这样工作:

$('dl.gallery-item').each(function(){
    var caption = $(this).find('dd.wp-caption-text').text();
    $(this).find('a').attr('title',caption);
    $(this).find('dd.wp-caption-text').remove();    
});