VPS参考、测评、推荐
分享你关注的VPS主机优惠信息

WordPress文章怎么快速方便的生成目录索引?WordPress文章目录索引怎么生成?

WordPress文章怎么快速方便的生成目录索引?WordPress文章目录索引怎么生成?

文章相当于文章目录。点击目录自动跳转到对应位置,这就需要你的文章有字幕,那么WordPress文章如何生成目录的呢?要做的就自动识别h3标签并组装成一个目录,好了,开始实现方法吧。

WordPress文章怎么快速方便的生成目录索引?WordPress文章目录索引怎么生成?

一、实现方法

文章中必须有一个h3标签,每个三级标题都会成为索引中的一个条目。将以下代码放入.中,您的文章中会自动生成一个索引。

  1.  article_nav($content)
  2. {
  3.     $matches = array();
  4.     $ul_li = ;
  5.     $r = “/

    (.*?)

    /
    ;
  6.     if (preg_match_all($r$content$matches)) {
  7.         foreach ($matches[1] as $num => $title) {
  8.             $content = str_replace($matches[0][$num], ‘

    “article_nav_’ . $num . ‘”>’ . $title . ‘

    ’, $content);
  9.             $ul_li .= ‘
  10. “#article_nav_’ . $num . ‘” title=“‘ . $title . ‘”>’ . $title . 
  11. ”;
  12.         }
  13.         if (is_singular()) {
  14.             $content = ‘
    “fn_article_nav”>
    “article_nav_title”>Article Nav
    ’ . $content;
  15.         }
  16.     }
  17.     return $content;
  18. }
  19. add_filter(“the_content”“article_nav”);

 

二、索引样式

生成了索引,但只是文章中的一个普通的ul列表。需要做的就是把它分开,所以只需要为它写一个css样式就了。建议使用 position:fixed 将其固定在左侧或右侧。下面了一个参考样式,根据自己的情况进行

  1. #article_nav_title{font-size:11px;text-align:center;line-height:15px;color:#cc0000;border-left:3px #cc0000 solid;border-bottom:1px #aaa dotted}
  2. #fn_article_nav{position:fixed;left:5px;top:140px;background-color:rgba(255,255,255,.55);border-radius: 0 3px 3px 0;box-shadow:0 0 2px #aaa}
  3. #fn_article_nav ul{padding:0!important;margin:0px!important}
  4. #fn_article_nav li{list-style:none;padding:3px;width:100px;margin:0;backgroundurl(“images/li.png”no-repeat scroll 0 5px transparent!important;text-indent: 1.6em;}

:WordPress文章快速方便的生成目录索引?WordPress文章目录索引生成?,://.caogenba.com.com/68897.html

如今做站的人不多了,多个朋友多条路子,加入站长和大佬们同道交流,Tips:可以免费打广告哦~ 点击立即加入>>

赞(0) 打赏
未经允许不得转载:草根吧VPS_最新VPS信息参考 » WordPress文章怎么快速方便的生成目录索引?WordPress文章目录索引怎么生成?
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址