how do i put this <?php echo $cfs->get('exclude'); ?> within the double quotes in this <?php echo do_shortcode('[gallery exclude=""]'); ?>
meaning, what is the correct syntax to merge the two? i attempted to read through some of this to solve it, but have little php knowledge.
thank you.
sprintf('[gallery exclude="%s"]', $cfs->get('exclude'));
See sprintf()
Also readable:
$exclude = $cfs->get('exclude');
"[gallery exclude=\"$exclude\"]";
this is one way
echo do_shortcode('[gallery exclude="' . $cfs->get('exclude') . '"]'); ?>
<?php echo do_shortcode("[gallery exclude='$cfs->get('exclude')]'); ?>
Related
Sorry if I worded the question wrong. In the code below, is there a way to insert php where the date is?
So this:
<?php echo do_shortcode('[fergcorp_cdt_single date="08 December 2013"]') ?>
Would become something like this:
<?php echo do_shortcode('[fergcorp_cdt_single date="<?=$date?>"]') ?>
Is the above correct? If not, how would I write it?
<?php echo do_shortcode('[fergcorp_cdt_single date="' . $date . '"]'); ?>
You could also use double quotes:
<?php echo do_shortcode("[fergcorp_cdt_single date=\"$date\"]") ?>
Currently, as an example, I have this php code on one of my pages.
<?php include("codes/games/scripts/titles/angrybirds.php"); ?>
How would I change this to make my variable:
$gametitle = "angrybirds";
work like this:
<?php include("codes/games/scripts/titles/$gametitle.php"); ?>
Thanks in advance for your help!
That code should work as-is, since the . won't be interpreted as part of the variable name. You can see the output of it here: http://codepad.org/ZbtiOPgB
However, for readability, I would encourage you to either use clear concatenation:
<?php include("codes/games/scripts/titles/".$gametitle.".php"); ?>
Or wrap your variable name(s) in { and }:
<?php include("codes/games/scripts/titles/{$gametitle}.php"); ?>
<?php include('codes/games/scripts/titles/'.$gametitle.'.php'); ?>
Or:
<?php include('codes/games/scripts/titles/'.$gametitle.'.php'); ?>
<?php
$file = 'codes/games/scripts/titles/' . $gametitle . '.php';
if (file_exists($file))
require_once($file);
?>
In a little trouble with this, is they any way i can get to echo's working together see code below,
<?php $youtube_vimeo_player = get_post_meta($post->ID,'_youtube_vimeo_player',TRUE); ?>
<?php echo $video->embed(' <?php echo $youtube_vimeo_player['url']; ?> ', '', ''); ?>
I'm wanting the info brought from the vimeo_player url to be entered into the video->embed section.
Any help on this would much be appreciated : )
try it like this:
<?php $youtube_vimeo_player = get_post_meta($post->ID,'_youtube_vimeo_player',TRUE); ?>
<?php echo $video->embed( $youtube_vimeo_player['url'], '', ''); ?>
Replace
' <?php echo $youtube_vimeo_player['url']; ?> '
with
"{$youtube_vimeo_player['url']}"
You dont need echoing inside the php string. Note that { and } are the special way to embed array index, or object method call into the string, they are not present in final string.
Btw, it's sufficient to just do
echo $video->embed($youtube_vimeo_player['url'], '', '');
As $youtube_vimeo_player['url'] already shoud be the string
<?php echo $video->embed("'".$youtube_vimeo_player['url']."'", '', ''); ?>
PHP isn't that crazy, but thanks for remembering us it could seem to.
Thou shall write:
<?php
$youtube_vimeo_player = get_post_meta($post->ID,'_youtube_vimeo_player',TRUE);
$url=$youtube_vimeo_player['url'];
$video->embed($url, '', '');
?>
Educate yourself on the concept of variable, and remember, php has only one level of embedding (that is one level of <?php ... ?> — no nesting)
And believe it, it's better this way.
<?php
$total=3;
echo '
<div class="idsdiv">.$total.<div> ';
?>
i want to appear $total variable number in the link.why is this script not working?
Enclose the whole string with double quotes to embed variables inside:
echo "<div class=\"idsdiv\">$total<div>";
You need to use double quotes around your HTML and single quotes around your attributes or do this...
echo '<div class="idsdiv">' . $total . '<div> ';
PHP doesn't process variable names in strings enclosed in single quotes.
<?php
$total=3;
echo '<div class="idsdiv">',$total,'<div>';
?>
Look at the string section of php.net (http://php.net/string) they talk about how to use each of the types. One of quote being the ' where nothing is parsed.
<?php $total=3;
echo "<div class=\"idsdiv\">$total<div> ";
?>
you had errors with your quotes
You can print HTML without printing it, like so:
<?php
$total = 3;
?>
<div class="idsdiv"><?php echo $total; ?></div>
When I still did PHP, I found it much easier to manage than escaping tons of quotes and things like that.
You can even do it inside of an if block too:
<?php
if ($foo == 'bar') {
?>
<div>Foo is bar</div>
<?php
}
?>
The method I like is
<?php
$total=3;
echo "<div class='idsdiv'><a href='profile.php?id={$total}'>{$total}</a><div>";
?>
It is my method, but there are plenty of ways to do it. Maybe even too many. If you want more information you can always refer to the documentation.
<?php
$total=3;
echo '<div class="idsdiv">'.$total.'<div>';
?>
You're quote are missing before and after the $total
There is a problem in this code I can not detected
<?php echo "<a href ='$rows['Link']'> .$rows['UploadName']</a> "; ?>
Do you find you have a solution???
Thank you very much.
My guess is that your problem is that it isn't writing out the data in $rows['Link'] ... if that is the case, then your solution is to change it to {$rows['Link']} ... actually, you'll probably want to change both, since it looks like you started doing string concatenation and then switched halfway through.
So:
<?php echo "<a href ='$rows['Link']'> .$rows['UploadName']</a> "; ?>
becomes:
<?php echo "<a href ='{$rows['Link']}'>{$rows['UploadName']}</a> "; ?>
See: The PHP Manual on Variable Parsing in strings
It should be:
<?php echo "<a href ='{$rows['Link']}'>{$rows['UploadName']}</a>"; ?>
Or:
<?php echo "<a href ='{$rows['Link']}'>" . $rows['UploadName'] . "</a>"; ?>
There's a problem in parsing variables in the string. Use curl braces:
<?php echo "<a href ='{$rows['Link']}'> .{$rows['UploadName']}</a> "; ?>
Take a look to this php.net page, under "variable parsing".
More alternatives:
<?php echo '' . $rows['UploadName'] . ''; ?>
or
<?=('' . $rows['UploadName'] . '')?>
Another alternative (that I tend to prefer, given I know that both 'Link' and 'UploadName' are valid indices of $row.
<?=$rows['UploadName']?>
I'm not sure what that does for readability for most people, but on color-coded IDEs, it tends to help, because the HTML isn't just seen as one giant ugly single-colored string.