Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.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 如何覆盖自定义源的WP Admin Syndication源限制?_Php_Wordpress_Feed_Syndication - Fatal编程技术网

Php 如何覆盖自定义源的WP Admin Syndication源限制?

Php 如何覆盖自定义源的WP Admin Syndication源限制?,php,wordpress,feed,syndication,Php,Wordpress,Feed,Syndication,我需要在WP Admin中覆盖General->Admin下辛迪加设置中最近发布的数量的设置 我正在使用下面的代码,它可以获取所有帖子,但我不需要那么多。有人能给我一个例子,如何检索50个职位?这应该只影响这一个提要,而不是所有其他提要 function no_limits_for_feed( $limits ) { return ''; } add_filter( 'post_limits', 'no_limits_for_feed' ); 更新:下面是我正在使用的代码示例,它来自

我需要在WP Admin中覆盖General->Admin下辛迪加设置中最近发布的数量的设置

我正在使用下面的代码,它可以获取所有帖子,但我不需要那么多。有人能给我一个例子,如何检索50个职位?这应该只影响这一个提要,而不是所有其他提要

function no_limits_for_feed( $limits ) {
    return '';
}

add_filter( 'post_limits', 'no_limits_for_feed' );
更新:下面是我正在使用的代码示例,它来自WordPress插件:

class feed_json {
    function feed_json() {
        global $wp_rewrite;

        add_action('init', array(&$this, 'add_feed_json'));
        add_action('do_feed_json', array(&$this, 'do_feed_json'), 10, 1);
        add_filter('template_include', array(&$this, 'template_json'));
        add_filter('query_vars', array(&$this, 'add_query_vars'));

        $plugin_basename = plugin_basename(__FILE__);
        add_action('activate_' . $plugin_basename, array(&$this, 'add_feed_json_once'));
        add_action('deactivate_' . $plugin_basename, array(&$this, 'remove_feed_json'));
    }

    function add_feed_json_once() {
        global $wp_rewrite;
        $this->add_feed_json();
        $wp_rewrite->flush_rules();
    }

    function remove_feed_json() {
        global $wp_rewrite;
        $feeds = array();
        foreach ( $wp_rewrite->feeds as $feed ) {
            if ( $feed !== 'json' ) {
                $feeds[] = $feed;
            }
        }
        $wp_rewrite->feeds = $feeds;
        $wp_rewrite->flush_rules();
    }

    function add_query_vars($qvars) {
      $qvars[] = 'callback';
      $qvars[] = 'limit';
      return $qvars;
    }

    function add_feed_json() {
        add_feed('json', array(&$this, 'do_feed_json'));
    }

    function do_feed_json() {
        load_template($this->template_json(dirname(__FILE__) . '/feed-json-template.php'));
    }

    function template_json( $template ) {
        $template_file = false;
        if (get_query_var('feed') === 'json') {
            $template_file = '/feed-json.php';
            if (function_exists('get_stylesheet_directory') && file_exists(get_stylesheet_directory() . $template_file)) {
                $template_file = get_stylesheet_directory() . $template_file;
            } elseif (function_exists('get_template_directory') && file_exists(get_template_directory() . $template_file)) {
                $template_file = get_template_directory() . $template_file;
            } elseif (file_exists(dirname(__FILE__) . '/feed-json-template.php')) {
                $template_file = dirname(__FILE__) . '/feed-json-template.php';
            } else {
                $template_file = false;
            }
        }

        return (
            $template_file !== false
            ? $template_file
            : $template
            );
    }
}
new feed_json();

我想你可以连接到,但是如果它是一个提要,
posts\u per\u page
值稍后会被覆盖。因此,只需连接到
post_limits
,检查您的提要,并在需要时返回不同的
LIMIT
部分

add_filter( 'post_limits', 'so6230475_post_limits', 10, 2 );
function so6230475_post_limits( $limits, &$wp_query )
{
    if ( $wp_query->is_feed( 'json' ) ) {
        $limits = 'LIMIT 50';
    }
    return $limits;
}

你能告诉我如何为你的特殊提要设置“/*检查*/”标志吗?@Zoolander:这取决于你是如何创建提要的。你能用你是如何做到这一点的信息和代码更新你的问题吗?@Jan Fabry:我已经用代码更新了我的原始帖子,还包括了我正在使用的插件的链接。谢谢@Zoolander:如果你要添加一个额外的feed类型,你可以只写
If($wp\u query->is\u feed('json'))
,如果它是一个feed并且来自类型
json
@Jan Fabry,这将是正确的。法布里:我把它添加到If语句中,但是它仍然只返回5个feed结果。我在WP Admin中将“Syndication feeds show the most recent”设置为5,并将functions.php中的posts_per_页面设置为100。有什么想法吗?