What Im trying to do is write a script that grabs the url of thumbnails attached to posts in wordpress. It sounds really easy(as I'm sure the solution is) but I can't seem to get it to work, I keep getting syntax errors no matter what I try. The problem line is the second echo(Img src...). Any help would be greatly appreciated.
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'archive-thumb');
$image_url = $image_url[0];
echo "<li class=\"recent-img-widget-li\"><a href='".get_permalink()."'>;
echo "<img src=\"".$image_url."\" width=\"120\" height=\"120\">";
echo "</a></li>";
Simply enough, you're not closing your first string after get_permalink(). Yo need another quote after the >.
You never close the first string. You just need a quote before the greater than on the first line (and possibly the second?). Look at the syntax highlighting that SO has.
A general guideline is to always look at the row above the one that is giving the error.
In this case you have forgotten to end the string in the last part of the first echo statement.
...ermalink()."'>;
Should be
...ermalink()."'>";
For one you should close that first echo. Missing the closing "
Related
I have a link that I would like to open a page in a pop up, the link and onclick work fine but open it in a new full window but when I add the part after '_blank' it stops working. Here's my code
echo '<li>'.$img.''.$item_name.'</li>';
I suspect there is a typo or a problem with my syntax but I can't find it.
Any help would be appreciated
echo '<li>'.$img.''.$item_name.'</li>';
echo '<li>'.$img.'test'.$item_name.'</li>';
You are missing some closing single quotes in the window.open arguments, and the arguments you are passing are slightly incorrect. _blank is a separate argument from URL (the first argument,) URL needs a closing single quote, and NAME needs an opening single quote. corrected code is below
echo('<li>' . $img . '' . $item_name . '</li>');
echo '<td>'.$row_sv['name'].'</td>';
I don't want to use any target and changed it like this but it messed up my table
echo '<td><a href="'.$row_sv['website].'$row_sv['name'].'</a></td>';
something wrong?
To make such pieces clearer I prefer using templates. In your case that would be:
printf( '<td>%s</td>', $row_sv['website'], $row_sv['name'] );
No mess with the quotes and opening/closing tags.
You should use the following:
echo '<td>'.$row_sv['name'].'</td>';
You mixed up the quotes a bit:
echo '<td>'.$row_sv['name'].'</td>';
You deleted too much, and then messed up something that was ok to begin with.
Use:
echo '<td>'.$row_sv['name'].'</td>';
In addition to deleting too much, you also had $row_sv['website] instead of $row_sv['website'] which should've cause a parse error too (unless it was just a typo here).
In the future here, you could also paste the HTML output instead of saying "it messed up my table" -- it'll make it easier for you to see the problem as well as folks here, I am sure.
I'm trying to display an image file from a directory using a PHP echo command and an IMG tag.
Here is the code:
//These variables represent the file name extensions from a form element from a previous page
$bannerimg=$_POST["banimg"];
$adimage=$_POST["adimage"];
echo "<img src='imgdir/'".$bannerimg."/>";
When I echo out the file variables ($bannerimg and $adimage) I get the proper file name and extension.
In theory, will this work? If so, what is the proper syntax to handle that echo statement?
Thanks for all the help.
Dustin
Yes it would work, but you should have tested that already.
Alternative syntaxes to the echo statement that I find a little bit more readable would be:
echo "<img src='imgdir/{$bannerimg}/>";
echo "<img src='imgdir/$bannerimg/>";
You can read all about variable parsing in the manual, the first syntax is the complex one and the second the simple. I prefer the complex one as the end of the variable is clearly defined and you can use it for complex expressions, not just simple variables.
You're doing it right but you can use the following just to keep it clean.
echo "<img src='imgdir/$bannerimg' />";
It should work.
To Sandeep's comment, I would have gone the other way.
echo '<img src="imgdir/'.$bannerimg.'/>';
Using " means the parser needs to check to see if there is anything to evaluate.
I barely know how to use PHP and I can't seem to make my code show an image if a condition proves true. This is the code:
<?php
$search=get_search_query();
$first=$search[0];
if ($first=="#"){
}
?>
I tried writing this thinking it would work and it didn't:
echo "<html>";
echo "<img src='http://chusmix.com/Imagenes/grupos/lujan.jpg'>";
Also I tried a code I found which started with the function: header() but it caused a tremendously long error, which said something like header already defined.
Thanks
You have used 'double quotes' incorrectly in the echo statement.
Try the following:
echo "<img src='http://chusmix.com/Imagenes/grupos/lujan.jpg' alt='Preview not available' />"
Regards,
Mahendra Liya.
You should var_dump($first) to know what it contains
check if the condition is really getting true
and also put single quote inside the double quote.
if ($first=="#"){
echo 'yes it is true';
echo "<img src='http://chusmix.com/Imagenes/grupos/lujan.jpg'>";
}
close the img tag
The part of the query string starting with # (so-called "hash") is not being sent to the server. That is, if your page is called like myblog.com/foo?bar=baz#quux, you php script will only receive myblog.com/foo?bar=baz. You need javascript if you want to handle urls with hashes.
I can't really find good guidelines through Google searches of the proper way to escape variables in URLs. Basically I am printing out a bunch of results from a MySQL query in a table, and I want one of the entries in each row to be a link to that result's page. I think this is easy, that I'm just missing a apostrophe or backslash somewhere, but I can't figure it out. Here's the line that's causing the error:
echo " Who Owns It? ";
and this is the error I'm getting:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
How do I fix this error?
In addition, what are some general guidelines for working with echo and variables in URLs?
echo " Who Owns It? ";
There are two things here that should be changed. For one thing there shouldn't be a / after movies.php. The second is that there aren't any apostrophies around url variables. It should be movie_id=$row['movie_id']. Whenever I use a php variable I usually concatonate it instead of embed it in the quotations. So in the end I'd do something like this:
echo " Who Owns It? ";
The $row['movie_id'] inside the double quoted string is not allowed (especially the single quotes). Either write it without ' or use the curly braces syntax:
echo " Who Owns It? ";
echo " Who Owns It? ";
See variable parsing for further information.
This is a better way:
$movie_id = urlencode($row["movie_id"]);
echo ' Who Owns It? ';
Good luck!
This is a better(er) way:
$movie_id = urlencode($row["movie_id"]);
echo " Who Owns It? ";
Easier to read. Besides the single and double quote speed thing is not much of an issue any more.
Echo or URLs have nothing to do with your problem. It's PHP strings syntax.