首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重复get_header()

重复get_header()
EN

Stack Overflow用户
提问于 2015-02-02 19:21:31
回答 1查看 240关注 0票数 1

复制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。

代码语言:javascript
复制
<a class="more-info" href="#" data-href="<?php echo the_permalink()?>" ></a>

然后在我的javascript中:

代码语言: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.     
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-02 19:42:05

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

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

代码语言:javascript
复制
if(!isset($_GET['isAjax']) && $_GET['isAjax'] != 1)
{
   get_header();
}

希望这能回答你的问题。

编辑: ajax调用的,如果您使用.load(),那么

代码语言:javascript
复制
$( "#divtoload" ).load( "single-{custom-post-type}.php?isAjax=1" );  

应该这么做

编辑2:尝试此操作,然后将变量连接到url

代码语言:javascript
复制
$( ".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.   

另一个选择

代码语言:javascript
复制
<a class="more-info" href="#" data-href="<?php echo the_permalink()?>?isAjax=1" ></a>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28285149

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档