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

查看:141
本文介绍了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.

有关内容事件的将来参考,请查看文件" plugins \ content \ example \ example.php "

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

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

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