重复的get_header()

时间:2015-02-02 19:21:32

标签: php jquery wordpress wordpress-theming

重复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

发送网址
<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.     

1 个答案:

答案 0 :(得分:1)

对于您的单{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>
相关问题