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条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭