• WPChina

    (@wordpresschina)


    I need to create additional RSS feeds, besides the ones native to WordPress. And I need to have both working at the same time.

    Here is what I want to do: I currently use the WP RSS feeds and I have them only using excerpts of my posts.

    However I also want to create another URL for a feed that will display the entire posts within the feed and only display the posts from the last day. Is there a way to create a “rss template” so that, for example I could create another feed at mydomain.com/myotherrssfeed/ ?

Viewing 15 replies - 1 through 15 (of 19 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Sure. Use a Page with a custom Page Template. Code your Page Template as the feed and there you go.

    http://codex.wordpress.org/Pages#Page_Templates

    http://www.scratch99.com/wordpress-plugin-dualfeeds/

    No idea if it provides a way to limit items in a feed in the way you ask for.

    Thread Starter WPChina

    (@wordpresschina)

    Hmmm… interesting. Ok I looked at both pages and will implement in the next few hours and let you know how it goes. Thanks for the feedback!

    Thats the good idea but how can you do that if you have done with that please let me know

    Thread Starter WPChina

    (@wordpresschina)

    Ok I am not getting good results with Otto42’s suggestion. πŸ™

    Tell me what I’m doing wrong. I created a page template with the following inside:

    ‘<?php
    /*
    Template Name: Full RSS Feed
    */
    ?>

    <?php
    if (empty($wp)) {
    require_once(‘wp-config.php’);
    wp(‘feed=rss2’);
    }
    require (ABSPATH . WPINC . ‘/feed-rss2.php’);
    ?>’

    But it is not displaying all the recent posts and I can’t figure out how to tweak it to do so… any ideas?

    I will investigate the plugin now.

    Thread Starter WPChina

    (@wordpresschina)

    OK Kafkaesqui’s suggestion for dual feeds is great and it’s a nice plugin, but it doesn’t fit my needs because it can’t be tweaked so much. If I could make the feed only display the last posts from the last day, then it would work fine. πŸ™

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Your template is not working because you are only copying code from elsewhere. That’s not what I thought you were trying to do.

    However I also want to create another URL for a feed that will display the entire posts within the feed and only display the posts from the last day.

    See, the template you posted certainly won’t do that. You didn’t specify any posts. Pages don’t get Posts for free, you have to query them. Also, you included a bunch of other stuff like including wp-config and a call to wp().. Those make no sense in a Page Template.

    So, try something like this instead:

    <?php
    /*
    Template Name: Full RSS Feed
    */
    
    // get the current date
    $current_day = date('j');
    $current_month = date('m');
    $current_year = date('Y');
    
    // set the query to today's posts only
    query_posts("day=$current_day&year=$current_year&monthnum=$current_month"); 
    
    // produce a feed from that query
    require (ABSPATH . WPINC . '/feed-rss2.php');
    ?>

    Then you just need to make a Page using that template. Content of the page doesn’t matter, just make sure that the page slug is correct for what you want the URL to be. Like “myotherrssfeed” or whatever.

    Obviously if you want to change the way that it works, then you can change the parameters to query_posts and get different posts instead.

    Otto’s idea is an excellent one, just keep in mind it will not alter the content displayed (i.e. summary or full text) in the feed.

    Thread Starter WPChina

    (@wordpresschina)

    Yes, Otto’s suggestion is great. Works!

    And Kafkaesqui, you are right that the content is not altered and still shows excerpts. I think my next step then will to clone “feed-rss2.php” and make “feed-rss2-full.php” and tweak things in there to spill out all contents. Not sure yet how to do that, but there should be ways on other threads.

    Thank you!

    WordPressChina,
    Wouldn’t it be better to amend the code inside query_posts() to get the full post instead of just the excerpt, I’m sure there is a way

    Have a look at this page http://codex.wordpress.org/Template_Tags/query_posts

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    I think my next step then will to clone “feed-rss2.php” and make “feed-rss2-full.php” and tweak things in there to spill out all contents. Not sure yet how to do that, but there should be ways on other threads.

    In your copy, you’ll find this code:

    <?php if (get_option('rss_use_excerpt')) : ?>
    		<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
    <?php else : ?>

    Remove that (and the “endif” after the content:encoded bits). Problem solved.

    @roganty: the query doesn’t control what part of the post is displayed, the Loop does that. The query always gets the full post *and* the excerpt.

    Thread Starter WPChina

    (@wordpresschina)

    Sorry for the delay–I had to wait until posts were added to test it working to only show “today’s” posts. It works a little bit, but not entirely.

    What works:
    1) It does display the entire post. Great!
    2) It does display today’s posts, but only according to the SERVER time, and not the WordPress time… Not Great. πŸ™

    My server is 15 hours different from me (I am 15 hours ahead). What should I add and where to make the code show my time (i.e. WordPress time) instead of the server time?

    Tks!

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    No, you’re mistaken. The selection mechanism selects posts according to the date/time on the post itself. What the server time is makes no difference.

    However, the FEED will show the post times in GMT/UTC. Why? Because feeds always show their times in GMT/UTC. It’s up to the feed reader to convert to the users local time, as needed.

    But what’s important to remember is that these two times are the same time. For any given moment, there can be multiple representations. The representation being used in the feed is the GMT/UTC one.

    Actually Otto, your vars do collect the day from the server first before querying for it, so it is dependent on the server time.

    WPC, here’s a mod of Otto’s code that provides one way to do what you ask:

    // get the current date + 15 hours
    $today = date('U')+54000; // date (Unix) + 15 hours
    $today = getdate($today);
    $current_day = zeroise($today['mday'],2);
    $current_month = zeroise($today['mon'],2);
    $current_year = $today['year'];

    Finally, if you just want to make sure the latest day of posts is queried for, so that *something* is always displayed:

    http://wordpress.org/support/topic/98090#post-488635

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Oh, my bad, I see what you’re getting at now. Sorry, I was confused by thinking of the query itself when I should have been thinking of the results of the date function. πŸ™‚

    Here’s a slightly better way to deal with that:

    // get the current date
    $now = current_time('timestamp',0);
    $current_day = date('j', $now);
    $current_month = date('m', $now);
    $current_year = date('Y', $now);

    This will use the same method that WordPress uses to adjust the timestamp value. The date will be adjusted by the same offset that the blog is set to use.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Need a way to create additonal RSS feeds, besides the ones native to WordPress’ is closed to new replies.