Joomla plugin : how to get article title and article id

前端 未结 5 982
抹茶落季
抹茶落季 2021-01-03 06:52

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:

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-03 07:55

    i tried :

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

    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".

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

    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"

提交回复
热议问题