在网站上我离开了菜单,该菜单几乎出现在每个子页面上
<div class="category_menu">
<nav class="cat_menu">
<div class="menu_title parent_cat_name">
<h6><?php echo $category->name; ?></h6>
</div>
<?php rs_left_menu_subcats($subcategories); ?>
</nav>
</div>
如果网站是主页,我想显示另一个菜单。在其他情况下,它应该是我粘贴的代码的菜单。
我可以使用哪些代码?
答案 0 :(得分:4)
您可以合并is_front_page()
和is_home()
Wordpress功能。
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ HelloWorld ---
[INFO] >>> cobertura-maven-plugin:2.7:cobertura (default-cli) > [cobertura]test @ HelloWorld >>>
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ HelloWorld ---
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ HelloWorld ---
[INFO] --- cobertura-maven-plugin:2.7:instrument (default-cli) @ HelloWorld ---
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ HelloWorld ---
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ HelloWorld ---
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ HelloWorld ---
[INFO] <<< cobertura-maven-plugin:2.7:cobertura (default-cli) < [cobertura]test @ HelloWorld <<<
[INFO] --- cobertura-maven-plugin:2.7:cobertura (default-cli) @ HelloWorld ---
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ HelloWorld ---
[INFO] --- maven-install-plugin:2.4:install (default-install) @ HelloWorld ---
答案 1 :(得分:2)
如果您想在wordpress主页上显示特定内容,请使用is_front_page()
if ( is_front_page() ) {
// your menu code goes here for home page
}
答案 2 :(得分:0)
变体与php - 由@hardik solanki回答
CSS的变体:
.home .category_menu { display: block; }
答案 3 :(得分:0)
由于对我来说is_front_page()
和is_home()
不起作用(WP 5.2.3),所以我写了这样的条件:
global $wp;
$current_url = home_url(add_query_arg(array($_GET), $wp->request));
if ($current_url==get_site_url()) {
// code for homepage
}