我想使用插件从joomla页面上的类别文章列表中删除整篇文章div [英] I want to remove an whole article div from category article listing on a joomla page using plugin

查看:73
本文介绍了我想使用插件从joomla页面上的类别文章列表中删除整篇文章div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类别页面,其中列出了joomla中属于该类别的所有文章。



我制作了一个自定义内容插件,这是用于在创建任何类型的文章时设置自定义字段,现在我可以在OnContentPrepare方法中查看/访问我在文章创建过程中保存的自定义值。



现在我希望我的插件隐藏/删除前端自定义字段值为1的文章。



但这不会影响任何后端值,如发布,标题,内容等只需显示:无CSS。



以下是我的插件代码:



已定义('_JEXEC')或死('限制访问');

类plgContentDtStatus扩展JPlugin

{

protected $ autoloadLanguage = true;

公共函数onContentPrepareForm($ form,$ data)

{

$ app = JFactory :: getApplication();

$ option = $ app-> input-> get('option');

开关($选项){

case'com_content':

if($ app-> isAdmin()){

JForm :: addFormPath(__ DIR__。'/ forms');

//根据类别显示特定表格

$ form-> loadFile(' content',false);

}

返回true;

}



返回true;

}



公共函数onContentPrepare($ context,& $ article,& $ params,$ page = 0)

{



if(isset($ article-> attribs)&&!empty($ article-> attribs)){

$ attr = json_decode($ article-> attribs);

/ *在此行之后我可以访问自定义字段值* /

}



if(isset($ attr-> is_done)&& $ attr-> is_done){



// -------------------------

$ article-> images = 0;

$ article-> published = 0;

$ tmp = json_decode($ params-> __ toString());

foreach($ tmp as $ key => $ val)

{

$ params-> set($ key,0);

$ article- > text ='';

}

/ *现在我正在尝试上面的代码来隐藏e文章不适用于所有模板。我想放置一个类或内联css来隐藏整篇文章,或者有没有办法跳过这篇文章并转到下一篇* /

// -------- -----------------

}



返回true;

}



}



请提前建议,谢谢。



我尝试过的事情:



i已将我的代码放在我尝试过的地方。

I have a category page which lists all articles belongs to that category in joomla.

I have made a custom content plugin, which is for setting a custom field while creating articles of any type, Now i can see/access in "OnContentPrepare" method the custom value which i saved during article creation.

Now i want my plugin to hide/remove article which have value 1 for custom field from frontend thats it.

But this shouldnt affect any backend values like publish, title, content e.t.c. Just "display:none" of CSS.

below is the code of my plugin:

defined ( '_JEXEC' ) or die ( 'Restricted access' );
class plgContentDtStatus extends JPlugin
{
protected $autoloadLanguage = true;
public function onContentPrepareForm($form, $data)
{
$app = JFactory::getApplication();
$option = $app->input->get('option');
switch($option) {
case 'com_content':
if ($app->isAdmin()) {
JForm::addFormPath(__DIR__ . '/forms');
//Show specific forms based on categories
$form->loadFile('content', false);
}
return true;
}

return true;
}

public function onContentPrepare($context, &$article, &$params, $page = 0)
{

if(isset($article->attribs) && !empty($article->attribs)){
$attr=json_decode($article->attribs);
/* After this line i can access the custom field value */
}

if(isset($attr->is_done) && $attr->is_done){

//-------------------------
$article->images=0;
$article->published=0;
$tmp=json_decode($params->__toString());
foreach($tmp as $key=>$val)
{
$params->set($key,0);
$article->text='';
}
/* Right now i am trying above code to hide articles not working for all templates. i want to place a class or inline css to hide whole div of article, or is there any way to skip the article and move to next one */
//-------------------------
}

return true;
}

}

Please suggest, Thanks in advance.

What I have tried:

i have placed my code what i have tried yet.

推荐答案

autoloadLanguage = true;

公共函数onContentPrepareForm(
autoloadLanguage = true;
public function onContentPrepareForm(


form,


数据)

{
data)
{


这篇关于我想使用插件从joomla页面上的类别文章列表中删除整篇文章div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆