2015-09-05 81 views
1

我需要获取cuurent页面类型。在wordpress中获取当前页面类型

Whene我使用这个func的任何其他功能的作品!

function get_current_page_name(){ 
    if (is_home() || is_front_page()) 
     return 'is_home'; 
    else 
     return 'is_page'; 
} 

但whene我在主页上使用这样的

function my_function(){ 
    echo get_current_page_name(); /// returns 'is_page' 
} 

此功能与阿贾克斯

回答

0

我检查调用,它似乎为我工作。

你能指定你使用的是什么版本的WordPress吗?有没有安装插件?你究竟把这个代码放在哪里?

在我的测试案例中,我将其添加到我的functions.php文件中。

function get_current_page_name(){ 
    if (is_home() || is_front_page()) 
     return 'is_home'; 
    else 
     return 'is_page'; 
} 

function my_function(){ 
    echo get_current_page_name(); 
} 

而这对我的index.php文件。

<?php 
    my_function(); 
?> 

This Works。

如果我会选择主页,在WordPress设置一些静态的页面,并把相同的,但在page.php文件时,它仍然有效,并返回is_home

+0

它是AJAX代码 - 这是在functions.php的 –

+0

您需要提供您正在使用的更具体的代码。此处显示的代码运行良好。问题在你的代码中的其他地方。请用你的具体用例来扩展你的问题。 –