[英]How can I use PHP to place specific HTML on Certain Pages of my Template?
There are two ways of writing php snippets to place html on the home page and then html on all other pages... This is for Joomla 3.++ 有两种方式编写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';
} ?>
This code allows for just focusing on the home page only: 此代码仅允许只关注主页:
<?php
$menu = & JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo 'HTML FOR HOME PAGE HERE';
}
?>
What I would like to do, specifically like the second code snippet, is focus on specific pages on the site.... 我想做的,特别是像第二个代码段一样,是专注于网站上的特定页面。
The reason being is A. I don't want to create a template for every other page type I am creating... And B. I don't want to have to place template elements of styling in my html module positions. 原因是A.我不想为我要创建的其他所有页面类型创建模板... B.我不想在HTML模块位置中放置样式的模板元素。 I feel the custom HTML or blog / article posts should simply be for content insertion. 我觉得自定义HTML或博客/文章帖子应仅用于内容插入。
So is there a way to instead of calling on the $menu->getDefault()) <<<< make that getPage??? 因此,有一种方法可以代替调用$ menu-> getDefault())<<<<使该getPage成为???
使用JInput
从请求中获取页面信息。
Found the answer. 找到了答案。 You can do a direct page edit and ifelse edits for multiple pages. 您可以对多个页面进行直接页面编辑和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>';
}
?>
Here is the code for multiple pages. 这是多个页面的代码。
<?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 '';
}
?>
Found the answer here. 在这里找到答案。
Joomla if else for menu by ID or url Joomla,如果其他用于按ID或URL进行菜单
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.