WordPress 排除页面插件 hack
我希望 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您尝试返回除指定页面之外的所有页面(并且您不希望使用
wp_list_pages()
的格式),您可以这样做:另一种选择是使用
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:Another option would be to use
wp_list_pages()
and style the<li>
and<ul>
elements so they don't look like a list.