Created
November 4, 2014 22:46
-
-
Save bhubbard/cd0eb9ac5e4d8603d4c8 to your computer and use it in GitHub Desktop.
Display a Inman news feed on a genesis page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * Template Name: Real Estate News | |
| * Description: Display Inman News articles on your site. | |
| */ | |
| remove_action( 'genesis_loop', 'genesis_do_loop' ); | |
| add_action( 'genesis_loop', 'inmanfeed_do_custom_loop' ); | |
| function inmanfeed_do_custom_loop() { | |
| // Get RSS Feed(s) | |
| include_once( ABSPATH . WPINC . '/feed.php' ); | |
| // Get a SimplePie feed object from the specified feed source. | |
| $rss = fetch_feed( 'http://feeds.feedburner.com/inmannews' ); | |
| if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly | |
| // Figure out how many total items there are, but limit it to 5. | |
| $maxitems = $rss->get_item_quantity( 10 ); | |
| // Build an array of all the items, starting with element 0 (first element). | |
| $rss_items = $rss->get_items( 0, $maxitems ); | |
| endif; | |
| ?> | |
| <h1><?php the_title(); ?></h1> | |
| <?php the_content(); ?> | |
| <ul> | |
| <?php if ( $maxitems == 0 ) : ?> | |
| <li><?php _e( 'No items' ); ?></li> | |
| <?php else : ?> | |
| <?php // Loop through each feed item and display each item as a hyperlink. ?> | |
| <?php foreach ( $rss_items as $item ) : ?> | |
| <li> | |
| <a href="<?php echo esc_url( $item->get_permalink() ); ?>" | |
| title="<?php printf( __( 'Posted %s' ), $item->get_date('j F Y | g:i a') ); ?>"> | |
| <?php echo esc_html( $item->get_title() ); ?> | |
| </a> | |
| </li> | |
| <?php endforeach; ?> | |
| <?php endif; ?> | |
| </ul> | |
| <?php } | |
| genesis(); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment