List your Behance Feed in WordPress without a Plugin

List your Behance feed in WordPress is very similar to list any other feed. You can use the integrated functions from WordPress. The only problem is that the thumbnail images from the Behance feed have no tag for themselves. So we have to get it out of the project <description> XML tag. This happens with a small function, which grabs the <img> from the description string. Check it out:

<?php
	
// put your behance feed in the string http://www.behance.net/YOURFEED.xml
$rss = fetch_feed('http://www.behance.net/solemone.xml');

// set the number of items, now there are 6 items
$maxitems = $rss->get_item_quantity(6);

// get the items
$rss_items = $rss->get_items(0, $maxitems);

?>
    
<ul id="behance">

<?php

// handle if there is no feed or an empty feed
if (!$rss_items) :
	echo '<li>No items.</li>';
else : 

// function to get the image out of the description tag in the feed
// http://www.catswhocode.com/blog/10-php-code-snippets-for-working-with-strings
function GetBetween($content,$start,$end) {
	$r = explode($start, $content);
	if (isset($r[1])){
		$r = explode($end, $r[1]);
		return $r[0];
	}
	return '';
}

foreach ( $rss_items as $item ) :

?>

    <li>
        <a href="<?php echo $item->get_permalink(); ?>" title="<?php echo $item->get_title(); ?>">
            <?php echo "<img src='".GetBetween($item->get_description(), "<img src='", "'")."' alt='".$item->get_title()."'>"; ?>
        </a>
    </li>
      
<?php endforeach; ?>
 
</ul>

<?php endif; ?>

Comments

  1. This is quite good, but do you know if there is a way to get all project info from behance? ie like an api call where you can get everything and display it on your own site through php?

    by Lee Mason on
  2. Hi Lee,

    sorry but I don’t know any way to do that. The project information isn’t complete in the feed.

    by solemone on
  3. I am quite new to WordPress and have no clue on how to implement this code. Could you please guide me?

    Thanks
    Ben

    by Ben Kamble on
  4. Hi Ben,
    put this code where you want to show your Behance feed. Maybe in the sidebar or the footer. Then change the feed url in this line $rss = fetch_feed(‘http://www.behance.net/solemone.xml’); to yours. If you need more information about WordPress, check out the WordPress Codex http://codex.wordpress.org/Main_Page.

    by solemone on
  5. Hey solemone Great code, but I’m getting function errors on line 7 when I implement this on my personal site. I’m not sure why that is but every thing I’ve tried it comes back to the same line. any help would be great!

    by Nathan on
  6. Hi Nathan,

    can you please quote the error? Maybe I can find out the problem.

    by solemone on
  7. Absolutely,

    Parse error: syntax error, unexpected T_FUNCTION in /public_html/wordpress/wp-content/themes/nathanstaton/behance.php on line 15

    That particular line corresponds with your line 7 from above. thanks for looking into it. if you need anymore info just let me know.

    by Nathan on
  8. I’ve tested the script just now and got the same error. Dont know where it comes from. But I will check the code. If you find something before, please let me know.

    Edit: I think the problem ist the Code Highlighter that I am using. Try to copy this snippet and please let me know if it is working.

    <?php
    	
    	// put your behance feed in the string http://www.behance.net/YOURFEED.xml
    	$rss = fetch_feed('http://www.behance.net/solemone.xml');
    	
    	// set the number of items, now there are 6 items
    	$maxitems = $rss->get_item_quantity(6);
    	
    	// get the items
    	$rss_items = $rss->get_items(0, $maxitems);
    ?>
        
    <ul id="behance">
    
    <?php
    	// handle if there is no feed or empty feed
    	if (!$rss_items) :
    		echo '<li>No items.</li>';
    	else : 
    
    	// function to get the image out of the description tag in the feed
    	// http://www.catswhocode.com/blog/10-php-code-snippets-for-working-with-strings
    	function GetBetween($content,$start,$end){
    		$r = explode($start, $content);
    		if (isset($r[1])){
    			$r = explode($end, $r[1]);
    			return $r[0];
    		}
    		return '';
    	}
    
    	foreach ( $rss_items as $item ) :
    ?>
        <li>
            <a href="<?php echo $item->get_permalink(); ?>" title="<?php echo $item->get_title(); ?>">
                <?php echo '<img '.GetBetween($item->get_description(), '<img', '>').'>'; ?>
            </a>
        </li>
    <?php endforeach; ?>
    </ul>
    <?php endif; 
    
    ?>
    
    by solemone on
  9. Awesome that code worked!! I was told that it had something to do wIth php 5.3 update, but not sure. Thanks so much for the help, btw there is an inline margin-right of 15px imbedded with in the feed image. I’ve tried styling this out but I’d rather place the code within the IMG tag. Any thoughts ?

    by Nathan on
  10. Hi Nathan,

    just change this line:
    <?php echo ‘<img ‘.GetBetween($item->get_description(), ‘<img’, ‘>’).’>’; ?>

    to this:
    <?php echo ‘<img src="’.GetBetween($item->get_description(), ‘<img src="’, ‘"’).’" alt="’.$item->get_title().’">’; ?>

    This should work ;)

    by solemone on
  11. Someone in the comments asked if it was possible to add a description. We’ll I don’t know about a description, but you can easily add the title of the piece.

    After including the code I noticed that the HTML which it generates includes an element with a “title” property. Using CSS you can print the value of that property to the screen.

    In your CSS you can simply add the following:

    #behance a:before {
    content:attr(title);
    }

    This will place the title after the element, before the image.
    You can also adding other properties to this rule such as font-size.

    Just thought I’d share.

    by Akram Taghavi-Burris on
  12. Thanks Akram.

    by solemone on
  13. can’t work with my page after paste and edit feed link to my Behance, showing real this script or because of my template or what. this that page http://devinstudio.net/references-2/

    by devinstudio on
  14. Hi devinstudio,

    behance has changed the quotation marks in the RSS feed from " to ‘. I changed this line:

    <?php echo "<img src='".GetBetween($item->get_description(), "<img src='", "'")."' alt='".$item->get_title()."'>"; ?>

    I tested it, it should work again. Thanks for the note.

    by solemone on
  15. on my wordpress still doesnt work, I try using single page http://devinstudio.net/behance.php view

    Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’ in /home/xxxxxxxx/public_html/behance.php on line 36

    by devinstudio on
  16. The snippet does not seem to be in your template, but in a separate PHP file. It uses features that are loaded by WordPress. So you need to include this snippet in your theme files: wp-content/themes/your_theme/ Like your sidebar(sidebar.php) or a specific page template.

    by solemone on
  17. Hello,
    we created the page in php for our gallery on Dreamweaver, but on WordPress we can’t see the Behance feed. How can we call the WordPress page to our gallery page created in Dreamweaver?

    by Veronica & Sabrina on
  18. Hi Veronica & Sabrina,

    I think you have to create a Page Template in WordPress and put the snippet in it. Afterwards you can create a new Page in the WordPress admin area and define this Template for the created page.

    Check out this: http://codex.wordpress.org/Page_Templates

    I hope this helps you.

    by solemone on

Leave a Reply