TypeCho通过页面自定义字段给导航菜单加ICO

用的typecho默认主题,想在导航菜单前面根据各个页面的自定义字段加对应的图标符号

代码:

<div class="col-mb-12">
    <nav id="nav-menu" class="clearfix" role="navigation">
        <a<?php if($this->is('index')): ?> class="current" <?php endif; ?> href="<?php $this->options->siteUrl(); ?>" title="首页"><i class="fa fa-home" aria-hidden="true"></i> <?php _e('首页'); ?></a>
        <?php $this->widget('Widget_Contents_Page_List')->to($pages); ?>
        <?php while($pages->next()): ?>

        <a<?php if($this->is('page', $pages->slug)): ?> class="current" <?php endif; ?> href="<?php $pages->permalink(); ?>" title="<?php $pages->title(); ?>">
            <?php if (isset($this->fields->Font_Awesome)): ?>
                <i class="fa <?php $this->fields->Font_Awesome(); ?>" aria-hidden="true"></i> <?php $pages->title(); ?>
            <?php else: ?>
                <?php $pages->title(); ?>
            <?php endif; ?>
        </a>
        <?php endwhile; ?>

        <a href="<?php $this->options->feedUrl(); ?>" title="RSS" target="_blank"><i class="fa fa-rss-square" aria-hidden="true"></i> <?php _e('RSS'); ?></a>
    </nav>
</div>

页面自定义字段设置:
图片描述

在首页的显示效果:
图片描述

进入页面的显示效果:
图片描述

目前的问题:
在首页不显示,因为没有进入页面,所以无法获取到页面的自定义字段
进入页面后,所有页面都会变成一样的前置图标符号

个人不会PHP,边查资料边写出来的。
感觉我这个思路有问题,不行,特地发帖提问。
自己想到一个笨方法,直接把导航菜单Page_List的代码删除,导航菜单直接写死。但是这在后台新增一个页面,就需要到herader.php里面把页面加上去。

还是希望大佬们可以给个思路。应该怎么写。

阅读 4.2k
1 个回答

换了一种思路,不再纠结,已经实现自己想要的了。

<?php if (strpos($pages->permalink, 'About.html') !== false): ?>
    <i class="fa fa-user-circle" aria-hidden="true"></i><?php $pages->title(); ?>
<?php elseif (strpos($pages->permalink, 'Archives.html') !== false): ?>
    <i class="fa fa-archive" aria-hidden="true"></i><?php $pages->title(); ?>
<?php elseif (strpos($pages->permalink, 'Links.html') !== false): ?>
    <i class="fa fa-link" aria-hidden="true"></i><?php $pages->title(); ?>
<?php else: ?>
    <?php $pages->title(); ?>
<?php endif; ?>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题