2017-01-12 17 views
1

私はonContentPrepareイベントを使ってこの[test]を他のテキストに変更します。prinf htmlのようなwordpressショートコードは変わりません。簡単なショートコードプラグインを作成するJoomla

どうしたのですか?

これはあなたのプラグインではなく、コンテンツのグループ検索であり、

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

を変更shortcodejd.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>[email protected]</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> 

このshortcodejd.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; 
    } 
} 

答えて

2
この機能で

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

あなたからこの$行を手に入れました。代わりに$ article-> textを使用してください。 @Yolethはあなたが内容に置き換えるしようとしているように、コンテンツのプラグインではなく、検索プラグインを持っている必要が指摘したように、あなたの関数はまた

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

のようになります。

+0

聖なる..私はそれを見なかった、ありがとう! – metalbox

0

であり、あなたがしていますあなたのプラグインが有効になっていることを確認してください。

関連する問題