doutao5419 2015-01-31 14:22
浏览 22

自定义PHP / WordPress Feed

I'm trying to configure a custom feed for Wordpress so it hooks in to my iPhone app. However, I've got so far but I'm becoming more stuck now. The code below gets the latest posts from WordPress and formats them the way I need. However, were I'm getting stuck at the moment is I'm trying to now:

  1. Excluding a category from the feed below (e.g. excluding category ID 5).
  2. Include another category to be 'sticky' (i.e category id 4), so even if it isn't in the latest 20 posts, it will still show in the feed.

    echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
    
    <root>
    <items>
    <language><?php bloginfo_rss( 'language' ); ?></language>
        <?php while( have_posts()) : the_post(); ?>
        <item>
            <title><?php the_title_rss(); ?></title>
            <category><?php 
                foreach((get_the_category()) as $category) { 
                        echo $category->cat_name . ' '; 
                    } 
    
            ?></category>
            <pubDate><?php echo mysql2date('d M Y', get_post_time('Y-m-d', true), true); ?></pubDate>
            <?php $allcontent = get_the_content_feed('rss2'); ?>
            <description>
                <![CDATA[
                <?php echo $allcontent; ?>
                ]]>
            </description>
            <link><?php the_permalink_rss() ?></link>
            <image>
                <?php if (has_post_thumbnail() ):
                $attachmentimage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
                echo $attachmentimage[0]; ?>
                <?php endif; ?>
            </image>
    
    <?php rss_enclosure(); ?>
        <?php do_action('rss2_item'); ?>
        </item>
        <?php endwhile; ?>
        </items>
    </root>
    
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法