我在我的WordPress网站,single.php中的循环中,选择标签中的选项是通过自定义查询返回的当前类别的职位。
在改变所选的选项,我有一个运作良好众多JavaScript函数,但其中最后一个功能( function f_next-previous
),似乎没有工作。
该功能的目的是更新下一个和以前的链接无需重新加载页面。
相对于导航链接的代码在我的模板(下一个和以前)运作良好,是上面:
<div id="nav-above" class="navigation">
<div class="nav-previous"><?php previous_post_link( '%link', '<img height="34" src="' . get_bloginfo("template_directory") . '/images/previous.png" />' ); ?></div>
<div class="nav-next"><?php next_post_link( '%link', '<img height="34" src="' . get_bloginfo("template_directory") . '/images/next.png" />' ); ?></div>
</div><!-- #nav-above -->
此功能的JavaScript代码:
function f_next-previous(id)
{
$.ajax({
cache: true,
type: "GET",
timeout: 5000,
url: 'wp-content/themes/twentyten/pages/next-previous.php?p='+id,
success: function(msg)
{
$('#nav-above').html(msg);
},
error: function(msg)
{
alert("Your browser broke!");
return false;
}
});
}
该文件next-previous.php
内容是:
<?php
$p=$_GET['p'];
require( '../../../wp-load.php' );
$my_query = new WP_Query();
$my_query->query(array( 'post__in' => array($p)));
if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="nav-previous"><?php previous_post_link( '%link', '<img height="34" src="' . get_bloginfo("template_directory") . '/images/previous.png" />' ); ?></div>
<div class="nav-next"><?php next_post_link( '%link', '<img height="34" src="' . get_bloginfo("template_directory") . '/images/next.png" />' ); ?></div>
<?php
endwhile;
endif;
?>
虽然给它一个值p参数测试此PHP文件,它提供了在浏览器中的逻辑结果。 jQuery和功能的脚本也包括在内,所有AJAX在我的网站就可以了。 那我在这工作缺少????
更新:请注意,我single.php中的部分文件负责触发AJAX调用是:
<form method="post" action="">
<select class="select2" name="" id="" >
<option value="<?php the_ID();?>"><?php the_title();?></option>
<?php
global $post;
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$myposts = get_posts("paged=$paged&category=4");
foreach($myposts as $post) :?>
<option value="<?php the_ID();?>"><?php the_title();?></option>
<?php endforeach;
wp_reset_postdata(); ?>
</select>
</form>