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 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办