Im using wordpress for a website and i have a problem with these PHP code:
global $wpdb;
$proy = $wpdb->get_results($wpdb->prepare ("select * from proyectos"));
foreach ( $proy as $proyecto)
{
$route = $proyecto->ruta; // THE PROBLEM IS WITH THIS
echo $route;
echo "<div style=background-image: url('".$route."'); class=element data-category=$proyecto->tipo /><p class=number>$proyecto->idP</p><h2 class=name>$proyecto->nombre</h2></div>";
}
So, im creating some divs and i want them to load an image as background. Query is correct, the problem is with the $route.
Making echo $route
shows this:../wordpress/wp-content/uploads/2013/12/image.jpg
now when i make this: style=background-image: url('".$route."');
and i reload the page it renders this: style=background-image: url('.. wordpress wp-content uploads 2013 12 image.jpg').
It replaces the /
for a blank
.
Please, any help or solutions?
Other valuable info: Im using PHP Code Snippet plugin for wordpress and Chrome browser.
Thank you.
Thanks NoobEditor!! I found the solution finally !! Here is the code:
$route ="'".$proyecto->ruta."'";
echo'<div style="height:150px;width:150px;float:left;background-image:url('.$route.')">
<p class=element>$proyecto->tipo</p></div>';
It renders the route perfectly and loads the image.
I am not a wordpress guy...but, looks to me that incorrect markup for css is being echo
ed :
general rule is =>
<div style="" ></div>
__^^__missing these quotes in below lines:
<div style=background-image: url('".$route."'); class=element data-category=$proyecto->tipo /><p class=number>$proyecto->idP</p><h2 class=name>$proyecto->nombre</h2></div>
change it to :
echo '<div style="background-image: url("'.$route.'"); class=element data-category=$proyecto->tipo /><p class=number>$proyecto->idP</p><h2 class=name>$proyecto->nombre</h2></div>';