Wordpress 未来页面问题(未显示) [英] Wordpress Future Page Issue (Not Showing)

查看:26
本文介绍了Wordpress 未来页面问题(未显示)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人要求我解决一个 wordpress 网站上的问题.问题是由应该使用帖子而不是页面的事实引起的.然而,该网站已启动并正在运行,最快的选择是使用各种 hack 来解决问题.

I've been asked to fix a problem on a wordpress site. The problem is caused by the fact posts should of been used instead of pages. However the site is up and running and quickest option would be to fix the problem using a hack of sorts.

该站点有一个事件部分,每个事件都是一个页面(这是问题,实际上应该是一个帖子).为了显示即将发生和过去的事件,使用发布日期,因此即将发生的事件的发布状态为未来".

The site has an events section, each event is a page (this is the issue, should really be a post). In order to have upcoming and past events the post date is used, therefore upcoming events has a post status of 'future'.

有一些事件列表页面,通过使用正确的 query_post() 可以很好地显示它们.虽然当您点击进入实际事件(这是一个未来的页面)时会出现问题.如果您以管理员身份登录,则会显示该页面,但如果您未登录,则会显示 404 页面.

There's are list page of events which shows them fine by using the correct query_post(). Although the problem arises when you click through to actual event (which is a future page). If your logged in as an Admin then the page shows but if your not logged in you get a 404 page.

现在,如果他们发布了未来就是现在!"插件可以解决这个问题.我有一种感觉,解决这个问题的唯一方法是重写部分核心 Wordpress 文件.

Now if they where posts then the "The Future is Now!" plugin would solve this problem. I have a feeling the only way round the problem is to rewrite part of core Wordpress files.

任何建议都会很棒,我在 Wordpress 方面有很多经验,所以即使您能指出我正确的方向.

Any advice would be great, I have a lot of experience with Wordpress so even if you can point me in the right direction.

干杯,杰森

[更新]

感谢 maiorano84 的详细回复.从长远来看,我打算将它们移到帖子中,但同时他们要求我们尽快修复它而不更改任何网址(今天他们发送了一封包含事件列表的群发电子邮件,而没有检查任何链接)

Thanks maiorano84 for your detailed response. In the long run I intend to move them to posts but in the meantime they've requested we fix it asap without changing any urls (today they sent out a mass email with a list of events without checking any links)

您的包含 post_status future 的解决方案在这种情况下不起作用,因为 wordpress 没有进入加载模板的阶段.wordpress 核心中的某些东西阻止了它走那么远.理想情况下,如果它们是一个钩子,我可以用来同时覆盖此行为,那将非常好,但如果涉及到它,我将暂时编辑核心文件.

Your solution of including post_status future doesn't work in this case as wordpress doesn't get to the stage of loading the template. Something in wordpress core stops it from getting that far. Ideally if they was a hook I could use to override this behavior in the meantime that would be excellent but if it comes to it I will temporarily edit the core files.

[更新 2]

我现在知道需要编辑或使用与它们相关的钩子的两个函数.

I now know the two functions that need editing or use a hook that relates to them.

首先我们 is_404() 需要更改为不将以后的页面添加为 404

First of we is_404() which needs changed to not add future pages as 404

第二,如果页面是未来,我们需要 is_page() 需要返回 true

Second we have is_page() need to return true if a page is future

[更新 3]

我已经在核心中找到了如何做到这一点.如果您转到 wp-includes/query.php 第 2682 行.复制它而不是旧函数,它可以正常工作.如果您有更好的方法,请告诉我.谢谢.

I've found how to do this in the core. If you go to wp-includes/query.php line 2682. Copy this in instead of the old function it works correct. If you have a better way please let me know. Thanks.

        /** Future Pages **/
    // Check post status to determine if post should be displayed.
    if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
        $status = get_post_status($this->posts[0]);
        $post_status_obj = get_post_status_object($status);;
        if ( !$post_status_obj->public ) {
                if  ( $post_status_obj->protected ) {
                        $this->is_preview = true;
                        print_r($status);
                        if ( 'draft' != $status ) {
                            $this->posts[0]->post_date = current_time('mysql');
                            } else {
                            $this->posts = array();
                        }
                } elseif ( $post_status_obj->private ) {
                    if ( ! current_user_can($read_cap, $this->posts[0]->ID) )
                        $this->posts = array();
                } else {
                    $this->posts = array();
                }
        }
        /** END **/

推荐答案

您实际上可以在页面查询中添加 post_status 参数 'future'.你真的不应该为了做你想做的事而修改你的核心文件.因此,在您的 page.php 和 archive.php 模板(或其他控制事件显示的相关模板)上,您可以执行以下操作:

You can actually add a post_status parameter of 'future' to your page queries. You REALLY shouldn't be modifying your core files in order to do what you want. So on your page.php and archive.php templates (or other relevant templates that's controlling your Event display), you can do something like this:

<?php
$params = array('posts_per_page'=>-1, 'post_status'=>'publish,future');
$query = new WP_Query($params);
if($query->have_posts()) : while($query->have_posts()) : $query->the_post();
?>
<!-- YOUR PAGE HTML HERE -->
<?php
endwhile;endif;
wp_reset_postdata();
?>

这过于简单化了,但在相应文件中使用正确的查询将使您能够以自己喜欢的方式显示页面.

This is an oversimplification, but using the correct queries in the corresponding files will allow you to display your pages however you like.

此处的更多信息:http://codex.wordpress.org/Class_Reference/WP_Query

另一件值得考虑的事情,我意识到这不是您问题的一部分,但很可能会解决您的问题:

Another thing worth considering, and I realize that this wasn't a part of your question, but may very well solve your issue:

为什么不在您客户端的服务器上创建一个子域,您可以在不中断用户体验的情况下修复所有问题?您可以轻松地将现有数据库导入您的开发环境,并在不影响实时版本的情况下进行所需的所有更改.

Why not create a subdomain on your client's server where you can work on fixing everything without interrupting the user experience? You can easily either import the existing database into your development environment, and make all the changes you need without affecting the live version.

值得深思.我的建议是将其扼杀在萌芽状态,并尽快将页面转换为帖子,否则网站很快就会变得一团糟,但这是你的决定.

Food for thought. My advice would be to nip this in the bud, and convert the pages over to posts as soon as possible, otherwise the website will turn into a giant mess very quickly, but that's your call.

希望这会有所帮助.

更新:

我仍然建议不要更改核心文件,但如果在一切都得到修复之前这是最后的手段,那么就去做吧.这是我认为可能有帮助的WP Friendly"解决方案:

I would still advise against altering the core files, but if it's a last resort until everything gets fixed, then have at it. Here's is a "WP Friendly" solution I think might help:

add_action('wp','future_redirect', 0);
function future_redirect($WP_Object)
{
    $page = is_page() ? get_page(get_the_ID()) : false;
    if($page && $page->post_status == 'future')
    {
        wp_redirect(/*YOUR REDIRECT URL*/);
        exit();
    }
    return $WP_Object;
}

这篇关于Wordpress 未来页面问题(未显示)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆