Sep 10

一直想做一个实时预览文章的东西,却不知道做在哪好。现在终于完成了,请看本站的“文章检索”页面。

舍弃了华丽但是臃肿的af-extended-live-archive,换用了Viper007Bond同学的Clean Archives Reloaded,特别欣赏作者对JS代码随用随载的方法,而不是一股脑全往Header里面丢。

看到文章列表后面那个小图标了吗?点它!---这就是我加的一点小佐料:文章实时预览。

参考ajaxwp,改变思路,用WordPress原本的方式渲染文章,用脚本访问 ajax-wp.php:


<?php
/**
 * AjaxWp - An AJAX enchancement for Wordpress
 * Copyright (c) 2006, Gianni Milanesi <gianni@giannim.com>
 *
 * AjaxWp is freely distributable under the terms of an MIT-style license.
 * For details, see the AjaxWp web site: http://www.giannim.com/projects/ajax-wp
 *
 */
	$postid = $_GET['postid'];
	require('../../../wp-blog-header.php');
	// Load the requested posts
	query_posts('p='.$postid);
	include("ajax-single.php");
?>

其中ajax-single.php则为原模板single.php去掉头尾等多余内容而来:


<div id="content">
	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
		<div class="entry">
		<div class="post" id="post-<?php the_ID(); ?>">
			<h2><a href="<?php echo get_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title('-image-'); ?></a></h2>
			<?php the_content('<p class="serif">Read the rest of this entry &raquo;</p>'); ?>
			<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?><br />
	<?php endwhile; else: ?>
		<div class="entry">
			<p>Sorry, no posts matched your criteria.</p>
		</div>
    <?php endif; ?>
</div>

我希望能得到一些意见建议,如果把这东西处理好了,做成插件应该是蛮好的。