重复 get_header()

Duplicate get_header()

重复get_header()问题!!!

我使用 jQuery 将单个 {custom-post-type}.php 插入首页的 ajax 容器中。我的单机{custom-post-type}.php使用wp函数get_header(),我的首页使用get_header(),所以一切都已经加载。所以当我加载我的自定义帖子时它崩溃了。

如果我从我的单曲中删除 get_header(){custom-post-type}.php 它可以正常加载到我的首页。但是当我在新页面中打开时,没有任何内容被加载,因为我没有 header.php 来加载所有样式、脚本等。

我已经尝试使用条件标签,但它不起作用。

有什么想法吗?

我正在这样做:

在我的首页中,我使用 data-href

发送 url
<a class="more-info" href="#" data-href="<?php echo the_permalink()?>" ></a>

然后在我的 javascript:

$( ".more-info" ).click(function(e){ 
    e.preventDefault();  
    var page = $(this).attr('data-href'); 
    lateralAnimation.init(page);
});

init : function(page){              
    $('#ajax-inserted').load(page)   
}   

//#ajax-inserted is where I load the content in my frontpage.     

对于你的单{custom-post-type}。php你可以检查你在使用jquery时添加的查询变量,例如"http://example.com/single-{custom-post-type}.php?isAjax=1"

然后在 php 中执行以下操作:

if(!isset($_GET['isAjax']) && $_GET['isAjax'] != 1)
{
   get_header();
}

希望这能回答您的问题。

编辑: 对于 ajax 调用,如果您使用的是 .load(),则

$( "#divtoload" ).load( "single-{custom-post-type}.php?isAjax=1" );  

应该做

编辑 2: 然后试试这个,这会将变量连接到 url

$( ".more-info" ).click(function(e){ 
    e.preventDefault();  
    var page = $(this).attr('data-href'); 
    lateralAnimation.init(page);
});

init : function(page){      
    //changed this line
    $('#ajax-inserted').load(page+"?isAjax=1)   
}   

//#ajax-inserted is where I load the content in my frontpage.   

或者

<a class="more-info" href="#" data-href="<?php echo the_permalink()?>?isAjax=1" ></a>