我正在wordpress中创建菜单,我想添加class="active" 在其页面处于活动状态时进行链接。我没有使用内置的wordpress菜单功能。
我正在把菜单硬编码在标题中。php,因为此菜单链接到自定义posttype归档页面。所以如果有人在里面,我想保持课堂活跃single 或archive 该posttype的页面。
以下是我想做的:
header.php
<?php if ($post_type == "custom_post_type1") : ?>
<li><a href="link_to_post_type1_story" class="active">Post type 1</a><li>
<?php else: ?>
<li><a href="link_to_post_type1_story">Post type 1</a><li>
<?php endif; ?>
<?php if ($post_type == "custom_post_type2") : ?>
<li><a href="link_to_post_type2_story" class="active">Post type 2</a><li>
<?php else: ?>
<li><a href="link_to_post_type2_story">Post type 2</a><li>
<?php endif; ?>
我希望我能很好地解释我在寻找什么。谢谢