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/

Tips & Tricks

Remove the title attribute using jQuery

Published

on

In WordPress, when you use wp_page_menu your anchor attribute’s usually carry a title with the same name. I’m not sure if it’s correct to do this, but it bother me when I hover over a page menu navigation link and I get a hover of the title.

So on my site I used jQuery to remove the title:

$("#nav a").removeAttr("title");

Pretty simple huh?

Continue Reading

Tips & Tricks

How to: Open external links in a new window

Published

on

Over the weekend, I attended WordCamp Denver, and I was asked by John Hawkins how to force links to open in a new tab with out editing the source code. So, today lets learn a simple jQuery trick to open all external links in your site in a new tab or window. We are going to make sure you have jQuery active on your site, you can do this easily in WordPress, since it’s bundled with the latest installations. Use this code in your header: <?php wp_enqueue_script('jquery'); ?> then, below the wp_head add the following:

<script type="text/javacript">
var $j = jQuery.noConflict();

$j(document).ready(function() {
//external attribute
    $j("a:not([@href*=http://YOURSITE.com/])").not("[href^=#]")
        .addClass("external")
        .attr({ target: "_blank" });
    }
);
</script>

That’s it, just make sure you change the http://YOURSITE.com to your website.

Update

If you like you can remove the var $j = and replace all $j with simply just $

 

Continue Reading

Themes

Fixing plugins not compatible with hybrid 0.4.2

Published

on

Hey everyone, as you may have noticed I have a running on the site. While everything almost everything moved over smoothly, there was an issue with how my parent theme striped text in typography. This caused some plugins, like cformsII to not be allowed to print to the screen. Justin had helped to find a fix to filter the hybrid_typography function.

Originally this function filtered out and changed some text that would not validate as XHTML. This had to be removed by running a new function in the child theme’s function.php file.

add_action('init', 'remove_typography');

function remove_typography() {
	remove_filter('the_content', 'hybrid_typography', 11);
}
Continue Reading

Random Search Terms

Title

Recent Posts: Fully Net Worth . com

Ben Zobrist Net Worth: 4 Interesting Facts You Should Know

Ben Zobrist Net Worth: 4 Interesting Facts You Should Know

Ben Zobrist is an American professional baseball second baseman and outfielder who currently plays for the Chicago Cubs of Major League Baseball. Early Life Ben was born on May 26, 1981, in Eureka, Illinois to Cynthia and Tom Zobrist. He started playing baseball when he was eight years old. He graduated from Eureka High School […]

Angel Strawbridge Net Worth: How Rich is Angel Strawbridge Actually?

Angel Strawbridge Net Worth: How Rich is Angel Strawbridge Actually?

Angel Strawbridge is a designer, author who appears in the popular TV series called Escape to the Chateau along with her husband Dick Strawbridge where they work on renovating a massive Chateau they had bought in France after moving from England. Angel Strawbridge net worth is under review and is not available at the moment. […]

Alexandra Grant Net Worth: How Rich is Keanu Reeves’ Girlfriend?

Alexandra Grant Net Worth: How Rich is Keanu Reeves’ Girlfriend?

Alexandra Grant is an American art designer who examines language and written texts through painting, drawing, and sculpture. She is recently in the news after she was spotted holding hands with famous actress Keanu Reeves. Alexandra Grant net worth currently is under review Grant was born in 1973, in Fairview Park, Ohio. Her parents divorced […]

Pete Buttigieg Net Worth: 5 Facts You Should Know

Pete Buttigieg Net Worth: 5 Facts You Should Know

Pete Buttigieg is the mayor of South Bend, Indiana. He is also an American war veteran and a former consultant. In the recent days, Buttigieg has been growing his name with him announcing candidacy for the Presidential election in 2020. Then President Obama called him as one of four Democrats who represented the future of […]

Trending