我想要实现的目标
我希望能够无缝切换本网站侧边栏中的不同帖子,同时为我的帖子使用自定义帖子模板。无缝我的意思是每次导航屏幕时屏幕都不会变白一秒钟。
我的问题
single.php 或 single-{slug}.php 不起作用,因为在导航侧边栏时 URL 不会更改
我正在使用的插件
自定义帖子类型 UI
Ajax 内容渲染器
我的侧边栏的jQuery脚本
$(document).ready(function() {
$("#sidebar li:has(a)").click(function() {
var page = $("a:first",this).attr("href");
$("#content").load(page);
return false;
});
});
侧边栏和内容区域的 HTML 和 PHP
<div class="row"> <!-- Main content row -->
<div class="col-md-4" id="sidebar">
<?php
if (is_page('gulvservice')){
wp_nav_menu(array('menu'=>'gulvservice' ));
} elseif (is_page('malerservice')) {
wp_nav_menu(array('menu'=>'malerservice' ));
} elseif (is_page('industrilakering')) {
wp_nav_menu(array('menu'=>'industrilakering' ));
}
?>
</div>
<div class="col-md-8" id="content">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="title"><h1>
<?php the_title(); ?>
</h1></div>
<div class="div">
<?php
if( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
</div>
<?php endwhile; endif; ?>
</div>
</div>
</div> <!-- Main Content -->
需要防止<a>
上的事件。所以最好将选择器移动到这些元素
尝试:
$(document).ready(function() {
$("#sidebar li a").click(function() {
var page = $(this).attr("href");
$("#content").load(page);
return false;
});
});