WordPress 排除页面插件 hack

发布于 2024-10-15 14:56:36 字数 1029 浏览 2 评论 0原文

我希望 WordPress 排除页面插件能够与我的主题配合使用。这是我的主题查询所有页面并将它们全部显示在单个页面上的行中的地方。

$pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' ORDER BY menu_order", ARRAY_A);

foreach ($pagepull as $single_page){
    echo $single_page['post_content']; 
    // do other stuff too
}

您对如何调整查询以使用排除页面有什么想法吗?没有获取所有页面的功能吗?我知道有 wp_list_pages() 来获取页面列表,但我不想在这里显示导航。

执行 2 次查询(1 次获取页面列表,然后 2 次查询该列表)是否会更好?不完全确定如何做到这一点,但额外的查询听起来是个坏主意。想法?

更新: 从下面的答案中我发现这是可行的:

        $excluded = ep_get_excluded_ids();
        foreach ($excluded as $removepage){
            echo "";
            $limits .= " AND id != $removepage";
        }
        $pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' $limits ORDER BY menu_order", ARRAY_A);

现在,为了安全起见,我如何测试插件的功能是否存在?感觉我依赖 ep_get_excluded_ids();从要安装的排除插件中。

UPDATE2: - 删除 - (我在这个问题上有一个简单的拼写错误,不用介意这个)

I want the wordpress exclude pages plugin to work with my theme. Here is where my theme queries for all the pages and displays them all in a row on a single page.

$pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' ORDER BY menu_order", ARRAY_A);

foreach ($pagepull as $single_page){
    echo $single_page['post_content']; 
    // do other stuff too
}

Do you have any ideas on how to adjust the query to work with exclude pages? There isn't a function to get all pages is there? I know there is wp_list_pages() to get the list of pages but i'm not trying to display a nav here.

Would it be a better idea to do 2 queries, 1 where you get the list of pages, and then 2 query for that list? Not entirely sure how to do that, but an extra query sounds like a bad idea. Thoughts?

UPDATE:
from the answer below I have found this to work:

        $excluded = ep_get_excluded_ids();
        foreach ($excluded as $removepage){
            echo "";
            $limits .= " AND id != $removepage";
        }
        $pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' $limits ORDER BY menu_order", ARRAY_A);

Now, for safety sake, how do I test to see if a plugin's function exists? Sense I rely on ep_get_excluded_ids(); from the Exclude Plugin to be installed.

UPDATE2: - removed - (i had a simple misspelling in this problem, never mind this)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北座城市 2024-10-22 14:56:36

如果您尝试返回除指定页面之外的所有页面(并且您不希望使用 wp_list_pages() 的格式),您可以这样做:

$excArr = array(5,7,10);

foreach($excArr as $p)
    $limits .= " AND id != $p";

$pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' $limits ORDER BY menu_order", ARRAY_A);

另一种选择是使用 wp_list_pages() 并设置

    • 元素的样式,使它们看起来不像列表。
  • If you are trying to return all but specified pages (and you don't want the formatting of wp_list_pages()), you could do:

    $excArr = array(5,7,10);
    
    foreach($excArr as $p)
        $limits .= " AND id != $p";
    
    $pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' $limits ORDER BY menu_order", ARRAY_A);
    

    Another option would be to use wp_list_pages() and style the <li> and <ul> elements so they don't look like a list.

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文