Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在此代码中添加仅更改给定类别的功能?_Php_Wordpress - Fatal编程技术网

Php 在此代码中添加仅更改给定类别的功能?

Php 在此代码中添加仅更改给定类别的功能?,php,wordpress,Php,Wordpress,我最近为我的Wordpress网站创建了这段代码。它使得未注册的用户在15天内无法看到最新的帖子,除非他们注册。它可以工作,但我需要它在我的Wordpress安装中只限制一个特定类别,而不是所有类别,即我需要它限制这个类别,但不是我的博客文章 有人能告诉我在哪里,需要什么来让代码以这种方式运行吗?谢谢 add_filter('posts_where', '_custom_s2member_archive_filter'); function _custom_s2member_archiv

我最近为我的Wordpress网站创建了这段代码。它使得未注册的用户在15天内无法看到最新的帖子,除非他们注册。它可以工作,但我需要它在我的Wordpress安装中只限制一个特定类别,而不是所有类别,即我需要它限制这个类别,但不是我的博客文章

有人能告诉我在哪里,需要什么来让代码以这种方式运行吗?谢谢

    add_filter('posts_where', '_custom_s2member_archive_filter');
function _custom_s2member_archive_filter($where) /* Require membership to view latest content. */
    {
        if(!is_admin() && (is_archive() || is_home()) && !current_user_can("access_s2member_level1"))
            {
                $where .= " AND post_date <= '".date ("Y-m-d", strtotime ("-15 days"))."'"; /* Back-date freeloaders. */
            }
        return $where;
    }
add_filter('template_redirect', '_custom_s2member_single_filter');
function _custom_s2member_single_filter() /* Require membership to view latest content. */
    {
        global $post; /* Need this for date comparison. */
        if(!is_admin() && is_single() && !current_user_can("access_s2member_level1"))
            {
                if(strtotime($post->post_date) > strtotime("-15 days"))
                    {
                        header("Location: ".S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
                        exit();
                    }
            }
    }

首先要弄清楚问题类别的ID是什么。你可以通过进入管理员侧栏中的Posts->Categories,然后点击你试图限制的类别来实现。您要访问的新页面的URL将以tag_ID=[some number]结尾。该[some number]是类别ID

然后使用Wordpress编写一个if语句,如 ifis_类别“[某些数字]” { 把你已经有的限制帖子的代码放在这里 }


当然,我自己没有测试过这个,但是让我知道它是如何工作的

为您编写代码的人不会更改它吗所以你想限制一个类别,但不限制其他帖子?做到这一点最简单的方法是在查询后进行过滤,但这会使奇怪的归档文件每页的帖子数量并不总是相同的。如果他们看到这里有帖子可以吗,但是你只有在档案馆注册后才能看到它?再加一点背景:这都是通过一个名为Comicpress Comicpress.org的主题运行的。基本上,我希望漫画类被过滤,但不是博客文章。我希望这能让事情变得更清楚一点@songdogtech我似乎很难激励编写代码的人来修复这一部分,因为我已经愚蠢地向他们支付了费用。现在的设置方式是,如果该人试图在他们的可观看漫画窗口外单击指向其中一本漫画的链接,插件会自动将其转发到注册页面。