【问题标题】:Create simple Shortcode Plugin Joomla创建简单的简码插件 Joomla
【发布时间】:2017-05-28 04:11:11
【问题描述】:

我使用 onContentPrepare 事件将此 [test] 更改为其他文本或 prinf html,例如 wordpress 短代码,但没有任何变化。

怎么了?

这是简码jd.xml

<?xml version="1.0" encoding="utf-8"?>
    <extension version="3.1" type="plugin" group="search">
        <name>shortcodejd</name>
        <author>Joomla! Project</author>
        <creationDate>November 2005</creationDate>
        <copyright>Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved.</copyright>
        <license>GNU General Public License version 2 or later; see LICENSE.txt</license>
        <authorEmail>admin@joomla.org</authorEmail>
        <authorUrl>www.joomla.org</authorUrl>
        <version>3.1.0</version>
        <description>SHORTCODEJD</description>
        <files>
            <filename plugin="shortcodejd">shortcodejd.php</filename>
            <filename>index.html</filename>
        </files>
        <languages>
            <language tag="en-GB">en-GB.shortcodejd.ini</language>
            <language tag="en-GB">en-GB.shortcodejd.sys.ini</language>
        </languages>
        <config>

        </config>
    </extension>

还有这个简码jd.php

defined('_JEXEC') or die;


class PlgContentShortcodejd extends JPlugin
{
 protected $autoloadLanguage = true;


    public function onContentPrepare($context, &$article, &$params, $limitstart)
    {
        $article->text = str_replace("[test]","<h1>Hi</h1>",$row->article);
        return true;
    }
}

【问题讨论】:

    标签: joomla joomla3.0 joomla-extensions


    【解决方案1】:

    您的插件在组搜索而不是内容,更改

    <extension version="3.1" type="plugin" group="search">
    To  
    <extension version="3.1" type="plugin" group="content">
    

    您确定您的插件已启用吗?

    【讨论】:

      【解决方案2】:

      在这个函数中

      public function onContentPrepare($context, &$article, &$params, $limitstart)
          {
              $article->text = str_replace("[test]","<h1>Hi</h1>",$row->article);
              return true;
          }
      

      你是从哪里得到这个 $row 的。相反,只需使用 $article->text。你的函数应该是这样的

      public function onContentPrepare($context, &$article, &$params, $limitstart)
              {
                  $article->text = str_replace("[test]","<h1>Hi</h1>",$article->text);
                  return true;
              }
      

      正如@Yoleth 指出的,你需要一个内容插件而不是搜索插件,因为你要替换内容。

      【讨论】:

      • 天啊..,我没看到,谢谢!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-05
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      相关资源
      最近更新 更多