[英]Enter article title from Joomla as title for event creation in EasySocial
[英]getting article title from joomla into a plugin
所以我有這個工作的PHP代碼來獲取當前顯示的Joomla文章:
<?php
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
if ($option=="com_content" && $view=="article") {
$ids = explode(':',JRequest::getString('id'));
$article_id = $ids[0];
$article =& JTable::getInstance("content");
$article->load($article_id);
echo $article->get("title");
}
else {
echo "Error - not an article";
}
?>
我已經在ChronoForms中成功使用了該名稱,以獲取我的文章名稱以通過電子郵件發送給客戶,這恰好是一個招標網站,每個文章名稱的末尾都有一個ID碼,例如12345。
是否有任何快速且骯臟的方法將此代碼插入到joomla中的某處,所以我可以動態修改文章中的插件,例如:
{gallery}12345{/gallery}
我嘗試將其直接添加到模板中,但是無論將其插入到哪里(頂部,底部,中間),都會遇到各種問題,在文章joomla附加組件中也嘗試了PHP,但是該代碼停止了頁面的顯示。
根據評論,這是我的理解; 如果我弄錯了,請糾正我。
您有一些包含代碼的文章
{gallery}here!{/gallery}
哪個插件應該替換為
{gallery}The title of the article{/gallery}
如果是這樣,這將需要在com_content,view = article上進行,其中Joomla將使插件的onContentBeforeDisplay()文章對象可用。
function onContentBeforeDisplay($context, &$article, &$params, $page=0){
$view = JRequest::getCmd('view');
if ($view == 'article') {
$content = $article->text;
$title = $article->title;
$content = preg_replace('/{gallery}.*{\/gallery}/',"{gallery}$title{/gallery}",$content);
$article->text = $content;
}
}
但是,如果您需要另一篇文章的標題,或者在com_content view = article之外需要它,則必須實例化com_content並從那里獲取它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.