Created
October 4, 2016 09:40
-
-
Save h1dd3nsn1p3r/05337dbfbaf02f040967071f44a0072f to your computer and use it in GitHub Desktop.
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 | |
| $rss = fetch_feed('Your_Website_Rss_Url_Here'); // eg http://anujsubedi.com.np/blog/feed | |
| if (!is_wp_error( $rss ) ) : | |
| $maxitems = $rss->get_item_quantity(4); // increase items quantity eg. 6 | |
| $rss_items = $rss->get_items(0, $maxitems); | |
| endif; | |
| ?> | |
| <?php | |
| function shorten($string, $length) | |
| { | |
| $suffix = '…'; | |
| $short_desc = trim(str_replace(array("/r", "/n", "/t"), ' ', strip_tags($string))); | |
| $desc = trim(substr($short_desc, 0, $length)); | |
| $lastchar = substr($desc, -1, 1); | |
| if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix=''; | |
| $desc .= $suffix; | |
| return $desc; | |
| } | |
| ?> | |
| <div class="blog_rolls_items_wrapper"> | |
| <div class="row"> | |
| <?php | |
| if ($maxitems == 0) echo '<li>No items.</li>'; | |
| else | |
| foreach ( $rss_items as $item ) : | |
| ?> | |
| <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"> | |
| <div class="blog_items"> | |
| <h3 class="your_class"> | |
| <a target="_blank" href='<?php echo esc_url( $item->get_permalink() ); ?>' title='<?php echo esc_html( $item->get_title() ); ?>'> <?php echo esc_html( $item->get_title() ); ?></a> | |
| </h3> | |
| <p> | |
| <?php echo shorten($item-> get_description(),'215'); // you may change the length of desc ?> | |
| </p> | |
| <a href="<?php echo esc_url( $item->get_permalink() ); ?>" target="_blank">Read More</a> | |
| </div> | |
| </div> | |
| <?php endforeach; ?> | |
| </div> | |
| </div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment