原來 Liboseo 使用的是直接在文章模版裏的文章下面添加代碼,我使用的是 WordPress 官方的 twentyten 主題修改的,所以編輯主題裏的loop-single.php,找到下面這段代碼:
<div >
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div
>' . __( 'Pages:', 'twentyten' ), 'after' =>
'</div>' ) ); ?>
</div><!-- .entry-content -->
在
<?php the_content(); ?>
後面直接加入下面的代碼:
<pre> 轉載請註明來自<a
>CMS 集中營</a>,本文地址:<a href=<?php
the_permalink(); ?>' title='<?php the_title(); ?>'><?php
the_permalink(); ?></a>
除非註明,CMS 集中營文章均為原創,轉載請註明出處和鏈接!</pre>
但是出了個問題,就是如果安裝了一些 wumii 或者百度分享之類的插件的話,上面添加的內容只能顯示在無覓之類的下面,而不是緊緊貼着文章。顯然這個不是我們要的效果。
經過各種測試,終於通過主題的自定義函數解決了。
方法很簡單,因為之所以我們添加的內容不能緊貼着文章,就是因為這些插件將內容插入到了 the_content(); 函數裏,而這個函數是
WordPress 程序默認的函數。我們如果直接修改 the_content(); 函數,那麼如果升級 WordPress 程序的話,就會被覆蓋。
於是我通過在主題的functions.php文件,在最下面添加了一個自定義的函數 liboseo_content();,內容如下:
function liboseo_content($more_link_text = null, $stripteaser = 0) {
$content = get_the_content($more_link_text, $stripteaser);
$content.= "<pre> 轉載請註明來自<a >CMS 集中營</a>,";
$content.= "本文地址:<a href='".get_permalink($post, true)."'
title='".get_the_title($post_id)."'>".get_permalink($post,
true)."</a>";
$content.= "
除非註明,CMS 集中營文章均為原創,轉載請註明出處和鏈接!</pre>";
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
然後把主題中的文章模版裏的 the_content(); 替換成自定義的函數,比如我用的主題模版文件是 loop-single.php,就直接將 the_content(); 修改成 liboseo_content();,變成了:
<div >
<?php liboseo_content(); ?>
<?php wp_link_pages( array( 'before' => '<div
>' . __( 'Pages:', 'twentyten' ), 'after' =>
'</div>' ) ); ?>
</div><!-- .entry-content -->
保存一下看看吧,是不是成功了?修改之前一定要備份原來的文件,如果可能的話,最好在本地測試好之後,再在網站上修改。