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">
Related
I am trying to store HTML and PHP in a MySQL text field and display it in PHP.
When it displays on site it renders as commented out tags:
<!--?php
if(isset($sp_msg) && $sp_msg != ''){
print '<div-->
This of course screws the whole page up.
How am I supposed to go about displaying this data correctly? I would like to eventually add this to a full functioning CMS so I would like to understand how to do this correctly.
page.php
<?php
require_once('library/autoload.php');
$pid = $_REQUEST['id'];
$page = $ct->get_page_info($pid);
$sp_msg = $page['special_msg'];
require_once('h.php');
?>
<div id="row">
<?php
print $page['page_content'];
?>
</div>
<?php
require_once('f.php');
?>
'page_content' stored in mysql as text
<h3>MY HEADER TEXT</h3>
<?php
if(isset($sp_msg) && $sp_msg != ''){
print '<div>'.$sp_msg.'</div>';
}
?>
<hr>
<p>paragraph text</p>
You need to eval the stored php code. When you print out the string stored in the MySQL you don't run it, you only print it.
<div id="row">
<?php
eval($page['page_content']);
?>
</div>
Warning:
I really don't recommend it. If any suspicious code can be entered into that DB it could cause really big problems. You can't check the PHP code if its not a crypto virus for example. This code will execute anything on the server.
See the PHP manual: eval
I'm using Advanced Custom Fields plugin for custom fields in WordPress, and I tried to embed YouTube videos by adding one more custom fields where I write the YouTube video IDs. And I added the snippet below to the realted content php file, but it did not work. Could you please tell me what is wrong with the code? Thanks.
<div class="videoembed">
<?php $embedcode = the_field('video-embed');
echo do_shortcode("[embedyt]http://www.youtube.com/watch?v=" .$embedcode. "&width=600height=350[/embedyt]"); ?>
</div>
I had the problem myself and found a solution that worked!
the field type must not be oembed, but must be single-line text
and than it works with this code:
<?php // use inside loop echo $youtubevideo_code = wp_oembed_get( get_field('video_url') ); ?>
You don't need to use shortcode in your case, just write iframe tag :
<iframe src="<?php echo $embedcode; ?>" width="600" height="350" frameborder="0"></iframe>
Ok so here is the link to the template code for gallery.
https://github.com/JoomShaper/Helix-Joomla/blob/master/helixPlugin/shortcodes/gallery.php
However when I insert images on my database (not in Php), the image shows up but I am unable to click that image and be directed to the images page, which I have hyperlinked on my database (Joomla). I will have multiple images where I will need to add this click function to.
I have been trying to figure this out forever. I am new to Php and coding, so forgive my ignorant use of word choices from the above paragraphs.
(I've noticed in the past when speaking to coders it is frustrating for them to code the jargon from a someone who doesn't know the language ha!) Thanks!
Sorry, I know this is not an answer probably, but I cannot comment yet. I have been looking at your code for a little while, and I noticed some things I wanted to ask you about. First:
<?php foreach ($galleryArray as $key=>$item) { ?>
<li style="width:<?php echo round(100/$columns); ?>%" class="<?php echo str_replace(',', ' ', $item['tag']) ?>">
<a class="img-polaroid" data-toggle="modal" href="<?php echo ($modal=='yes')? '#modal-' . $key . '':'#' ?>">
<?php
echo '<img alt=" " src="' . $item['src'] . '" />';
?>
<?php if($item['content'] !='') { ?>
<div>
<div>
<?php echo do_shortcode($item['content']); ?>
</div>
</div>
<?php } ?>
</a>
</li>
You begin your a and li inside the foreach loop, but you finish them outside of it. Considering that the a is your link, and your link is not working, I thought this could be part of your issue.
Also, I noticed that when you link to the modal, you use the same variables from the loop, but the variables were defined inside the loop and would not carry over on clicking the link that was generated. It seems to me that you would need to define a property value with the variable you need from each one, so that you can use JS to do something along the lines of "onClick" grab "this.property.value" so that you could have that information in the modal.
I only thought this was of note because the modal you are opening with the link is named by one of these variables. Unless you are creating a separate modal for each one inside the foreach loop, the name you are linking to does not exist. Sorry if this is confusing.
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.
:)
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