Connect with us
Lido Finance: Redefining the staking experience. Immerse yourself in the world of liquid staking and secure crypto trading with Lido Finance, ensuring your assets are optimized for growth.

Tips & Tricks

Turn your RSS feed into a shortcode

Published

on

Last week I wrote how to “Use WordPress to print a RSS feed for Eventbrite attendees“. It was pretty popular, but then I found myself in a place that was more annoying. Trying to incorporate that into a blog post or page.

Without having to download a plugin that will allow PHP to be executed inside a post, I would have to create a template file and use that. Which is what I did, and it works just fine. But for some reason I forgot all about shortcodes! With a shortcode, I could generate all the PHP in the functions file and then just call the shortcode when/where I want.

Okay, so lets show the completed PHP code:

function attendee_feed_print_2009() {
 global $wpdb;
 include_once( ABSPATH . WPINC . '/rss.php' );
 $rss = fetch_rss( 'http://www.eventbrite.com/rss/event_list_attendees/384870157' );
 $items = array_slice( $rss->items, 0 );
 if ( empty( $items ) ) echo '<ul style="list-style-type: none; list-style-image: none; list-style-position: outside;"><li>No items</li></ul>';

 else

 foreach ( $items as $item ) : ?>
 <ul style="list-style-type:none; list-style-image:none; list-style-position:outside; margin-bottom: 0px">
 <li><!--<strong><?php echo $item[ 'title' ]; //User name ?></strong><br />-->

 <?php echo $item[ 'content' ][ 'encoded' ]; ?>

 <hr style="border: 1px solid #ddd; margin-bottom: 8px" />
 </li>
 </ul>
 <?php endforeach;
}

Now, this code has to be changed for it to work as a shortcode. We’ll have to return the function and not print/echo it.

I also wanted to be able to use multiple instances of the code with different feeds. To do so I had to create a argument to extract from the completed short code. I found a demo at: Alex Mansfield’s post.

Remember this:

function attendee_feed_print_2009() {
 global $wpdb;
 include_once( ABSPATH . WPINC . '/rss.php' );
 $rss = fetch_rss( 'http://www.eventbrite.com/rss/event_list_attendees/384870157' );

We are going to update it to read as follows ( changes in bold ) :

function attendee_feed_print_2009( $rss_nbr ) {
 global $wpdb;
 extract( shortcode_atts( array( 'rss' => ''), $rss_nbr ) );
 include_once( ABSPATH . WPINC . '/rss.php' );
 $rss = fetch_rss( $rss );

And the final code with the fields updated to return the arguments ( put into your functions.php file ( in between <?php ?> ) ) :

function attendee_feed_print_2009( $rss_nbr ) {
  global $wpdb;
  extract( shortcode_atts( array( 'rss' => ''), $rss_nbr ) );
  include_once( ABSPATH . WPINC . '/rss.php' );
  $rss = fetch_rss( $rss );
  $items = array_slice( $rss->items, 0 );
  
  $rss_html = '<div id="eventbrite-attendee-list" style="clear:both;">';
  
  if ( empty( $items ) ) $rss_html .= '<ul style="list-style:none;"><li>No attendees, yet.</li></ul>';

  else

  foreach ( $items as $item ) :

  $rss_html .= '<ul style="background:none; list-style:none; margin:0px">';
  $rss_html .= '<li style="background:none; list-style:none;">';
  $rss_html .= $item[ 'content' ][ 'encoded' ];
    
  $rss_html .= '<hr style="border: 1px solid #ddd; margin-bottom: 10px" />';
  $rss_html .= '</li>';
  $rss_html .= '</ul>';
  
  endforeach;

  $rss_html .= '</div>';

  return $rss_html;
  }

And lets not forget to add the shortcode function!

add_shortcode( 'eventbrite-attendees', 'attendee_feed_print_2009' );

Final outcome with look like this `[eventbrite-attendees rss="http://your-rss-feed.com/"]`

I’ve created this into a plugin!

Download the plugin: http://wordpress.org/extend/plugins/eventbrite-attendees-shortcode/

Themes

Add additional meta boxes to Hybrid Theme

Published

on

At the time of writing this post I have Theme Hybrid as my parent theme, and am using a custom version of Hybrid News that Justin Tadlock offers to the public.

Well I want to tell you how you can add additional custom meta boxes to your child theme’s running the Hybrid Theme.

In your child function.php file just add the following to create a new post meta box:

/**
* Add additional post meta boxes
*
* by WPCult
*/
function wpcult_post_meta_boxes($meta_boxes) {
	$meta_boxes['image'] = array(
		'name' => 'image',
		'default' => '',
		'title' => __('Image:'),
		'type' => 'text',
		'show_description' => false,
		'description' => __('Please use a full size image, larger than 500px (this photo will dynamically re-size itself!'),
	);
	return $meta_boxes;
}
add_filter('hybrid_post_meta_boxes', 'wpcult_post_meta_boxes');

This will create a custom meta box called Image, and will create a custom field with the id of image.

Additionally you can create this on pages as well by copy/paste and replacing “post_meta_box” with “page_meta_box” every where inside the function.

Continue Reading

Tips & Tricks

Sick of images being to large for the content area?

Published

on

Have you ever uploaded an image that might have been a tad bigger than the width of your content area? I know I have! So here is a little CSS fix to handle these situations.

Resize those large images using CSS

Resize those large images using CSS

.post img {
	max-width: 600px;
	height: auto;
	}

That’s it, really simple huh. Just make sure that you change the .post to the correct body class(which starts with a “.“) or body ID(which starts with a “#“).

Would you like a quick explanation?
The CSS is just telling any image inside the class of .post to not be more than 600px wide. By the way make sure you change it to fit the dimension of your content width. And the height attribute is set to auto to automatically change the height to match the new width. 🙂

Continue Reading

Tips & Tricks

How to: Display RSS feeds from anywhere

Published

on

Here is a simple way to display any RSS feed in your WordPress blog.

<?php include_once(ABSPATH . WPINC . '/rss.php');
	$rss = fetch_rss('http://feeds2.feedburner.com/WPCult');
	$items = array_slice($rss->items, 0, 4);

		if (empty($items)) echo '<li>No items</li>';
		else
			foreach ( $items as $item ) : ?>
            <a style="font-size: 14px;" href='<?php echo $item['link']; ?>' title='<?php echo $item['title']; ?>'><?php echo $item['title']; ?></a><br /> 
            <p style="font-size: 10px; color: #aaa;"><?php echo date('F, j Y',strtotime($item['pubdate'])); ?></p>
            <p><?php echo substr($item['summary'],0,strpos($item['summary'], "This is a post from")); ?></p>
            <?php endforeach; ?>

The first step is to include the WordPress file rss.php then will apply code after to style the feeds.

Of coarse I forgot to mention, change the RSS feed to the feed you want to pull.

Continue Reading

Random Search Terms

Title

Recent Posts: Fully Net Worth . com

Ceaser Emanuel Net Worth: How Rich is Black Ink Crew Star?

Ceaser Emanuel Net Worth: How Rich is Black Ink Crew Star?

David Emmanuel, who is better known as Ceaser Emmanuel, is the CEO of the tattoo shop franchise called Black Ink Crew. The show also has a reality television series of the same name on VH1 which has operated for a total of 8 seasons so far. As of 2019, Ceaser Emanuel net worth is estimated […]

Bernie Sanders net worth 2020.

Bernie Sanders net worth 2020.

Bernie Sanders net worth Introduction Bernie Sanders is an American politician who, since 2007, has been a junior U.S. senator from Vermont and U.S. One of the wealthiest guys to enter the potential presidential election of 2020 is Senator Bernie Sanders. Because of the intense emphasis of the political bourgeois on the role of ‘millionaires […]

Leah Messer Net Worth: How Rich is the Teem Mom Star Actually?

Leah Messer Net Worth: How Rich is the Teem Mom Star Actually?

Leah Messer is a television personality who is best known for being a part of the cast of the hit reality television show called Teen Mom 2. As of 2019, Leah Messer net worth is estimated to be $80,000. Messer grew up as a country girl from a small town called Elkview, West Virginia. She […]

Deval Patrick net worth.

Deval Patrick net worth.

Deval Patrick net worth Deval Patrick is an American politician who was born in Chicago, Illinois, in 1956. His father was a musician and left the family when Patrick was young. His mother raised him at the Robert Taylor Homes area near Chicago’s southern side. When he was in the 8th grade, Deval was recruited […]

Trending