I have a box ad in a <div> that I have put in index.php but it's showing up in almost all the other pages.
Which file do I need to edit or put this box ad in so that it is only visible on the home page and not on other pages?
Well i found the answer
if ( basename($PHP_SELF) == FILENAME_DEFAULT && $cPath==null) {
Give the body of your index.php an extra class. For example contentindex. Also, provide your ad-div with an extra style element:
<div class="contentindex" style="display:none;"/>
And in your css it should be something like:
.contentindex ad {
display: inline;
}
Work with parents and children.
But why do you want this? If it's not allowed to be visible, why is it the div there in the first place?
Even thought its not proper you can edit the language template since it allows HTML.
It's in catalog\includes\languages\english\index.php You could use:
define('TABLE_HEADING_NEW_PRODUCTS', 'Your content here.<br />New Products For %s');
Or something similar.
Add it to the bottom of the index.php file in the catalog folder. Below
<?php
} else { // default page
?>
Related
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
}
I have a menu that wants to change only the content.
I wanted a separate files for different pages to organize.
I could save menu in a separate php file and include that in the main page.
Still seems a bit repetitive when there are more than 10 menus.
I know there is an anchor tag navigation that updates content part with jQuery.
But I kinda don't like that # tag in the address bar for some reason (or shouldn't I?)
Is there a better way to manage this?
I could save menu in a separate php file and include that in the main page.
Yes. Do that.
I know there is an anchor tag navigation that updates content part with jQuery.
Breaks search engines. Depends on JS. Avoid it.
I don't think that to add just one line with include into each file is indeed such a repetitive task. 99% of local folks a way more repetitive in thir code.
However, if you want something more intelligent, you can create one program file contains menu, and many data files, shown according to user choice
here is a very simple example
Main page<br>
<a href=?about>About</a><br>
<a href=?links>Links</a><br>
<br><br>
<?
if (empty($_SERVER['QUERY_STRING'])) {
$name="index";
} else {
$name=basename($_SERVER['QUERY_STRING']);
}
$file="txt/".$name.".htm";
if (is_readable($file)) {
readfile($file);
} else {
header("HTTP/1.0 404 Not Found");
exit;
}
?>
Desperately hoping someone can assist with this. I'm a novice with php. I try and self teach myself through tutorials and I've searched high and low to no avail.
Basically I'm looking to implement an "If index.php page, show foo, if not on index.php page, show bar"
Any ideas?
I hope I explain this well enough...
index.php includes a sidebar:
require_once('./cache/templates/sidebar.php');
Every subsequent page is built uses what's defined in this index.php file, meaning the sidebar.php is a must.
I'm wanting to edit sidebar.php to contain an advert which displays solely on the index page.
At the moment, when I edit sidebar.php, so for instance, to display the letter "B", it will display on the homepage, and every other page like so;
Index Page: http://img.photobucket.com/albums/v684/nilsatis/1stack.jpg
Every other page: http://img.photobucket.com/albums/v684/nilsatis/2stack.jpg
How can I dictate one area of an included file to display on one page but exclude showing on others?
Any assistance would be very appreciated.
[Edit] This is the website in question: www.grandoldteam.com . You can see where I have the text "Test" - this was entered in sidebar.php. I'd like this text (future advert) to feature only on the index page, nowhere else.
[Edit 2] This is the point in which sidebar.php is called in the index.php file;
<p class="page_desc">'.$PAGE['subtitle'].'</p>
' );
}
if (isset($url[1])) require_once('./cache/html/'.$url[0].'/'.$url[1].'.php');
else require_once('./cache/html/'.$url[0].'.php');
}
}
require_once('./cache/templates/sidebar.php');
}
require_once('./cache/templates/footer.php');
And this is the but in which I can edit sidebar.php to display wanted text;
<div class="clear"></div>
test
</div>
<p>
</div>
To do it the way you want, use the $_SERVER superglobal. The script's name is found in more than one place.
if (strpos($_SERVER['SCRIPT_NAME'], 'index.php') !== false) // index page...
Another option is to have index.php set some variable like $show_ad before including the side bar, and the side bar page can check that variable.
I would not recommend to retrieve the name of the caller script, because several pages can have the same name in different folders, and also because you may want to change page names in the future.
Use a global variable or a constant that says which page is the caller.
index.php:
<?php
$GLOBALS['caller_page'] = 'index';
require_once('./cache/templates/sidebar.php');
...
sidebar.php:
<?php
...
if ( isset($GLOBALS['caller_page']) && ($GLOBALS['caller_page']=='index') ) {
... // special action for the index page
}
...
Try this instead,
Create a session on the page where you only want to show "foo".
Then do this
if ($_SESSION['valid']) {
//if the session is present, then show
}
else {
//if not,
}
This is not only a better way of going about it as what happens if your filenames get changed? This way it doesn't matter as it is checking against a session, not something that could change :)
How to work it out:
At the top sidebar.php, add the line:
print_r($_SERVER);
This will show you the full contents of the $_SERVER variable. From that, you should see a number of candidates that could be used, as well as other things that may be useful to you at some point.
Once you've decided on what to use, you will need to check whether it includes the string index.php. A good way to do that would be to use:
if (strpos($_SERVER['SCRIPT_NAME'], 'index.php') !== false) {
}
This idiomatic line checks to see whether the position of the string index.php in the script name isn't false, that is, it is a value.
Test the value
$_SERVER[ 'REQUEST_URI' ]
against the literal
'/index.php'.
If it is identical. you index.php is executing.
all of those answers are great, but i provide a different practice. It's not better, but in my feeling it's more comfortable.
when you do this:
require_once('./cache/templates/sidebar.php');
on index.php, do this instead:
require_once('./cache/templates/sidebar.php?ad=1');
now, on sidebar.php, add this:
if(isset($_GET['ad'])&& $_GET['ad']=='1')
// display ad
else
//don't display ad
EDIT:
you want working code, fine...
lets say your ad is actually the image of stackoverflow logo:
now on sidebar.php you'll have somthing like:
<?php
....
if(isset($_GET['ad'])&& $_GET['ad']=='1')
{
?>
<div>
<a href="http://stackoverflow.com">
<img src="http://blog.vicompany.nl/wp-content/uploads/2011/04/stackoverflow-logo-250.png" alt="ad"/>
</a>
</div>
<?php
}
else
{
}
....
?>
I have a views page that contains a listing of one of my content type. I used views-view-list--<name of my view>.tpl to theme the page. However, the region/blocks that I defined are not displaying. In other pages it works fine, but on the views page it does not. I'm trying to display a user login block in my defined region.
Please tell me how to access my user login block or my region to display on my views.
Your help is greatly appreciated. I'm using drupal 6 by the way.
Best regards,
Think i ran into something similar yesterday. I was trying to print a region, for example
<?php print $footer ?>
but inside a tpl file that came from views - and for whatever reason, it doesn't output the region from one of the views tpl files.
I used this code:
<?php print theme('blocks', footer); // change "footer" to the name of your region ?>
As I am writing this, a safer and maybe recommended way in D7 would be:
<?php
$region = block_get_blocks_by_region('footer') //first define the block;
print render($region) // then print the block;
?>
I tried #Garry but I got some errors back from Drupal. Please see here
Hope this helps someone down the line.
Any page in drupal have page template based on url or content type . So you have to create right page template for your page where views page/block to be displayed. I'm assuming that you are using page template based on url
This worked for me, except the syntax above needs semi-colons after (); for example print render($region); otherwise thank you for this answer
This is how the snippet will work for Drupal 7 with Bootstrap - HTML tags, considering that the 'billboard' region host an ad:
<aside class="col-xs-0 col-sm-12 role="banner">
<?php
$region = block_get_blocks_by_region('billboard');
print render($region);
?>
</aside>
ok, the title did not make much sense but this is what i am planning to do. I have designed a template for my website, with head body and div for specific stuff and everything. The website consists of header file, footer file, right-side column, header dropdown menu and a main body which would be present beneath the header dropdown menu, to the left of the right-side column, and above the footer. Right now there is some content is this main body area. What i am trying to achieve is that whenever any link is clicked on any of the other parts of the webpage, i want that content to be displayed in this main body. Right now i am copying this template to each and every page, but I want to keep this standard template as index.php and then replace main body content based on the link clicked. This is a php based website. Are there any examples where i can see how this can be achieved? or is there any standard procedure to do this. Please guide me, Thanks.
Here's a very simple way to do this:
index.php
<?php
function putPage($page) {
// put a list of allowed pages here
$allowed = array('page1', 'page2');
$page = trim($page);
$page = (in_array($page, $allowed)) ? $page : 'home';
echo #file_get_contents('.\html\\' . $page . '.html');
}
?>
<html>
<head>
<title>Title</title>
<!-- put stylesheets, js files, etc. here -->
</head>
<body>
<!-- you can have a nav bar or something here -->
<div class="navbar">
Page 1 Page 2
</div>
<?php putPage($_GET['page']); ?>
<!-- put a footer here -->
</body>
</html>
Then just put .html pages with the contents in an html subfolder.
The script will fetch them and insert them in the body.
There are a few ways you can achieve this. Off hand the two obvious ones I would say are:
Ajax to obtain content with event handlers attached to links/buttons/menus that produce maincontent specific to the request.
This requires server and client side scripting to achieve.
w3 ajax
Or alternatively use mod_rewrite with apache to determine what content to load in index.php page. For example with mod rewrite you may have a link http://www.site.com/subject/content/item# as a link structure. This could translate to www.site.com/index.php?subject=&content=&id= And these GET values would allow you to determine what to display in main content area.
This requires server side scripting and configuration of apache or (any web server with similar functionality to mod_rewrite).
mod_rewrite - apache
I use this:
<?php
$pag = array(1 => 'Home.php', 3 => '2.php');
echo require $pag[(int)#$_GET['p'] | 1];
?>
This is called either a Template View as far as you build your link specific HTML completely in PHP. You create a page layout template containing some wildcards. You load the template into a string and use string replacements or XML functions (more fancy but only suggestive if transformation is more complex).
Otherwise it is called Two Step View where you create the page layout template (as above) and a specific template for the links. Now first load the link specific template, put your dynamic content into (same techniques as above), load the page layout template and put the previous transformed specific template into.