[英]How can I use PHP to place specific HTML on Certain Pages of my Template?
有兩種方式編寫php代碼片段,以將html放置在主頁上,然后將html放置在所有其他頁面上...這是針對Joomla 3。++的。
<?php
$menu = & JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo 'HTML for HOME PAGE HERE';
} else {
echo 'HTML for ALL OTHER PAGES HERE';
} ?>
此代碼僅允許只關注主頁:
<?php
$menu = & JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo 'HTML FOR HOME PAGE HERE';
}
?>
我想做的,特別是像第二個代碼段一樣,是專注於網站上的特定頁面。
原因是A.我不想為我要創建的其他所有頁面類型創建模板... B.我不想在HTML模塊位置中放置樣式的模板元素。 我覺得自定義HTML或博客/文章帖子應僅用於內容插入。
因此,有一種方法可以代替調用$ menu-> getDefault())<<<<使該getPage成為???
使用JInput
從請求中獲取頁面信息。
找到了答案。 您可以對多個頁面進行直接頁面編輯和ifelse編輯。
<?php
//This is the code for the page with menu ID 102
$menuID = JSite::getMenu()->getActive()->id ;
if ($menuID == '102')
{
echo '<strong>long</strong>';
}
?>
這是多個頁面的代碼。
<?php
//This is the code for the page with menu ID 6
$menuID = JSite::getMenu()->getActive()->id ;
if ($menuID == '6')
{
echo '';
}
elseif ($menuID == '2') //This is the HTML for page with menu ID 2
{
echo '';
}
elseif ($menuID == '4') //THis is the html for page with menu id 4
{
echo '';
}
else //This is the HTML code for the rest of the pages
{
echo '';
}
?>
在這里找到答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.