dowe98261 2016-03-08 20:35
浏览 41
已采纳

我可以在更改URL的同时使用jQuery .load吗?

What i want to achieve

I want to be able to shift seamlessly through the different posts in the sidebar on this website, while having using a custom post template for my posts. And by seamlessly i mean that the screen doesn't go white for a second every time you navigate it.

My problem

single.php or single-{slug}.php does not work, since the URL doesn't change while navigating the sidebar

Plugins i am using

Custom Post Type UI

Ajax Content Renderer

jQuery script for my sidebar

$(document).ready(function() {
    $("#sidebar li:has(a)").click(function() {

        var page = $("a:first",this).attr("href");

        $("#content").load(page);
        return false;
    });
});

HTML & PHP for sidebar and content area

<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 -->
  • 写回答

1条回答 默认 最新

  • duanqiao1947 2016-03-08 20:42
    关注

    Need to prevent the event on the <a>. So it would be better to move the selector to those elements

    Try:

    $(document).ready(function() {
      $("#sidebar li a").click(function() {
        var page = $(this).attr("href");
        $("#content").load(page);
        return false;
      });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊