WORDPRESS自定义备忘录

本文所述,基于wordpress 2.8.4 和 iNove 1.4.6

WORDPRESS中使用相对链接实现多域名访问的方法

注释掉wp-includes/function.php文件中第361和362行(2.8.4版本,其他版本可能略有不同)。即

1.// If home is not set use siteurl.
2. if ( 'home' == $setting && '' == $value )
3. return get_option( 'siteurl' );

没有简介时,将<!–more–>前的内容作为简介,wp-includes/post-template.php 247行

/**
 * Retrieve the post excerpt.
 *
 * @since 0.71
 *
 * @param mixed $deprecated Not used.
 * @return string
 */
function get_the_excerpt($deprecated = '') {
 global $post;
 $output = '';
 $output = $post->post_excerpt;
 if ( post_password_required($post) ) {
 $output = __('There is no excerpt because this is a protected post.');
 return $output;
 }
 if(!$output){
 return get_the_content('');
 }
 return apply_filters('get_the_excerpt', $output);
}

模板里加入站点图标, templates/start.php

加上站点LOGO
上传alan.png到img下
style.css加上:

#caption img{float:left; border:2px solid #fff; height:40px; margin-right:10px;margin-top:-0px;}

更改templates/header.php,第2行

<div id="caption">
 <img src="http://www.everalan.com/blog/wp-content/themes/inove/img/alan.png"/><h1 id="title"><a href="<?php bloginfo('url'); ?>/"><?php bloginfo('name'); ?></a></h1>
 <div id="tagline"><?php bloginfo('description'); ?></div>
 </div>

更改内容字体大小, style.css 461行

.post .content {
line-height:145%;
font-size:14px;
overflow:hidden;
padding:5px 0 0 5px;
}

删除WPRDPRESS自带的分页,index.php中

<div id="pagenavi">
<?php if(function_exists('wp_pagenavi')) : ?>
<?php wp_pagenavi() ?>
<?php else : ?>
<span><?php previous_posts_link(__('Newer Entries', 'inove')); ?></span>
<span><?php next_posts_link(__('Older Entries', 'inove')); ?></span>
<?php endif; ?>
<div></div>
</div>

列表改为显示简介,而不是全文, index.php,archive.php

the_content(__('Read more...', 'inove'));
 //改成
the_excerpt(__('Read more...', 'inove'));

边栏去掉west和east, sidebar.php去掉以下几行

<div id="centersidebar">

 <!-- sidebar east START -->
 <div id="eastsidebar">
 <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('east_sidebar') ) : ?>

 <!-- categories -->
 <div>
 <h3>Categories</h3>
 <ul>
 <?php wp_list_cats('sort_column=name&optioncount=0&depth=1'); ?>
 </ul>
 </div>

 <?php endif; ?>
 </div>
 <!-- sidebar east END -->

 <!-- sidebar west START -->
 <div id="westsidebar">
 <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('west_sidebar') ) : ?>

 <!-- blogroll -->
 <div>
 <h3>Blogroll</h3>
 <ul>
 <?php wp_list_bookmarks('title_li=&categorize=0'); ?>
 </ul>
 </div>

 <?php endif; ?>
 </div>
 <!-- sidebar west END -->
 <div></div>
</div>

rss放到最下边,sidebar.php 将以下文字移动到

结尾处

<!-- feeds -->
 <div>
 <div>
 <div id="subscribe">
 <a rel="external nofollow" id="feedrss" title="<?php _e('Subscribe to this blog...', 'inove'); ?>" href="<?php echo $feed; ?>"><?php _e('<abbr title="Really Simple Syndication">RSS</abbr>', 'inove'); ?></a>
 <?php if($options['feed_readers']) : ?>
 <ul id="feed_readers">
 ......
 </ul>
 <?php endif; ?>
 </div>
 <?php if($options['feed_email'] && $options['feed_url_email']) : ?>
 <a rel="external nofollow" id="feedemail" title="<?php _e('Subscribe to this blog via email...', 'inove'); ?>" href="<?php echo $options['feed_url_email']; ?>"><?php _e('Email feed', 'inove'); ?></a>
 <?php endif; if($options['twitter'] && $options['twitter_username']) : ?>
 <a id="followme" title="<?php _e('Follow me!', 'inove'); ?>" href="http://twitter.com/<?php echo $options['twitter_username']; ?>/"><?php _e('Twitter', 'inove'); ?></a>
 <?php endif; ?>
 <div></div>
 </div>
 </div>

利用自定义域rate,和pv增加编辑推荐小工具wigest和热门文章小工具,在sidebar.php里加上

<div>
 <h3>热门文章</h3>
 <ul>
 <?php
 $posts = get_posts('numberposts=10&meta_key=pv&orderby=meta_value');
 foreach($posts as $post) {
 setup_postdata($post);
 echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
 }
 $post = $posts[0];
 ?>
 </ul>
 </div>
<div>
 <h3>精华文章</h3>
 <ul>
 <?php
 $posts = get_posts('numberposts=10&meta_key=rate');
 foreach($posts as $post) {
 setup_postdata($post);
 echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
 }
 $post = $posts[0];
 ?>
 </ul>
 </div>

以meta_value排序是可以以数值排序,现在是以字符串排序。wp-includes/query.php 2033行左右:

$allowed_keys = array('author', 'date', 'title', 'modified', 'menu_order', 'parent', 'ID', 'rand');
 if ( !empty($q['meta_key']) ) {
 $allowed_keys[] = $q['meta_key'];
 $allowed_keys[] = 'meta_value';
 $allowed_keys[] = 'meta_value*1';
 }
//以及
case $q['meta_key']:
 case 'meta_value':
 $orderby = "$wpdb->postmeta.meta_value";
 break;
 case 'meta_value*1':
 $orderby = "$wpdb->postmeta.meta_value*1";
 break;

当然,前提是你文章里加上自定义域rate

导航菜单以文章数排序,更改templates/header.php,改成以下代码

<?php
 if($options['menu_type'] == 'categories') {
 wp_list_categories('&title_li=0&orderby=count&order=desc&show_count=0');
 } else {
 wp_list_pages('title_li=0&sort_column=menu_order');
 }
 ?>

尾文件上加上备案和PV统计, footer.php

<a href="http://www.miibeian.gov.cn/" target="_blank">&#20140;ICP&#22791;09024899&#21495;</a>
<div style="display:none">
 <!-- cnzz -->
 <script src="http://s26.cnzz.com/stat.php?id=xxxxxweb_id=yyyyy&show=pic1" language="JavaScript" charset="gb2312"></script>
<script type="text/javascript" src="<?=get_option('home')?>/pv.php"></script>
</div>

发表评论

电子邮件地址不会被公开。

*