简体   繁体   English

如何使用PHP在模板的某些页面上放置特定的HTML?

[英]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.

相关问题 如何以特定的HTML格式放置php制成的下拉列表? - How can I place a drop-down list made in php in a specific HTML form? 如何使用密码保护某些HTML页面? - How can I secure certain HTML pages with a password? 如何使用php文件在其他HTML页面中显示HTML菜单div? - How can I use a php file to display an HTML menu div in other HTML pages? 我怎样才能只为某些页面重写我的网址 - how can i rewrite my url for only certain pages PHP-如何在html表中编辑特定行并更新数据库? - Php - How can I edit a certain row in my html table and update my db? 如何通过1个提交按钮将html / php代码定向到两个不同的页面? - How can I get my html/php code to direct to two different pages from 1 submit button? 如何在Wordpress的不同页面上使用一个模板? - How can i use one template on different pages in wordpress? HTML和PHP:如何正确排列页面? - HTML and PHP: How do I arrange my pages correctly? 如何使用PHP正则表达式转换某些HTML标记属性的内容? - How can I use a PHP regex to transform the contents of certain HTML tag attributes? 如何使用 index.php 中的 is_archive() 来检索 WordPress 中基于存档的特定模板? - How can I use is_archive() in index.php to retrieve specific archive based template in WordPress?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM