dtukyb8095 2016-02-01 22:43
浏览 43

静态/动态页面上的Wordpress方式URL

I would like to add a menu or footer like in Wordpress or any other CMS.

That really dont work with PHP includes because if a website file is in subdirectory there is a problem with the path. As you know a normal static menu looks like

<nav>
  <ul>
      <li><a href="about.php">About</a></li>

   </ul>
</nav>

but CMS menu looks like

<nav>
  <ul>
      <li><a href="/about/">About</a></li>
  </ul>
</nav>

And that on all pages so no problems with the path if you try it with static/dynamic pages you have to add the path or the url and that looks really ugly or not

<?php
define('WEB_ROOT', '../');  // relative path to /
?>
...
<nav>
  <ul>
      <li><a href="../../solution/">Solution</a></li>
       or
      <li><a href="https://example.com/solution/">Solution</a></li>
       or
      <li><a href="<?php echo WEB_ROOT; ?>solution">Solution</a></li>

  </ul>
</nav>

I think thats a bad idea and really ugly. so how to solve that kind of problem maybe with adding a web root in php like above but looks not really good so do you have any other ideas? And that Solution should also work for CSS and JS not only for static contents, so all styles are same and menus looks just like the other pages even if it is in the subdirectories

  • 写回答

2条回答 默认 最新

  • dongwo2222 2016-02-01 22:48
    关注

    Generally in Wordpress I use the site url to generate full urls:

    site_url('/about');

    As for JS/CSS files, it depends where you are putting them. If the files are located in a specific theme use:

    get_template_directory();

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题