Stop a particular <div> appearing on just one page - php

I was wondering could you help me, we currently have an announcement banner across the top of all our webpages which I want to remain apart from one page. A couple of guys did a bit of work for me a put an announcement in which I can edit via Custome Content Type Manager on Wordpress.
In the Header.php the code is there and I'm not sure how to get it to stop appearing on a particular page, the id of the page I DONT want it on is 2664. The code is shown below:
<?php
$gathering_page = get_the_ID();
if( ($gathering_page == 3001 || $gathering_page ==2664) && !(is_front_page()) ){ ?>
I'm not sure if the guys have tried to block it or what this code means.
Any feedback would be appreciated. Thanks
EDIT: This may make it easier; I would like to make a div class disappear on the page named above. the div class is
<div class="snippetHomeTop">

I'm sorry if I did wrong, but have you tried using the is page?
<?php if (is_page('2664')) {
// don´t show content for page ID 2664
} else {
// show content for other pages
}?>
Good Luck

Related

How can I include / exclude a part of an included PHP file based on the file I am including it in?

The title is a bit convoluted. Let me explain better.
I'm making a blog where registered users can delete and edit their posts. The posts are displayed on 2 sites - the main page, and an admin control panel page. The code for generating the posts is in a separate file.
On the title page, everyone should only be able to see the posts. On the admin page, registered users can edit / delete their posts using the same included php file. There is one function smack in the middle of the code that determines if the editing buttons are visible. I want that function to be present when the file is included on the admin page, and not be present when it is included on the main page.
Let's say that the file which is included, blogposts.php looks something like this:
<?php
code
function();
rest of code
?>
What can i do to exclude that function in the instance where I don't need it?
I've also tried deleting the function and writing:
<?php
require "blogposts.php";
function();
?>
That executes it only on the last post, but should execute it on all of them since it is part of a while loop in the original code.
So, other than writing the code twice, once with and once without the function, if you guys have any ideas I'd appreciate it,
You could place the function inside an if statement, and check the current page against $_SERVER['REQUEST_URI'].
Something like:
if($_SERVER['REQUEST_URI'] == '/current_page_uri.php')
{
function();
}
And then replace the '/current_page_uri.php' with the URI for your admin page.

Conditional statements doesn't work on Wordpress title tag

I'm trying to use as few plugins on my WP site as possible. Therefore I created custom fields for posts and pages to create a title tag and meta description.
The code look as follows:
<title>
<?php $title = get_post_meta($post->ID, 'Title', true);
if ($title) { ?>
<?php echo $title; ?> | domain.com
<?php }
else { ?>
<?php wp_title(''); ?> | domain.com
<?php } ?>
</title>
The code works like a charm, unless for one cause. The homepage titletag is similar to the most recent blog posted (my homepage is a blog overview). Obviously I don't want that.
I found that inserting the following code right under <title> works
<?php if(is_home()) { echo "My desired homepage title tag"; } ?>
However, the title tag now contains both the desired title tag AND the title from the custom field. I first thought I could simply solve that by using the logical if, elseif, else contruction and change the following:
if ($title) { ?>
into elseif.
However then my whole site breaks and I get a blank page in return for every URL I try to access.
Then my PHP knowledge stops. I have no idea how to solve the double title. Can someone help me out and point what I'm doing wrong? Why doesn't the conditional statements work
The main reason should be that when you access $post->ID you get the ID of the latest inserted post, not the homepage.
By default wordpress loads the latest post an you have them ready to use in the loop.
To avoid that you have to set a different homepage than "latest posts" in "settings" -> "reading".
Once you do that you'll se the correct title loading up.
Anyway I would advise to use the super useful WordPress SEO plugin by yoast, is the de facto standard for this kind of things and is used by a lot of high traffic wordpress installation.
let me know

How can add tracking code (tradetracker and daisycon) on thank you page

I have a task, I did research but I still cannot be done.
I am using OpenCart. And I have to add code tracking (from tradetracker and daisycon) to thank you page.
How can I do it?
If you aren't too comfortable with writing your own extension and your tracking code is JavaScript or HTML you can place it straight into your template. You will find the template you need in:
/catalog/view/theme/default/template/common/success.php
The only problem is that this will now fire every time the page loads. Any success goes to this template.
To fix this you need to go into the controller and make a small addition.
Find:
if (isset($this->session->data['order_id'])) {
Add a new line below reading:
$this->data['enable_tracking'] = TRUE;
Then back in the template before simply add an if statement round the tracking code you have added like so:
<?php if($enable_tracking === TRUE){ ?>
Delete this line and replace with tracking code
<?php } ?>
That should solve your problem.

PHP setcookie function not being set on wordpress splash page implementation

So I'm trying to get a splash page implemented on a wordpress site. I've looked around and read about how to do it using PHP. The idea of the splash page is to redirect people that haven't viewed the site to a splash page that encourages them to donate. The page is already set to a static homepage which I am making the splash page be. Provided here is the code that I have for the cookie, for some reason when I go into my settings on chrome and check to see if the cookie is being written it doesn't show up.
<?php
if((strpos($_SERVER['HTTP_REFERER'], get_bloginfo('home')) === false) && !$_SERVER['QUERY_STRING'] && $_COOKIE["CookieName"] != 'true') :
setcookie("CookieName", 'true', time() + 3600*24*15, "/~user/");
?>
//splash page code
<?php else : ?> //theme code <?php endif; ?>
The else condition is the information for the homepage that was created by the theme. The URL for the site is in the format of siteIP/~user/. If you guys have some feed back that would be greatly appreciated. Also if you can provide a source so that I can read up on it that would also be appreciated. Thanks for your time.
Sorry for posting an answer but I can't comment because I don't have the rep.
Besides reviewing the comments above, try simplifying - check that the if statement is being executed, then you'll know if you have an error in the cookie setting.
Also, your code as quoted doesn't have a closing statement, I assume you have that in the actual page but thought I would mention that.
The reason that it didn't work is because there was a file that was overwriting the splash page itself so the code on the splash page wasn't being called in the first place. It's a matter of just naming files so that it doesn't have any additional files overwriting it the content that you put up there.

Wordpress Conditional Sidebar Section Based off of Page ID

Goal - have a section of my sidebar that is conditional depending on what page I'm on. All child pages of the selected page should also show the conditional section.
There are at least two ways to do this - 1) have all the conditional hooks and resulting code in one sidebar file and, 2) have multiple sidebar.php documents and call them based off what pages are being visited.
I've pretty much failed at both ways so far... :( I'm working on the second method right now though, because I think it might be more flexible long term. Anyway, in my page.php I replaced:
<?php get_sidebar() ?>
With
<?php
if (is_page(1997) || $post->post_parent) {
get_sidebar('sidebar-test-may12.php')
}
else { get_sidebar()
} ?>
With the hope of testing the method. What I want to happen is that if the page is page id 1997 or any of its child pages please show sidebar-test-may12.php. Otherwise show the regular sidebar. With the new code the whole page goes blank. Any suggestions or solutions for me? Seems like a common problem, but I haven't been able to figure it out yet. Thanks!
You have a few problems with your code example:
1) $post->post_parent is not being checked against anything else, so it will only return true if it is a child page (not necessarily the child of the page you want to target)
2) get_sidebar() is being called incorrectly. If you want to get 'sidebar-test-may12.php' from your theme folder, you need to call get_sidebar('test-may12')
3) You're missing semicolons after your function calls
So your code should look like this:
<?php
if(is_page(1997) || $post->post_parent == 1997) {
get_sidebar('test-may12'); //get sidebar-test-may12.php
}
else{
get_sidebar(); //get sidebar.php
}
?>
Let me know if that helps.
UPDATE: Bear in mind, $post->post_parent does NOT get the top-most ancestor ID of a child page. If you want to grab the top-level ID regardless of depth, consider doing this:
<?php
$ancestors = get_ancestors(get_the_ID(), 'page');
if(is_page(1997) || end($ancestors) == 1997)
get_sidebar('test-may12'); //get sidebar-test-may12.php
else
get_sidebar(); //get sidebar.php
?>
POSSIBLE SOLUTION: Building off your example and my proposed ancestry check, one thing you can do is have your template check to see if a special sidebar exists in your theme based on the parent page's slug. This way, if you decide a particular page needs a special sidebar for it and all of its children/grandchildren/great-grandchildren/etc. you just need to add it into your theme with a name of 'sidebar-{parent_slug}.php'. So:
<?php
$id = get_the_ID();
$ancestors = get_ancestors($id, 'page');
$top_page = $ancestors ? get_page(end($ancestors)) : get_page($id);
if(locate_template('sidebar-'.$top_page->post_name.'.php'))
get_sidebar($top_page->post_name);
else
get_sidebar();
?>
This way, you don't need a ton of conditionals to decide which Sidebar file to load on a general Page template.
Use some error trapping to show what's going on with your php, either toggling an error log in .htaccess of a simple widget: http://wordpress.org/extend/plugins/error-log-dashboard-widget/
I've hardcoded logic for sidebars, but I've also used WordPress › Widget Logic « WordPress Plugins for my own and client sites. It's easy to use with a simplified version of WP conditionals, like is_category and is_page ('101')
For someone else tackling this same problem -- there is a new plugin out that solves this problem very well. It even makes creating the sidebars easy. You can check it out here:
http://wordpress.org/extend/plugins/custom-sidebars/

Categories