【问题标题】:Add Wordpress Pages to their own RSS feed and not main RSS feed using Plugin使用插件将 Wordpress 页面添加到他们自己的 RSS 提要,而不是主 RSS 提要
【发布时间】:2018-11-14 01:05:36
【问题描述】:

我正在学习编写 Wordpress 插件,并找到了一些将 Wordpress 页面添加到 RSS 提要的代码。

我在我的 Wordpress 插件中使用了以下代码,效果很好! https://www.thewebtaylor.com/articles/wordpress-add-pages-rss-feed

我试图弄清楚如何将 Wordpress 页面发送到他们自己的单独提要,而不是将其包含在 Wordpress 默认 RSS 中。

【问题讨论】:

    标签: wordpress plugins rss


    【解决方案1】:

    `我找到了解决方案。

    add_action( 'pre_get_posts', 't5_pages_in_feed' );
    
    /**
     * Set post type to 'page' if it was requested.
     *
     * @param  object $query
     * @return void
     */
    function t5_pages_in_feed( &$query )
    {
        if ( isset ( $_GET['post_type'] ) && $_GET['post_type'] === 'page' && is_feed() )
        {
            $query->set( 'post_type', 'page' );
        }
    }`
    

    现在您在 /feed/?post_type=page 处获得页面提要。

    https://wordpress.stackexchange.com/questions/52853/how-to-get-a-feed-for-post-type-page

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-25
      • 2016-06-08
      • 1970-01-01
      • 2020-02-05
      • 1970-01-01
      • 2014-02-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多