首页CMSTypecho博客如何调用菜单方法 - 分类/页面模块

Typecho博客如何调用菜单方法 - 分类/页面模块

时间2024-05-23 06:58:03发布访客分类CMS浏览411
导读:老蒋这几天在帮助一个前端同时熟悉Typecho主题的衔接,这个同事对于前端还是熟悉的,但是对于CMS的主题是不懂的,于是需要磨合熟悉,后面工作的时候才可以衔接。这里需要记录的是Typecho CMS程序菜单的调用,我们根据官方的调用方法记录...

老蒋这几天在帮助一个前端同时熟悉Typecho主题的衔接,这个同事对于前端还是熟悉的,但是对于CMS的主题是不懂的,于是需要磨合熟悉,后面工作的时候才可以衔接。这里需要记录的是Typecho CMS程序菜单的调用,我们根据官方的调用方法记录到菜单的调用。

1、官方菜单调用

 nav id="nav-menu" class="clearfix" role="navigation">
                        a?php if($this->
    is('index')): ?>
     class="current"?php endif;
     ?>
     href="?php $this->
    options->
    siteUrl();
     ?>
    ">
    ?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 $pages->
    title();
     ?>
    /a>
                        ?php endwhile;
     ?>
                    /nav>
    

这是官方默认主题调用方式,但是我们可以看到他只调用首页、页面,没有分类。

2、分类调用

 nav id="nav-menu" class="clearfix" role="navigation">
                        a?php if($this->
    is('index')): ?>
     class="current"?php endif;
     ?>
     href="?php $this->
    options->
    siteUrl();
     ?>
    ">
    ?php _e('首页');
     ?>
    /a>
                        ?php $this->
    widget('Widget_Metas_Category_List')->
    to($category);
     ?>
    ?php while($category->
    next()): ?>
    a?php if($this->
    is('category', $category->
    slug)): ?>
     class="current"?php endif;
     ?>
     href="?php $category->
    permalink();
     ?>
    " title="?php $category->
    name();
     ?>
    ">
    ?php $category->
    name();
     ?>
    /a>
    ?php endwhile;
     ?>
                    /nav>
    

这是只调用首页、分类的。然后我们可以根据官方的调用方式再衍生出来很多方式。对于CSS我们需要自定义设置,比如Current样式。

2、分类+页面方式

如果我们需要分类+页面的调用呢?

 nav id="nav-menu" class="clearfix" role="navigation">
                        a?php if($this->
    is('index')): ?>
     class="current"?php endif;
     ?>
     href="?php $this->
    options->
    siteUrl();
     ?>
    ">
    ?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 $pages->
    title();
     ?>
    /a>
    ?php endwhile;
     ?>
                        ?php $this->
    widget('Widget_Metas_Category_List')->
    to($category);
     ?>
    ?php while($category->
    next()): ?>
    a?php if($this->
    is('category', $category->
    slug)): ?>
     class="current"?php endif;
     ?>
     href="?php $category->
    permalink();
     ?>
    " title="?php $category->
    name();
     ?>
    ">
    ?php $category->
    name();
     ?>
    /a>
    ?php endwhile;
     ?>
                    /nav>
    

两者合并起来即可。

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: Typecho博客如何调用菜单方法 - 分类/页面模块
本文地址: https://pptw.com/jishu/666142.html
ZBLOG模板制作常备缩略图调用方法(4个方法任意选) Caffe框架的未来发展趋势是什么

游客 回复需填写必要信息