dqeonr8554 2014-01-17 11:39
浏览 76
已采纳

在wordpress查询中遇到相对路径问题

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.

  • 写回答

2条回答 默认 最新

  • dongnanman9093 2014-01-20 14:45
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程