Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
general-topic
Possible to edit RSS feed URL or the feed itself to show posts from certain time period?
Avatar
Beth Terry
Member
sp_UserOfflineSmall Offline
Dec 10, 2013 - 12:58 am

Hi.  The URL for my forum feed for all posts is:

http://myplasticfreelife.com/f.....81d9ab816/

I would like to add this feed to a weekly newsletter template, and I'm wondering if there is a way to either add parameters to the URL to specify only posts written within the last 7 days (regardless of how many there are) or if there is a way to create a new feed that would only contain posts from the last 7 days.  I figured out how to do it with my Wordpress feed.  Is there a way to do it in Simple Press?

Thanks,

Beth Terry

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Dec 10, 2013 - 3:52 am

If you know how to use standard WordPress style filters then yes - there is one defined for the WHERE clause of the query for the Simple:Press feed. This takes this form:

$where = apply_filters('sph_rss_where', $where, $feed);

The passed $where variable contains the WHERE clause that will be used by the query and the $feed variable contains the feed type (such as 'group', 'forum' or 'all' etc).

You can massage the $where content to add a post_date clause

andy-signature.png
YELLOW
SWORDFISH
Avatar
Beth Terry
Member
sp_UserOfflineSmall Offline
Dec 11, 2013 - 7:06 pm

Actually, I'm not a programmer.  I'm good at finding the code solutions I need by Googling and searching help forums and then copying and pasting.  So I need more help than a line of code because I don't know what to do with it.

How about if I tell you what I did in Wordpress, and you can tell me how I would do something similar in SimplePress -- not just the code but where to put it or what file to create and where.

To create my custom Wordpress feed showing only posts for the past 7 days, I created a new template called rss-last7days.php and put it in my theme folder.   Then, right after :

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

I added:

<?php $mylimit=7 * 86400; //days * seconds per day
 $post_age = date('U') - get_post_time('U');
 if ($post_age < $mylimit) { ?>

This was code that I found in a Wordpress forum.  I am good at copying and pasting and sort of understanding what it is that the php is doing.  But I'm not a programmer.

So, to use the code that you have provided above, do I need to create a new template?  If so, where do I put it?  Do I need to edit sp-feed.php?  If so, won't my changes get overwritten by updates?  What other steps do I need to take?

Thanks,

Beth

 

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Dec 12, 2013 - 7:12 am

I think this should do it:

$where = apply_filters('sph_rss_where', $where, $feed);

add_filter('sph_rss_where', 'feed_filter', 1, 2);
function feed_filter($w, $f) {
    $w .= ' AND ' . SFPOSTS .'.post_date > DATE_SUB(CURDATE(), INTERVAL 7 DAY) ';
    return $w;
}

You want to put that in either spFunctions.php file of the Simple:Press theme you are using (in the /templates folder of the theme) - or - in the functions.php file of your WordPress theme.

If you choose the Sp theme route then remember - as always we recommend that you create your own SP theme so that any customisation is not lost during a future update. (http://codex.simple-press.com/.....g-a-theme/)

Anyway - try this and see if this works for you.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Beth Terry
Member
sp_UserOfflineSmall Offline
Dec 13, 2013 - 4:44 pm

It works!  I added it to functions.php.  Thank you!!!  

Any time I want to change the number of days, I can just change "INTERVAL # DAY"

Beth

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Dec 13, 2013 - 5:17 pm

np. glad we could help.

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 649
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 618
Members: 17356
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10122
Posts: 79610