WordPress怎么在页面上添加目录

要实现的如下功能,在页面上添加一个文章目录:

   

步骤:

 
1)在wordpress中,在Posts----Categories中建立目录,
2)
3) add new post,指定post所属的category。
  
 
4)添加Categories至页面左侧边栏,这一步在外观-小工具里设置,把文章目录添加到左侧栏,有的主题没有左侧栏,那么需要修改代码:
     获取左侧栏内容的代码在当前主题的index.php页面上
              

<?php get_header(); ?>   --------这里是头部文件,获取菜单等

<div id="container">         ---------这里包含的是主页面内容

<div id="content" role="main">     

<?php get_template_part( 'loop', 'index' ); ?>  -------------获取文章内容
</div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>    -------这句用来获取你放在侧边栏的内容,如果你上一步把文章目录放在了侧边栏里,这里就能获取到

<?php get_footer(); ?>     ----------页脚内容

      我们如果想调整文章目录在整个页面是居左还是居右,在style.css文件中,查找 container的样式, 得到如下:

/*
LAYOUT: Two columns
DESCRIPTION: Two-column fixed layout with one sidebar right of content
*/

#container {
float: right;       ----------------这里写明container是居右
margin: 0 -240px 0 0;
width: 100%;
}
#content {
margin: 0 280px 0 20px;
}
#primary,
#secondary {    
float: left;      --------------------------这里说明文章目录所在的居左,如果需要改变,left/right互换
overflow: hidden;
width: 220px;
}
#secondary {
clear: left;      -------------------------这里说明文章目录所在的居左,如果需要改变,left/right互换
}
#footer {
clear: both;
width: 100%;
}

5)再换个其他主题之后,效果如下,点击相应的文章目录,可以看到对应的文章:
 
   
 
6)如果要目录第一次出现的时候,只显示一级目录:
     wp-includes-----category-template.php下,找到这个方法:
      

function wp_list_categories( $args = '' ) {
$defaults = array(
'show_option_all' => '', 'show_option_none' => __('No categories'),
'orderby' => 'name', 'order' => 'ASC',
'style' => 'list',
'show_count' => 0, 'hide_empty' => 1,
'use_desc_for_title' => 1, 'child_of' => 0,
'feed' => '', 'feed_type' => '',
'feed_image' => '', 'exclude' => '',
'exclude_tree' => '', 'current_category' => 0,
'hierarchical' => true, 'title_li' => __( 'Categories' ),
'echo' => 1, 'depth' => 0,   -----------------------------这里设置为1,可以默认显示为1级目录
'taxonomy' => 'category'
);

  
 
 
 

转载于:https://www.cnblogs.com/hiflora/p/3198737.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值