Joomla 插件:如何获取文章标题和文章 ID [英] Joomla plugin : how to get article title and article id

查看:22
本文介绍了Joomla 插件:如何获取文章标题和文章 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Joomla 1.6 中开发了简单的插件我坚持:如何获取文章标题和文章网址.

I have developed on simple plugin in Joomla 1.6 I stuck at : How to get article title and article url.

如果尝试打印以下语句,我没有得到任何输出:

I am getting no output if tried to print below statement:

echo $article->title;
echo $article->id;

我已经在php文件中写了这个,没有使用MVC架构.Joomla 管理端是否还有其他设置需要做?

I have written this in php file, not used MVC architecture. Is there any other settings need to do in Joomla admin side ?

请建议您提取文章标题和文章网址的指针.

Please suggest your pointers for extracting article title and article url.

提前致谢!

普文

推荐答案

我试过:

public function onContentPrepare($context,&$article, &$params, $limitstart) {
 echo JRequest::getVar('id');
}

我仍然没有得到 ID.对吗?

文章在您的第二个参数 ($article) 中加载.在此事件 (onContentPrepare) 上,您可以访问的唯一属性是 $article->text.

The article is loaded in your second argument ($article). Being on this event (onContentPrepare), the only property you can access is $article->text.

为了适合您的目的(获取文章 ID 和标题),您需要使用另一个事件,称为onContentBeforeDisplay".

For suiting your purpose (getting the article id and title) you will want to use another event, called "onContentBeforeDisplay".

public function onContentBeforeDisplay($context, &$article, &$params, $limitstart)

这里您(再次)通过第二个参数传递了文章,但现在您可以访问诸如 $article->id$article->title 和许多其他.

Here you have (again) the article passed through the second argument, but now you have access to properties like $article->id, $article->title and many others.

有关内容事件的未来参考,请查看文件pluginscontentexampleexample.php"

For future references on content events, take a look at the file "pluginscontentexampleexample.php"

这篇关于Joomla 插件:如何获取文章标题和文章 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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