添加过滤器Wordpress(短代码在rss中不起作用)

时间:2016-06-14 09:29:52

标签: wordpress wordpress-plugin rss shortcode add-filter

我已使用BxSlider将自定义插件替换为默认的Wordpress库。

该插件正在前端工作。

<?php
/*
Plugin Name: Weemsel Gallerij
Plugin URI: https://www.hetweemsel.nl
Description: Weemsel Gallerij met Facebook instant articles support
Version: 1.0
Author: Het Weemsel
Author URI: https://www.hetweemsel.nl
*/

remove_shortcode('gallery');
add_shortcode('gallery', 'parse_gallery_shortcode');

wp_register_style('bxslider-css', plugins_url() . '/weemsel-gallerij/assets/css/jquery.bxslider.css', false, null);
wp_enqueue_style('bxslider-css');

wp_register_script('bxslider-js', plugins_url() . '/weemsel-gallerij/assets/js/jquery.bxslider.min.js', false, null, true);
wp_enqueue_script('bxslider-js');

wp_register_script('setup-js', plugins_url() . '/weemsel-gallerij/assets/js/bxsetup.js', false, null, true);
wp_enqueue_script('setup-js');  

function parse_gallery_shortcode($args) {

    global $post;

    if ( ! empty( $atts['ids'] ) ) {
        // 'ids' is explicitly ordered, unless you specify otherwise.
        if ( empty( $atts['orderby'] ) )
            $atts['orderby'] = 'post__in';
        $atts['include'] = $atts['ids'];
    }

    extract(shortcode_atts(array(
        'orderby' => 'menu_order ASC, ID ASC',
        'include' => '',
        'id' => $post->ID,
        'itemtag' => 'dl',
        'icontag' => 'dt',
        'captiontag' => 'dd',
        'columns' => 3,
        'size' => 'full',
        'link' => 'file'
    ), $atts));


    $args = array(
        'post_type' => 'attachment',
        'post_status' => 'inherit',
        'post_mime_type' => 'image',
        'orderby' => $orderby
    );

    if ( !empty($include) )
        $args['include'] = $include;
    else {
        $args['post_parent'] = $id;
        $args['numberposts'] = -1;
    }

    $images = get_posts($args);
    ?>
    <?php
    ob_start();

        echo '<ul class="bxslider">';
            foreach ( $images as $image ) { 
                    echo '<li><figure><img src="';
                    echo wp_get_attachment_url($image->ID, $size);
                    echo '" /></figure></li>';
                }
        echo '</ul>';




        echo '<div id="bx-pager">';

            $i = 0;

            foreach ( $images as $image ) { 
                    echo '<a data-slide-index="';
                    echo $i++;
                    echo $item[number];
                    echo '" href=""><figure><img src="';
                        echo wp_get_attachment_image_url($image->ID, $size);
                    echo '" /></figure></a>';           
            }
        echo '</div>';


    $content = ob_get_contents();
    ob_end_clean(); 

    return $content;

}

add_filter('the_excerpt','do_shortcode', 10, 100);
add_filter('the_content','do_shortcode', 10, 100);
add_filter('the_excerpt_rss','do_shortcode', 10, 100);
add_filter('the_content_rss','do_shortcode', 10, 100);
?> 

不知何故,当使用add_filter函数时,RSS的结果真的很奇怪,不输出HTML或正确的链接。 RSS提要是自定义提要

<?php
/**
 * Template Name: Zakelijke feed
 */
$postCount = 5; // The number of posts to show in the feed
$posts = query_posts('showposts=' . $postCount .'&cat=52');
header('Content-Type: '.feed_content_type('rss-http').'; charset='.get_option('blog_charset'), true);
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
?>
<rss version="2.0"
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        xmlns:wfw="http://wellformedweb.org/CommentAPI/"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:atom="http://www.w3.org/2005/Atom"
        xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
        xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
        <?php do_action('rss2_ns'); ?>>
<channel>
        <title><?php bloginfo_rss('name'); ?> - Feed</title>
        <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
        <link><?php bloginfo_rss('url') ?></link>
        <description><?php bloginfo_rss('description') ?></description>
        <lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
        <sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
        <sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
        <?php do_action('rss2_head'); ?>
        <?php while(have_posts()) : the_post(); ?>
                <item>
                        <title><?php the_title_rss(); ?></title>
                        <link><?php the_permalink_rss(); ?></link>
                        <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
                        <dc:creator><?php the_author(); ?></dc:creator>
                        <guid isPermaLink="false"><?php the_guid(); ?></guid>
                        <description xml:space="preserve"><![CDATA[ <?php the_post_thumbnail( 'medium' );  ?> ]]><![CDATA[ <?php the_excerpt(); ?> ]]></description>
                        <content:encoded xml:space="preserve"><![CDATA[ <?php the_post_thumbnail(); ?> ]]><![CDATA[ <?php the_content_rss() ?> ]]></content:encoded>
                        <?php rss_enclosure(); ?>
                        <?php do_action('rss2_item'); ?>
                </item>
        <?php endwhile; ?>
</channel>
</rss>

我得到的输出真的很奇怪,可以在以下网址看到: https://woerden.tv/zakelijk/feed/zakelijk

https://woerden.tv"><figure><img src= [3] https://woerden.tv"><figure><img src= [4] https://woerden.tv"><figure><img src= [5] https://woerden.tv"><figure><img src= [6] https://woerden.tv"><figure><img src=
谁能告诉我出了什么问题?

最诚挚的问候, 迪伦

1 个答案:

答案 0 :(得分:0)

RSS代码指的是已弃用的函数the_content_rss()

<content:encoded xml:space="preserve"><![CDATA[ <?php the_post_thumbnail(); ?> ]]><![CDATA[ <?php the_content_rss() ?> ]]></content:encoded>

根据https://codex.wordpress.org/Template_Tags/the_content_rss,您需要将其更新为the_content_feed() https://codex.wordpress.org/Template_Tags/the_content_feed