首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用钩子更改foogallery中的输出\输入模板?

如何使用钩子更改foogallery中的输出\输入模板?
EN

Stack Overflow用户
提问于 2017-08-18 16:13:15
回答 1查看 271关注 0票数 0

我需要更改输出篡改模板。例如:

现在我在数据库中存储了这个模板

代码语言:javascript
复制
<div id="foogallery-gallery-67" class="foogallery-container foogallery-default foogallery-link-image foogallery-lightbox-foobox-free spacing-width-10 hover-effect-zoom3  border-style-square-white alignment-center hover-caption-simple foogallery-default-loading">
    <a  href="http://wordpress.local/wp-content/uploads/2017/08/222-1.jpg" data-caption-title="Title" data-caption-desc="description text" data-attachment-id="128" class="">
        <img  src="http://wordpress.local/wp-content/uploads/cache/2017/08/222-1/705461751.jpg" width="150" height="150" />
    </a>
</div>

我需要添加一个data-*属性(data-custom)

代码语言:javascript
复制
<div id="foogallery-gallery-67" class="foogallery-container foogallery-default foogallery-link-image foogallery-lightbox-foobox-free spacing-width-10 hover-effect-zoom3  border-style-square-white alignment-center hover-caption-simple foogallery-default-loading">
    <a  href="http://wordpress.local/wp-content/uploads/2017/08/222-1.jpg" data-caption-title="Title" data-caption-desc="description text" data-attachment-id="128" data-custom="" class="">
        <img  src="http://wordpress.local/wp-content/uploads/cache/2017/08/222-1/705461751.jpg" width="150" height="150" />
    </a>
</div>

我知道我可以直接添加到数据库中,我感兴趣的是如何重新定义输出和输入函数,以便将来不会出现问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-25 17:40:07

我再一次回答我自己的问题

例如,我们有这样一个插件的结构:

代码语言:javascript
复制
class Plugin()
{
    public function __construct()
    {

    }
}

$startPlugin = new Plugin();

并且我们需要更改输出FooGallary模板。FooGallary有这个过滤器,谁可以改变输出的篡改foogallery_attachment_html_link_attributes。现在改变我们的类,帮助这个过滤器。

代码语言:javascript
复制
class Plugin()
{
    public function __construct()
    {
        add_filter('foogallery_attachment_html_link_attributes', array($this, 'addFoogalleryCategory'), 10, 3);
    }

    public function addFoogalleryCategory($attr, $args, $attachment)
    {
        $attr['data-category'] = 'category';
        return $attr;
    }
}

$startPlugin = new Plugin();

这很简单,但我没有立即找到解决方案。也许我帮了什么人。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45751761

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档