I have a custom CMS here entitled phpVMS, and I want to exclude a piece of code, a banner for a single page. phpVMS is steered using templates, for instance, the main template that codes the general layout for all pages is entitled layout.tpl. So, like I said, this displays whatever is in the template, on all of the pages. I have however created a special control panel, and therefore require to exclude the banner, because it slightly destroys the theme of it. Is there any PHP code that excludes a piece of code on a single site? I need to remove a single div...
<div id="slideshow"></div>
...on a single page.
Basically, I could create a new template but this is a very long winded and unefficient way within this CMS, and the final result isn't that great - because I can't reinclude the mainbox div which is the box defining the content on the centre white bit of the theme - it's already in the layout.tpl.
I hope you can somehow help me, hope I've included enough information there.
Thanks.
I don't think you can do what you're asking in PHP, but you might be able to do this on the client-side, by either hiding the div (CSS display:none) or by removing it with JavaScript. You might be able to do something like:
<?php
include("layout.tpi");
if (condition)
{
// Javascript:
echo "<script>document.getElementById('slideshow').style.display = 'none';</script>";
// OR jQuery:
echo "<script>$('#slideshow').hide();</script>";
}
?>
If you use a variable to determine you don't want to include the div, you could do this:
<?php if ($include) { ?>
<div id="slideshow"></div>
<?php } ?>
OR
<?php
if (!$include)
echo "<!--";
?>
<div id="slideshow"></div>
<?php
if (!$include)
echo "-->";
?>
EDIT: Obviously, there is no good reason to use the second method. The second method will only comment out the HTML so it will still show up in the source.
I'm not sure if this is what you are looking for, but seems simple
<?
$template = true;
if($template) {
?>
<div id="slideshow"></div>
<?
}
?>
On the template, you could have some code that reads:
if($_SERVER['PHP_SELF'] == /*control panel file*/) {
//exclude
}else{
//include
}
Related
Im creating a site using Adobe Dreamweaver CS6 and I have added a login function there. I have also added a Dynamic Text session MM_Username that displays the logged in users name in the page. However, my problem here is that every time someone is not logged in, dynamic text shows an ugly error message. I'd like to hide this content from my page every time someone logs in. Is there some simple solution to do it like wrapping the text with some php code? Any help would be appreciated since I've pretty much looked everywhere. Thanks in advance.
-John
From memory (been a few years now) I believe in the server behavior panel, there is an option to "show region if" or something similar.
Failing that you can wrap the offending content in an if similar to this:
<?php if (isset($_SESSION['MM_Username'])) { ?> your content here <?php } ?>
Or this which I personally find more readable when mixing html and php:
<?php if (isset($_SESSION['MM_Username'])) : ?> your content here <?php endif; ?>
You can check firstly when user logged_in, If he/she is logged in then,
if(isset(session['var'])){ ?>
< your html content here using CSS hide property >
<?php } else { ?>
< Your html content goes here using CSS show property>
<?php } ?>
The code does exact of what you want for me; hope it helps
<?php if ($_SESSION['MM_UserGroup'] == 'teacher') { ?>
<div class="home"><img src="images/ico-folder.png" width="32" height="31" /></div>
<?php } else { ?>
<?php } ?>
I am trying to find the best way to have a DIV be hidden if the url is something. For example I have 2 sites using the same template but only 1 of those sites I want to display something.
So site A is domain.com
Site B is site.domain.com
I want it so if site.domain.com is where people are at then do not show DIV ID="hide". I also need it to have this work for not just that specific URL but for anything that comes after it so site.domain.com/aboutus.php, site.domain.com/contact.php etc....
I would like to do this with PHP or JS.
Just check HTTP_HOST:
<?php
if($_SERVER['HTTP_HOST'] != 'site.domain.com'){
echo '<div>contents</div>'; // display div, he is not on site.domain.com
}
?>
You can probably do something like:
<php if($_SERVER['HTTP_HOST'] == 'example.com'): ?>
<div>This is example.com</div>
<?php else: ?>
<div>This is NOT example.com</div>
<?php endif; ?>
But I think you'd really be better off creating some sort of site1_settings.php that gets included on every page in one site, and then site2_settings.php that gets included in the second. For one thing, this will make it much easier to test your code locally.
I usually use strpos for this.
if(strpos($_SERVER["HTTP_HOST"], "site") !== FALSE)
{
// The user is on site.domain.com
}
else
{
// The user is on domain.com
}
Here would be my javascript implementation. Note: jQuery
if(window.location.indexOf("textinurl"))
{
$('#DivId').hide();
}
I've always thought about this and I can't decide what to do. Lets say I have a <div> and I want to echo specific links in it if the user is an admin or a just a member.
Would it be best to have the <div> in the HTML, and just do some if echos within it?
Or should you echo the whole entire div and everything inside it?
There is no possibilty of the div being empty.
You probably should go with code like (for simple application):
<div class="nav">
Index
Profile
<?php
if( $this->isAdmin()){
echo $this->getAdminLinks();
}
?>
</div>
Or rather something like this:
<?php
echo $this->getAdminLinks();
?>
and let that function care about whether to display or not function. For example Zend uses inline php in phtml templates (and I consider Zend great place where to learn).
If you're building complex application (multiple styles, complex navigation, many different types of pages and many conditions how to generate menu) or you use MVC framework, you should go with code:
<?php
echo $this->getNavigation();
?>
Code like this may get really hard to read (imagine 70 lines like this):
One
<?php echo $this->getSecond(); ?>
Third
<?php // some crazy stuff with 2 submenu levels
?>
Anyway, there's no one "good way" to do this, it's all based on what you need and how do you like your codes written.
I don't even know if this is possible but hopefully someone will be able to point me in the right direction.
Basically I want to know if there is a way of getting the css class of a div and then displaying content based on that class.
So for example if;
<body class="home">
Then a div would display as follows;
<div><p>This is the Home page</p></div>
Like I said, I don't even know if this is possible but any help would be greatly appreciated.
Thanks
What you're trying to do can be done with Javascript, but if you want to use php only, then try to use php before you provide the "class" parameter. For example, if $_GET['class']=="home" then <div class="<? echo $_GET['class']?>">some text</div>
Perhaps, you can use Javascript, with IDs for example:
<div id="home"></div>
<script>document.getElementById('home').InnerHTML = "this is text for home";</script>
Hope it helps!
See you point, but you goes the wrong way. If you want to put all content in one page differs by some query param, there is no need to do so. You just can hide unneeded blocks with css and show them with js. On the other hand, if this is some sort of server-side utilization, there is definitely no reason to do so too. On the server you can totally control the output, so make separate templates.
Is there a reason not to use PHP instead of reading the class of a div?
#index.html
<html>
<?php include /contentDefinitions.php; ?>
...
<?php $content = home; ?>
...
</html>
#contentDefinitions.php
<?php
if($content = home){
<p>This is the homepage. I am a happy paragraph.</p>
}
?>
**this would be a little more efficient with an array or something,
but at the end of the day the easiest thing would just be to include
home.php, page2.php, page3.php etc. as needed instead of going the
route of variables etc... though having an array would let you edit
all the content within one file.
I'm no master of code and have zero familiarity with Joomla, so this may be absolutely useless to you. :)
I have a small situaton here. I'm building a custom CMS for one of my websites.
Below is the code for the main index page:
<?php
require("includes/config.php");
include("includes/header.php");
if(empty($_GET['page'])) {
include('pages/home.php');
} else {
if(!empty($_GET['page'])){
$app = mysqli_real_escape_string($db,$_GET['page']);
$content = mysqli_fetch_assoc(mysqli_query($db, "SELECT * FROM pages_content WHERE htmltitle = '$app'")) or die(mysqli_error($db));
$title = $content['title'];
$metakeywords = $content['htmlkeywords'];
$metadesc = $content['htmldesc'];
?>
<h1><?php echo $content['title']; ?></h1><hr /><br />
<div id="content"><?php echo $content['content']; ?></div>
<? } else { include('includes/error/404.php');} }
include('includes/footer.php'); ?>
The file, includes/header.php contains code to echo variables, such as, page title and meta stuff.
The issue is that when the include("includes/header.php"); is where it is, outside of the if conditions, it will not echo the varables, obviously, however, I can't put the include in the if condition otherwise, the home page, which does not require any url variables will show without these conditions.
What do I do?
You can't really write code like this for too long. It's ok to for start, but you will soon realize it's hard to maintain. The usual way is to split it into a few steps.
First check input and determine on which page are you
If you know you are on the homepage, include something like includes/templates/homepage.php
Otherwise try to load the page from the database
If it worked, include includes/templates/page.php
Otherwise include includes/templates/404.php
Each of the files in includes/templates will output the whole page, i.e. they all include the header, do something and include the footer. You can use for example Smarty templates instead of PHP files, which will make the approach obvious.
Once you have this, you can split the code even more. Instead of loading the page directly from index.php, include another file which defines a function like load_page($name) and returns the page details.
Then a few more changes and you realize you are using the MVC approach. :) The functions that load data from the database are your Models, the Smary templates are Views and the PHP files that put them together are Controllers.