Joomla插件:如何获取文章标题和文章id
我在 Joomla 1.6 中开发了简单的插件 我坚持:如何获取文章标题和文章网址。
如果尝试打印以下语句,我不会得到任何输出:
echo $article->title;
echo $article->id;
我已经在 php 文件中编写了此内容,未使用 MVC 架构。 Joomla 管理端还需要做其他设置吗?
请建议您提取文章标题和文章网址的指针。
提前致谢!
普拉文
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;
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.
Thanks in advance!
Pravin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
要获取 Joomla 文章 id,请使用此...
在前面的答案中,有人使用
id
而不是Itemid
。希望这有帮助!To get Joomla article id use this...
In the previous answer someone used
id
instead ofItemid
. Hope this helps!为了获取文章 ID,您必须编写以下内容:
对于标题,您只需获取获得的 id,加载文章对象
In order to get the article ID you have to write the following:
For the title, you just take the id you got, load the article object
看来
JRequest
在 2.5 和 2.5 中已被弃用。 3.x,如已弃用元素列表中所示。我宁愿使用以下内容:
It seems
JRequest
is deprecated in 2.5 & 3.x as indicated in the Deprecated Elements list.I would rather use the following:
我尝试过:
我仍然没有得到 ID。这是正确的吗?
文章已加载到您的第二个参数 (
$article
) 中。在此事件 (onContentPrepare
) 中,您可以访问的唯一属性是$article->text
。为了满足您的目的(获取文章 ID 和标题),您将需要使用另一个名为“
onContentBeforeDisplay
”的事件。在这里,您(再次)通过第二个参数传递了文章,但现在您可以访问诸如
$article->id
、$article->title
和还有很多其他的。有关内容事件的未来参考,请查看文件“plugins\content\example\example.php”
i tried :
Still I am not getting the id. Is this right?
The article is loaded in your second argument (
$article
). Being on this event (onContentPrepare
), the only property you can access is$article->text
.For suiting your purpose (getting the article id and title) you will want to use another event, called "
onContentBeforeDisplay
".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.For future references on content events, take a look at the file "plugins\content\example\example.php"
您可以使用这样的方式获取活动文章标题
可能会有所帮助。
You can use for getting active article title like this
may this help.