I'm trying to use the is_page conditional tag to create a slider that displays different sets of images depending on the page.
Below I've created an example of the code I'm using. All I'm getting back is a blank page and I'm really not sure why. Everything I've looked at on Google tells me my Syntax is correct (At least from what I can tell).
I am using the is_page tag before the loop in WordPress so that shouldn't effect it as far as I'm aware. Please correct me if I'm wrong.
I tried placing <?php wp_reset_query(); ?> just before the loop too, but it had no effect.
Any ideas what I might be doing wrong?
EXAMPLE:
<div id="container">
<?php if (is_page('123') || is_page('356')){ ?> // check page, if any are true display image
<img alt="" src="<?php bloginfo('template_url');?>/images/image1.jpg" width="650" />
<?php } ?>
<?php if (is_page('123') || is_page('356') || is_page('638') || is_page('1199')){ ?> // check page, if any are true display image
<img alt="" src="<?php bloginfo('template_url');?>/images/image2.jpg" width="650" />
<?php } ?>
</div>
PROBLEM SOLVED:
<?php
// THIS GIVES US SOME OPTIONS FOR STYLING THE ADMIN AREA
function custom_design() {
echo '<style type="text/css">
#wphead{background:#592222}
#footer{background:#592222}
#footer-upgrade{background:#592222}
textarea {white-space:nowrap;overflow:scroll;}
</style>';
}
add_action('admin_head', 'custom_design');
?>
It seems this piece of code in my functions.php was causing the error. The CSS "whitespace:nowrap" was breaking any new template pages I was making. Totally bizarre. Never seen CSS do that before, at least not to that extent.
Sorry for wasting your time guys, thank you for the help. At least I know I wasn't going crazy now.
:)
Related
I've been trying to get information from WP for a while now and I still can't get it to work. What I'm trying to do is to get the information from an online resume and display it on the site.
The problem is that I haven't worked with WP a lot before and I can't figure out if there is a better way than SQL extraction to get that information.
This is the code I have now, it's very simple but doesn't work.
$output = '
<html>
<head>
<link rel="stylesheet" type="text/css" href="style1.css">
</head>
<body>
<div id="header">
<h1 class="title">'.the_custom_field('_candidate_name', 144).'</h1>
<ul class="contactInformation">
<li id="fullName">//This is where the name should go</li>
<li id="adress">//I want to fetch the adress and echo it here etc.</li>
<li id="phoneNumber"></li>
</ul>
<div id="resumePicture">
<img src="mVqghXM.jpg" height="auto" width="100px">
</div>
</div>
<div id="education">
<ul>
</ul>
</div>
<div id="experience">
</div>
</body>
</html>';
I've tried using get_custom_field as well as get_resume_field and placing them into a variable but i get an error that says it's undefined, and I presume that is because I don't have the WP Job Manager Field Editor plugin.
I would rather find another way to do this, either via some other WP compatible function or via SQL, instead of having to buy that plugin.
I would also love one of you to explain to me briefly how the WP system/database is built, because that would help immensely.
Thank you!
EDIT: I found the way of fetching the data from the database. It was get_resume_field, but what I'd done was copy the meta_key straight off the database, being "_candidate_name", but when I took the first underscore away, it worked. Thank you both for helping with the two problems I had. Cheers!
Use three files in your custom php file to get and use all wordpress function. Try this.
include_once("/path/to/wordpress/wp-config.php");
include_once("/path/to/wordpress/wp-load.php");
include_once("/path/to/wordpress/wp-includes/wp-db.php");
You have made to collect all the HTML into a single variable as per you need.
The major important thing is that you have to echo/ return the variable to print the output.
This will do the trick if you return it from a function
function get_page()
{
$output = '<p>Welcome</p>';
$output .= '<p>Again</p>';
return $output;
}
After the return you have to echo the statement by calling the function
$test = get_page();
echo $test;
Output:
Welcome
Again
I'm working on a website for a friend, everything goes well so far, but there's one little thing I can't seem to figure out.
I have included SmartSlider 2, which I want to hide on mobile devices. But since SS2 doesn't natively support this I tried by editing the code. Long story short, it won't work.
I've tried including the CSS in the file itself (header.php) :
<div class="slider" style="#media(max-width:1120px;){.slider {display:none;}}">
<?php echo do_shortcode('[smartslider2 slider="2"]'); ?>
</div>
For some reason, it still shows up, hopefully you guys can help me out. Thanks in advance.
It will not work like you are trying.
you have to put this in custom css
#media screen and (max-width: 1120px) {
.slider {
display:none;
}
}
and remove from here
<div class="slider">
<?php echo do_shortcode('[smartslider2 slider="2"]'); ?>
</div>
and in media query CSS you have ; here #media(max-width:1120px; it's wrong
Fiddle
Alright so I looked through here and tried to find a solution to this, and I found some php that came up twice as an answer, but it isn't working for me, so here's the problem.
I have a custom wordpress theme. Under the navbar, I want to put a dynamic image based on that page's featured image. The image needs to be responsive and spread across the width of the page, much like you'd imagine a responsive header image to function. I can handle the responsive css bit and put the image in a div when I get to pulling it, but the image isn't even pulling.
Here's the code that came up twice as an answer on Stack Overflow:
<img src="<?php $img=wp_get_attachment_thumb_url(get_post_thumbnail_id($post->ID)); echo $img[0]; ?>" alt="<?php the_title(); ?>"/>
It isn't working. The php string is not pulling the thumbnail url and the only output in the console is the alt information wrapped in an img tag. I don't know if it has to do with the code being in the header.php, but any advice would be great.
Use this to show post thumbnails within the loop. You can also pass an elseif statement to show nothing if no image is uploaded or show a placeholder image. Hope that helps!
<?php if ( has_post_thumbnail()) : ?>
<?php the_post_thumbnail('PLACE-CUSTOM-SIZE-HERE-OR-OMIT-TO-USE-ORIGINAL-SIZE'); ?>
<?php endif; ?>
<?php
if ( has_post_thumbnail()) {
$featureImage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'feature' );
$featureImage = $featureImage[0];
?>
<div id="feature" style="background-image: url('<?php echo $featureImage; ?>')">
<? } else { ?>
<div id="feature">
<? } ?>
This is how I have accomplished this in the past.
I'm just going to leave this here in case this is causing your issue.
From the doc page: get_post_thumbnail_id()
Note: To enable featured images, see post thumbnails, the current
theme must include add_theme_support( 'post-thumbnails' );
I am working on a custom wordpress homepage.
I want that it is loading in a different div in the header.
The header now loads the #content div for every page. But i want to let it load #contenthome div if the homepage loads.
I'm using this php-code:
<?php if (is_page_template('template-home.php')) { ?>
<div id="contenthome">
<?php } else { ?>
<div id="content">
<? } ?>
I'm fairly new to php. so i hope you guys can help me :)
Thanks a lot.
Or this:
if(is_home())
{
<div id="contenthome">
<?php } else { ?>
<div id="content">
<? } ?>
Personally, I prefer writing things in shorthand when it comes to cases like these. Consider also using this to shorten your code:
<div id="<?php echo is_home() ? 'contenthome' : 'content'; ?>">
ADDITIONAL NOTES: If your <body> tag has the Wordpress body_class() added to it, you can pretty much target individual pages with CSS, even when they're using the same template. The homepage, like any other page, will have a unique body class applied that will then allow you to target that particular page.
So if your issue is simply a matter of being able to target any given page regardless of template with CSS, you won't necessarily NEED to apply any unique divs to your page. For example:
<style type="text/css">
#content{display:block;}
.home #content{display:none;}
</style>
This will hide the content div only on the homepage. It's probably not what you want it to do, but you can see how the page itself is being targeted to override the default behavior.
UPDATE: As per your latest question, if you need another particular page to use that conditional, use is_page() like so:
LONG CODE:
if(is_home() || is_page('posts_page_title'))
{
<div id="contenthome">
<?php } else { ?>
<div id="content">
<? } ?>
SHORTHAND:
<div id="<?php echo is_home() || is_page('posts_page_title') ? 'contenthome' : 'content'; ?>">
If you prefer, you may also use is_page('posts_page_ID') or is_page('posts_page_slug'). Play around with it and see what works best for you. More information here: http://codex.wordpress.org/Function_Reference/is_page
With reference to this post Try this one....
$pagename = get_query_var('pagename');
if ($pagename = 'template-home.php') {
<div id="contenthome">
<?php } else { ?>
<div id="content">
<? } ?>
it seems like you already created a file in your theme just for the homepage and you called it template-home.php
from this point you have two options:
1) you can just define a constant (or variable) and decide what div to use only when it is defined; if you will use a variable remember that in header.php you are in fact inside a function (get_header) and you will need to use global to have access to it
2) if you foresee any other differences between the structure of the header between the main page and the rest of your wordpress you could use another file for the header. to do this, in your template-home.php file give a parameter to the get_header function, like get_header('home')
if you do this header-home.php will be loaded instead of header.php
My question is about WordPress, but it might just be a general PHP question...I'm trying to make a custom download button for my single posts, so I added the following code in my single.php
<div id="downloadbutton">
<?php if(get_post_meta($post->ID, "download_link", $single = true) != ""){ ?>
<?php } ?>
</div>
For some reason, the download button shows up only in Firefox browser, but not in Chrome or IE...
Any tips?
You need to close the <a> tag:
<img src="example.png" border="0">