复制get_header()问题!
我使用jQuery将单{custom-post-type}.php插入到头版的ajax容器中。我的单{custom-post-type}.php使用wp函数get_header(),我的首页使用get_header() to,所以所有东西都已经加载了。所以当我加载我的定制帖子时,它就崩溃了。
如果我将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. 发布于 2015-02-02 19:42:05
对于单{自定义post类型}.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>https://stackoverflow.com/questions/28285149
复制相似问题