1. Grab RSS feed with PHP

    Posted on: September 29, 2009

    I would like to share a PHP function for writing out parts of an RSS feed to a page. I used this in the redesign of ryanbosinger.com to show the latest three posts of this blog.

    To use it, just call the function where you’d like it show up like so:

    <?php getFeed("http://ryanbosinger.com/blog/feed", 3); ?>

    The second parameter is the amount of posts to show. It will write out as an unordered list. You can choose to write out different parts of the feed by changing: $x->channel->item[$i]->[name-of-feed-tag]

    <?php
    function getFeed($feed_url, $posts_to_show) {
     
    	try 
    	{
    		$content = file_get_contents($feed_url);
    		$x = new SimpleXmlElement($content);
     
    		echo "<ul>";
     
    		$i = 0;
     
    		while ($i < $posts_to_show){
    			echo "<li><a href=\"" . $x->channel->item[$i]->link . "\" title=\"" . $x->channel->item[$i]->title . "\" target=\"_blank\">" . $x->channel->item[$i]->title . "</a></li>";
    			$i++;
    		}
     
    		echo "</ul>";
     
    	} 
    	catch (Exception $e) 
    	{
    		echo "<p>The blog feed doesn't seem to be available at the moment...</p>";
    	}
    }
    ?>

  2. That damn clearFix…

    Posted on: September 23, 2009

    I’ve used this solution to clear float containers in CSS:

    /* float clearing for IE6 */
    * html .clearfix{
      height: 1%;
      overflow: visible;
    }
     
    /* float clearing for IE7 */
    *+html .clearfix{
      min-height: 1%;
    }
     
    /* float clearing for everyone else */
    .clearfix:after{
      clear: both;
      content: ".";
      display: block;
      height: 0;
      visibility: hidden;
      font-size: 0;
    }

    But it seems you can just do this as well:

    #container-to-fix { overflow: hidden; }

    Now I’ve read a bit about how this isn’t always the most ideal solution, but simply setting overflow to “hidden” has definitely been working out for me lately…