php - Front-page.php url 蛞蝓
问题描述
我有一个非常简单的问题。我正在构建一个非常小且基本的网站,我在其中编写了一个简单的菜单。我希望菜单中的当前页面以黄色突出显示。
为了做到这一点,我添加了一个 if 语句来查找url slug,这是真的,将 CSS 类添加到那个特定的 HTML 元素。
适用于“服务”和“关于我们”,但主页呢?我为此使用什么 URL slug?此外,无论出于何种原因,我的“索引”url slug 都无法正常工作。
注意:“现代”类是改变颜色的 CSS 触发器。
<ul class="list-inline">
<!-- empty site_url() will default to front-page.php -->
<li class="list-inline-item modern"><a href="<?php echo site_url()?>" class="text-white lead"><h3 class="menu-items <?php if (is_page('http://modern-artisans--carpentry-version.local/')) echo "modern"?>">home</h3></a></li>
<li class="list-inline-item"><a href="<?php echo site_url('/services')?>" class="text-white lead"><h3 class="menu-items <?php if (is_page('services')) echo "modern"?>">services</h3></a></li>
<li class="list-inline-item"><a href="<?php echo site_url('/about-us')?>" class="text-white lead"><h3 class="menu-items <?php if (is_page('about-us')) echo "modern"?>">about us</h3></a></li>
<li class="list-inline-item"><a href="<?php echo site_url('/index')?>" class="text-white lead"><h3 class="menu-items <?php if (is_page('index')) echo "modern"?>">work history</h3></a></li>
</ul>
解决方案
您应该能够通过使用返回布尔值的 is_front_page() 来实现这一点。您可以将其放在菜单中的 if 语句中。
https://developer.wordpress.org/reference/functions/is_front_page/
推荐阅读
- android - 将 Flutter 命令行参数添加到 Android Studio
- java - Logger 和 FileHandler 在调用者的方法线程上执行?
- php - 从括号之间的特殊链接中提取文本
- ssl - 在 apache 服务器中保护 SSL 证书和私钥?
- laravel - 是否可以在 Laravel 中对 where 子句进行分组?
- java - 如何识别将在 java 类文件中使用的类
- react-native - React Native 项目中的 Google 助理?
- java - Cosmos DB的查询结果如何通过指定每页的条目数来执行分页?
- arrays - 如何修复由于索引而导致的绘图错误?
- vue.js - 我想看子组件中父组件的值