WP本身只会系文章类的页面加 rel="canonical"、rel="prev"、rel="next" 元素。
如果你的主题没系普通的归档类页面加果三个嘢的话,可以直接用我下边的代码(我主题用紧的)
系主题的header.php内</head>完之前加入以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<?php function bdCleanUrlAndS($sUrl) { $arrtemp1 = explode('?', $sUrl ) ; $link = rtrim($arrtemp1[0] , '/' ) ; return $link; } if ( !is_singular() ) { $urltemp1 = get_bloginfo('url') . $_SERVER['REQUEST_URI'] ; $link = bdCleanUrlAndS($urltemp1) ; echo "<link rel='canonical' href='$link' />\n"; $temptext = get_previous_posts_link(''); preg_match_all("/href=\"(.*)\"/iU", $temptext, $matches); $max = count($matches[0]); if (0 < $max) { $link = bdCleanUrlAndS($matches[1][0]) ; echo "<link rel='prev' href='$link' />\n"; } $temptext = get_next_posts_link(''); preg_match_all("/href=\"(.*)\"/iU", $temptext, $matches); $max = count($matches[0]); if (0 < $max) { $link = bdCleanUrlAndS($matches[1][0]) ; echo "<link rel='next' href='$link' />\n"; } } ?> |
如果想去掉那个prev 和next的文章导航,应该在哪里去掉? 我在主题文件里找了半天 没找到 莫非在WP文件中?
我是用get_adjacent_post取得,你搜索一下主题内的文件,没的话自己慢慢分析一下single之类的文件。