Autoblog your Dribbble shots with a custom post type

2 Comments

dribbble to wp autoblog

I ran across a fun code snippet today by Tammy Hart that automatically creates posts to a WordPress custom post type from your Dribbble RSS feed. The post type is called “shot” and all it requires is for you to change your Dribbble name in the fetch_feed( ) function.

In addition to Tammy’s creation of the Shot post type, I put together a simple archive template that you can use in your theme. I used markup consistent with the Twenty Eleven theme, and it simply pulls the meta data defined in the post type for the entry title and post image. It also links to the original Dribbble post.

You can get Tammy’s code from her post on Forrst, and the archive template after the jump. Thanks to Tammy for sharing her fun implementation of custom post types!

To use this archive template, you’ll want to put it in a file named archive-shot.php. This name is important so that WordPress will know to pull from the shot post type. You can read about template hierarchy in the codex for more information.

<?php
/**
 * The template for displaying Dribbble Shot Archives.
 *
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.2
 */

get_header(); ?>

		<section id="primary">
			<div id="content" role="main">

			<?php if ( have_posts() ) : ?>

				<header class="page-header">
					<h1 class="page-title">Dribbble Shots</h1>
				</header>

				<?php twentyeleven_content_nav( 'nav-above' ); ?>

				<?php /* Start the Loop */ ?>
				<?php while ( have_posts() ) : the_post(); ?>

					<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
					<header class="entry-header">
						<h1 class="entry-title"><?php the_title(); ?></h1>
					</header><!-- .entry-header -->

					<!-- Let's show the image with the 'image' post meta -->
					<img class="thumb" src="<?php echo get_post_meta($post->ID, 'image', true) ?>" alt="<?php the_title(); ?>" />

					<div class="entry-content"><?php the_content(); ?></div>

					<!-- Let's link out to the dribbble shot with the link_url post meta -->
					<div class="link-out"><a href="<?php echo get_post_meta($post->ID, 'link_url', true); ?>">View this shot on Dribbble</a></div>

					</article><!-- #post-ID -->

				<?php endwhile; ?>

				<?php twentyeleven_content_nav( 'nav-below' ); ?>

			<?php else : ?>

				<article id="post-0" class="post no-results not-found">
					<header class="entry-header">
						<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
					</header><!-- .entry-header -->

					<div class="entry-content">
						<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
						<?php get_search_form(); ?>
					</div><!-- .entry-content -->
				</article><!-- #post-0 -->

			<?php endif; ?>

			</div><!-- #content -->
		</section><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

2 thoughts on “Autoblog your Dribbble shots with a custom post type

Comments are closed.