Drupal Adding custom Omniture code, PHP variable not being set - php

Ok I have some custom Omniture code I need to add to a Drupal site. All is good as I have added the Javascript code to the themes template page. The code shows up on all the pages as expected but I have a couple of PHP variables that I need to print in the Javascript that are coming up blank.
<?php
$omniture_event = "test this works as expected";
$omniture =<<<OMNITURE
<script language="JavaScript"><!--
s.events="{$omniture_event}"
s.landing="{$omniture_landing}"
OMNITURE;
echo $omniture;
?>
but $omniture_landing is set on the landing page only and it looks like the template page is being loaded first then the content of the page is being added. I can print the value to the screen and I see the Javascript in the footer as expected with the other PHP variable set, but when I try to set the variable on the landing page it comes up blank in the javascript.

You can edit your page.tpl.php template file. If the 'Landing page' is your front page, then you can do something a little easier and more consistent (if you end up changing the title).
if($is_front) {
$omniture_landing = 'Yeah we have landed!!!';
}
Or by node id:
if($node->nid == '1') {
$omniture_landing = 'Yeah we have landed!!!';
}
Replacing 1 with whatever the node Id is of course
Also, check to see if you have a page-front.tpl.php If so, that file, page-front.tpl.php is the template that runs on the landing page instead of page.tpl.php and you can add your code to page-front.tpl.php or remove it if you don't need a separate template for the landing page.

I ended up adding this to the template page (page.tpl.php) before the Omniture code
if($node->title == 'Landing Page Title') {
$omniture_landing = 'Yeah we have landed!!!';
} else {
$omniture_landing = '';
}

Related

Conditionally display menu for page type in Wordpress

I am relatively unfamiliar with Wordpress and I am creating a custom theme for a client. I would like to either display or remove the main menu depending on the page type. I have researched several options like removing the navigation from header.php and referencing it separately and also making the menu conditional which is preferable.
I have a custom page type in my theme called 'landing page' on which I would like the menu to be never be displayed, though it will be on every other page. Ultimately there will be a lot of these and I would rather I didn't have to intervene.
I would rather not duplicate my header.php file but I can only find reference to displaying the menu conditionally like below by page name or ID which seems ridiculous.
<?php
if (is_page('contact')){
<?php include(TEMPLATEPATH.'/headerA.php'); ?>
}
elseif (is_page('gallery')){
<?php include(TEMPLATEPATH.'/headerB.php'); ?>
}
else {
<?php include(TEMPLATEPATH.'/headerA.php'); ?>
}
?>
Rather than including files as above, I will put the whole thing into my header and just make the navigation conditional. Does anyone know how I should approach this using my custom page type landing page rather than by page name so every page created with that type will never have a menu?
Thanks
Are you talking about a Custom Post Type (CPT) or a page called landing-page?
They are completely different. See http://codex.wordpress.org/Post_Types
In any event, this will work for a custom post type or a page:
if ( !is_singular( 'custom-post-type-name-or-page-slug-here' ) ) {
get_template_part('menu');
}
It says: "If this page is not a single page or a CPT, load the file menu.php from the theme folder."
See also http://codex.wordpress.org/Include_Tags:
The get_template_part() tag includes the file {slug}.php or
{slug}-{name}.php from your current theme's directory, a custom
Include Tags other than header, sidebar, footer.

How can i check if there is any content in them main page of joomla?

i am using joomla 3 for a web site, i don't use any content in the main page but the system output is on because i need to output contents on other pages of the site. the problem is i have a space in the middle of the page where normally the content comes. i know where this comes from but i have to disable it if there is no content on that selected page. i tried to check the
$this['template']->render('content')
which is actually used to render the specific content. but i was not able to use it in a conditional if. so i need to check if the loaded page has a content output. has anybody a idea how i could do that?
PS: i dont want do this with css.
You may check if you are showing the main page and render conditionally:
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
if ($menu->getActive() == $menu->getDefault()) {
$this['template']->render('content');
}
?>
For multilingual site check this link for detecting if you are on the default page:
http://docs.joomla.org/How_to_determine_if_the_user_is_viewing_the_front_page
Just curious... why don't use the <jdoc:type="component/>?

Page title show "page not found" on wordpress

i made a couple of php pages and integrated them into wordpress.
The first page is fine, but the second one show "page not found" on the title when it is loaded.
You can find the first page here:
http://www.stefanovirgulti.it/spese.php
then click on "Aggiungi Negozio" to go to second page.
code of first page:
(suppressed wordpress template code)
//if ( is_user_logged_in() ){
if ( true ){
$index=linkBuilder("Aggiungi Negozio",$_SERVER['PHP_SELF']."?p=1");
$appPath="./moneym/";
//$page=$_GET["p"];
switch ($_GET["p"])
{
case 1:
$page="negozi.php";
break;
default:
echo "this is the first page<br>";
echo $index;
break;
}
if ($page != "") include $appPath.$page;
}
else {
echo "This is a private page.<br>";
}
function linkBuilder($name,$path){
return sprintf("%s ",$path,$name);
}
(suppressed wordpress template code)
The code of the second page contains only an echo.
How do i fix this?
PS: the second page works, but if you check the title page, it says "page not found" and i can't change that, this is my problem.
How did you create these pages? Without looking at your header.php file I'll assume your using some sort of default code to get the page title. To create new pages in wordpress you need to create them in the backend admin panel. if your just loading in files, the wordpress enviroment will see this as a page that doesn't exist.
Solved!
I found the "page custom template" functionality. I just made a template with all my code, then used it as template for a wp static page.
I have done the custom template starting from page.php of my current template, took off the code that handles the content, and replace it with my php/sql stuff.
I have made a new page inside wp and used this custom template.
In this way i have a page that does what i want, but act as a real wp page, i can even add it to menus and apply whatever plugin to it. I left the title funcionality so i can change the title of my cutom page from wp admin.
THe reason for this is that one of your included phps includes a check for wordpress environment and displays that title when the condition is satisfied.
The solution is to use php to output "" tags before the included file is loaded.

One file, displaying code on one page, but excluding on another?

Can anyone advise how I'd alter a template which is called on every page load to display a particular section on just the one page?
I hope I explain this well enough...
index.php includes;
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?
Edit: Thanks very much for your time. It's really appreciated.
I inherited/purchased the website and I'm finding the index.php file very temperamental.
I'm attempting to put this code within the sidebar (or below it, above the footer) but any amend on index.php breaks it.
}
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');
A quick and dirty hack would be inserting a custom CSS stylesheet on the index.php page that makes some div that's part of "sidebar.php" visible.
Example:
sidebar.php:
<?php
echo '<div id="theLetterB" style="display:none">B</div>';
?>
index.php:
<?php
if ($_SERVER['PHP_SELF'] == 'index.php') // Replace this with something to differentiate between pages
{
echo '<style type="text/css"> #theLetterB { display:block; } </style>';
}
?>

How do you make a WordPress front page template in the Carrington blog theme?

I tried adding a frontpage.php file to the content directory, but that wasn't being loaded. Now I've added the following snippet to assure I'm getting a context of 'frontpage':
add_filter('cfct_context', 'scompt_front_page_context');
function scompt_front_page_context($context) {
if( is_front_page() )
return 'frontpage';
return $context;
}
That is allowing me to create a frontpage.php file in the loop directory, but I'm still unable to get it to use my file for the content.
Not exaclty sure what you're trying to do, but in order to use a page template in Wordpress, you must have this at the top of the file:
<?php
/*
Template Name: mypage
*/
?>
and that goes before
<?php get_header(); ?>
And in order for Wordpress to use the template, you have to select it in the page editing area in admin.
So, for a "frontpage," use a template named home.php - with the template name as above - and select it as the template to use in the page editor.
you need two pages to get this to work.
page_example.php (make newfile in same directory as page.php)
pages/page_example.php (copy and rename page_default.php)
page_example.php
must have this header only
<?php
/*
Template Name: Page example
*/
if (__FILE__ == $_SERVER['SCRIPT_FILENAME']) { die(); }
if (CFCT_DEBUG) { cfct_banner(__FILE__); }
cfct_page('page_example');
?>
and
pages/page_example.php is the page it calls so really all your changes need to be in here.
ie remove the side bar, get_sidebar();
now select this page as usual when you are creating a page.
The index.php file is used on the front page of your wordpress blog. Edit (or create) the index.php file to make changes for the front page of your blog.
The correct name of the file needed to replace the front page template is front-page.php not frontpage.php
This is actually a problem in the utility.php file (in the carrington core). There is a function that tells it how to get/determine the content for any given situation. The code looks like this (around line 500):
function swpt_choose_content_template($type = 'content') {
$files = swpt_files(swpt_PATH.$type);
$filename = swpt_choose_single_template($files);
if (!$filename && swpt_context() == 'page' && file_exists(swpt_PATH.$type.'/page.php')) {
$filename = 'page.php';
}
if (!$filename) {
$filename = swpt_default_file($type);
}
return apply_filters('swpt_choose_content_template', $filename, $type);
}
You need to add another case in there to have it check for the front page content template path...this would be the code (in this example, the front page is "front-page.php"):
//checks to see if this is the front page content - this fixes the error of the framework choosing the default content rather than the front page content
if (!$filename && swpt_context() == 'front-page' && file_exists(swpt_PATH.$type.'/front-page.php')) {
$filename = 'front-page.php';
}
I added that right above the default case, and it instantly solved the problem of Carrington calling the default content rather than the front page content template.

Categories