douhai5835 2012-09-26 00:30
浏览 21
已采纳

如何连接PHP变量以在菜单中使用

I'm not a PHP guy, however I believe PHP can be used to accomplish this.

Basically I'm using the same absolute path in my main menu + /about, /blog etc so figured well my files are already PHP why not use a Var to do this :) (I come from a Flash AS background)

Testing link: http://s433108212.onlinehome.us/

This is what I've tried below, but to no avail :(

<div id="nav_bar">

<?php $athenasweburl = 'http://s433108212.onlinehome.us/'; ?>

<ul class="nav">
    <li class="<?php echo $page === 'home' ? "selected" : "" ?>"><a href="<?php $athenasweburl; ?>">Home</a></li>
    <li class="<?php echo $page === 'about' ? "selected" : "" ?>"><a href="<?php echo ($athenasweburl+'about'); ?>">About</a></li>
    <li class="<?php echo $page === 'blog' ? "selected" : "" ?>"><a href="<?php $athenasweburl+'blog'; ?>">Blog</a></li>
    <li class="<?php echo $page === 'book' ? "selected" : "" ?>"><a href="<?php $athenasweburl+'book'; ?>">Book</a></li>
    <li class="<?php echo $page === 'events' ? "selected" : "" ?>"><a href="<?php $athenasweburl+'events'; ?>">Events</a></li>
    <li class="<?php echo $page === 'services' ? "selected" : "" ?>"><a href="<?php $athenasweburl+'services'; ?>">Services</a></li>
    <li class="<?php echo $page === 'contact' ? "selected" : "" ?>"><a href="#dialog" name="modal">Contact</a></li>
    <li class="search"><input type="text" onfocus="if(this.value == 'Search') { this.value = ''; }" value="Search" /></li>
    <li class="search_btn"><a href="#" title="Lets find it!"><div class="search_go">Go</div></a></li>
</ul>

thoughts anyone?

  • 写回答

4条回答 默认 最新

  • droi5225 2012-09-26 00:35
    关注

    In PHP + adds numbers together.. What you looking for is gluing strings.. Replace the + signs with . (dot), and an echo in front of each string, and it should work.

    <div id="nav_bar">
    
    <?php
    $menu = array("home","about","blog","book","events","services");
    function echoListItem($item){
        global $page;
        $url = 'http://s433108212.onlinehome.us/';
        if($item != "home") $url .= $item;
        $selected = $item == $page ? 'selected' : '';
        echo '<li class="'.$selected.'"><a href="'.$url.'">'.ucfirst($item).'</a></li>';
    }
    ?>
    
    <ul class="nav">
        <?php array_walk($menu, 'echoListItem'); ?>
        <li class="<?php echo $page === "contact" ? "selected" : "" ?>"><a href="#dialog" name="modal">Contact</a></li>
        <li class="search"><input type="text" onfocus="if(this.value == 'Search') { this.value = ''; }" value="Search" /></li>
        <li class="search_btn"><a href="#" title="Lets find it!"><div class="search_go">Go</div></a></li>
    </ul>
    

    This should do just about the same!

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

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab