这是我的插件代码:
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
// Import library dependencies
jimport('joomla.plugin.plugin');
class plgContentHideArticles extends JPlugin
{
/**
* Constructor
*/
function plgContentHideArticles( &$subject, $config )
{
parent::__construct( $subject, $config );
}
/**
* Example prepare content method
*
* Method is called by the view
*
* @param object The article object. Note $article->text is also available
* @param object The article params
* @param int The 'page' number
*/
function onPrepareContent( &$article, &$params, $limitstart )
{
global $mainframe;
}
function onBeforeDisplayContent( &$article, &$params, $limitstart )
{
global $mainframe;
//add your plugin codes here
return 'test';
//return a string value. Returned value from this event will be displayed in a placeholder.
// Most templates display this placeholder after the article separator.
}
}
这是针对 xml 文件的:
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.1" type="plugin" group="content">
<name>Content - HideArticles</name>
<author>Saleh Zamzam</author>
<creationDate>2014-11-23 15:33:47</creationDate>
<license>MIT License</license>
<authorEmail>szamdev@gmail.com</authorEmail>
<authorUrl>www.example.com</authorUrl>
<version>1.0.0</version>
<description>Hide Custom Articles from Home page</description>
<files>
<filename plugin="hide_articles">hide_articles.php</filename>
</files>
<languages>
<language tag="en-GB">language/en-GB/en-GB.hide_articles.sys.ini</language>
<language tag="en-GB">language/en-GB/en-GB.hide_articles.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="Settings" label="Settings">
<field name="Ids" type="text" default="" label="Articles Ids" description="" size="100"/>
</fieldset>
</fields>
</config>
</extension>
该事件永远不会被触发。
请注意,插件已成功安装,没有任何错误消息。
我的主要想法是我想从主页隐藏自定义文章,我将根据视图来做到这一点。
$view = JFactory::getApplication()->input->getString('view', '');
知道问题出在哪里吗?
Joomla 3.x不会触发onPrepareContent事件。
此事件在旧版本的 Joomla 中触发。
使用 onContentPrepare 事件而不是 onPrepareContent
onBeforeDisplayContent 事件也是如此。
有关所有与内容相关的事件,请参阅此链接。