Genesis AgentPress Featured Image & Thumbnails

So I’m working on a real estate site and obviously wanted to use AgentPress from StudioPress but I found a couple of things that I’d like to work a little better/more automated – a featured image and thumbnails on the listing page.

On the listing page you have to insert a main image and then can insert a gallery if you choose to do so, but my client needs things to be as easy as possible so I made some changes for them and I’ll show you what I did and maybe you can use it as well.

In the AgentPress theme we’re going to be dealing with “functions.php” and “single-listing.php”.

First, in functions.php starting around line 13 you’ll notice code for creating image sizes. We’ll want to add a new size, so just add this line after the ones that are there:

add_image_size( 'featured-single', 600, 400, TRUE );

What that is going to do is crop a photo to 600×400 whenever you upload a featured image to a listing (or post/page for that matter). We’ll use this later on, so just save the file and upload back to your server.

Next, we want to pull that image into our Listings page automatically, so in your AgentPress theme, open up “single-listing.php”. What you’ll see is this:

<?php
remove_action( 'genesis_before_post_content', 'genesis_post_info' );
remove_action( 'genesis_after_post_content', 'genesis_post_meta' );
remove_action( 'genesis_after_post', 'genesis_do_author_box_single' );
 
genesis();

We’re going to add in a function to place the featured image before the content on that page but right below the page title. Here is the code we’ll add right after the last “remove_action” line seen above:

add_filter ( 'genesis_after_post_title', 'your_custom_header' );
 
function your_custom_header () {
echo '<div id="page_featured">';
echo the_post_thumbnail( 'featured-single' );
echo '</div>';
 
}

What we’re saying is after the post title, insert this code. You’ll see that I’m calling in the new image we created in the first step and just wrapped it in a div so that we can style it if we want.

So that brings in the featured image automatically – pretty cool! I also wanted to load in the WordPress gallery automatically also, so we need to add a bit more to that code and here is the gallery piece:

echo '<div id="single_gallery">';
	$attachments = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order_by' => 'menu_order'));
	            if ( ! is_array($attachments) ) continue;
	            $count = count($attachments);
 
	            foreach ($attachments as $ats) {
	            $atmeta = wp_get_attachment_metadata($ats->ID);
	            $atsrc = wp_get_attachment_image_src($ats->ID, array(100,100));
echo '<a href="'. $ats->guid .'" rel="lightbox" title="'.get_the_title($ats->ID).'">';
echo '<img src="'.$atsrc[0].'" width="100" height="100" title="'.get_the_title($ats->ID).'">';
echo '</a>';
}
echo '</div>';

You’ll see that it’s wrapped in a div as well (for styling) and also you see that I have the gallery thumbails set to be 100×100. You can change that size to whatever dimensions you’d like. Also notice the rel=”lightbox” in there – I’m using the LightBox Plus plugin and that will make the thumbnails pop up using that plugin. If you use a different plugin that requires different code you can change that out. Next, you’ll want some CSS to make the gallery look nice, so add this to your style.css file:

#single_gallery {
	margin: 10px 0px 10px 0px;
	}
 
 
#single_gallery img, #page_featured img {
	margin: 5px;
        padding: 5px;
	background: #fff;
        -moz-box-shadow: 0 1px 4px #000;
	-webkit-box-shadow: 0 1px 4px #000;
        -khtml-box-shadow: 0 1px 4px #000;
	box-shadow: 0 1px 4px #000;
	}
 
 
#single_gallery img:hover {
 
	background: #ccc;
        margin: 5px;
        padding: 5px;
	}

Putting it all together, this is what my entire “single-listing.php” file looks like:

<?php
remove_action( 'genesis_before_post_content', 'genesis_post_info' );
remove_action( 'genesis_after_post_content', 'genesis_post_meta' );
remove_action( 'genesis_after_post', 'genesis_do_author_box_single' );
 
/** Add Featured Image Below Title */
add_filter ( 'genesis_after_post_title', 'your_custom_header' );
 
function your_custom_header () {
    echo '<div id="page_featured">';
    echo the_post_thumbnail( 'featured-single' );
    echo '</div>';
    echo '<div id="single_gallery">';
	$attachments = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order_by' => 'menu_order'));
	            if ( ! is_array($attachments) ) continue;
	            $count = count($attachments);
 
	            foreach ($attachments as $ats) {
	            $atmeta = wp_get_attachment_metadata($ats->ID);
	            $atsrc = wp_get_attachment_image_src($ats->ID, array(100,100));
    echo '<a href="'. $ats->guid .'" rel="lightbox" title="'.get_the_title($ats->ID).'">';
    echo '<img src="'.$atsrc[0].'" width="100" height="100" title="'.get_the_title($ats->ID).'">';
    echo '</a>';
}
    echo '</div>';
}
 
genesis();

Now when you go to a listing page in AgentPress you will have your featured image and WordPress gallery automatically inserted – pretty slick!

Happy coding!

WordCamp Phoenix 2011

So it’s pretty obvious I don’t blog as much as I probably should, but this is my site so whatever, right?!

Anyway, to get things sort of caught up, I’ve been busy. 9seeds has been busy, thus the lack of posting…just working going on here. But this weekend I’ll be at WordCamp Phoenix and thought I’d write a little about it.

First, on Friday I’ll be doing a free Intro to WordPress for Beginners class as part of the Free WorkShop Friday, which should be really cool. It’s from 9am-4pm and we’ll cover everything you’d probably ever want to know about using WordPress. I really like this idea as a lot of beginners are lost at WordCamps and just need a very basic intro to what WordPress is, etc so I’m excited to have been asked to do this.

Saturday I’ll be speaking about WordPress and eCommerce at 1:30pm and will cover WP eCommerce, Shopp and PHPurchase which are shopping cart solutions for WordPress. I have 30 minutes, so don’t blink as you might miss something ! I’ll be around all day and helping out at the Genius Bar so there will be plenty of time for questions.

On Sunday my wife Abbie was asked to teach a WordPress for Kids class. This is really cool! Again – they’ve thought of everything. Everything! We homeschool our kiddos so she’s the perfect fit for this class and what better thing to teach kids than to know WordPress?

Working at home and being far away from my WordPress friends is tough sometimes but it all evens out at WordCamps – it’s sort of like reunion time so I’m excited about seeing all my friends that I haven’t seen in a while. The whole 9seeds crew will be there as well so that’s cool, since we don’t see each other often enough either – so it’s going to be a packed weekend but good times will be had.

I’d also like to recognize Amanda Blum, Chuck Reynolds and the rest of the team at WordCamp Phoenix for all the hard work they’ve put into this event. 5 days of WordPress, over 600 attendees and surprises around every turn – I really don’t think they’ve left a single detail unnoticed. If you’re attending WordCamp Phoenix, make sure to find them and let them know how much they are appreciated and not just drink all of the free coffee :)

That’s it for now…

WordPress Twitter Archive

So…I read a cool article last week about creating a Twitter archive using WordPress at wpmu.org and thought that it sounded like a great idea as I would like to “own” all of my tweets and have them in MY database….just because I can I suppose.

So, first I’ll say that this is a great article, but the services listed (backupmytweets.com and tweetbackup.com) are not the greatest. They do in fact work, but neither gave me the exported file type that I wanted and for the life of me, I could not get them to import into WordPress as posts. So I went searching with my best friend. Google. What actually happened was that WordPress itself helped me out and solved my issue. If you go to “Tools–>Import” in the WordPress Dashboard it will show you the importers available, but what I rarely pay attention to (as I don’t import hardly at all) is that below the importers there is a really cool link that says:

“If the importer you need is not listed, search the plugins directory to see if an importer is available.”

So I click that it shows a search result for “importers” in the WordPress Plugin Repository….nice. Guess what was there? A Twitter Importer! And yes, it works great.

So, here is what I did to get my Twitter Archive up and running on WordPress:

1. Made a new subdomain on my site and set up WordPress like I normally would.

2. I downloaded and installed the Twitter theme that was mentioned in the article above.

3. I mention this high in the list because if you wait to do this later, your time/date on your old tweets will be wrong. Go to “Settings–>General” in the WordPress Dashboard and make sure your time settings are correct for wherever you live.

4. Install Twitter Tools plugin and configure it to create a blog post for every tweet you make. (there are some settings in here that require you to get API info from Twitter, etc, but it’s super simple…just follow the instructions from the Twitter Tools setup page.

5. Download and install the Twitter Importer. Once you do that, it will show up on the “Tools–>Import” page in the WordPress Dashboard.

6. Run the Twitter Importer. It will ask for your Twitter handle, what user to associate them with and what category you want to dump them into. If you want them to go to a particular category, you will need to create that first (go to “Posts–>Categories” in WordPress Dashboard to create new category). So now all your tweets should be imported as Posts, (NOTE: If you don’t see all of your tweets show up, run the importer again as sometimes it can take 2-3 tries to get ALL of your tweets imported) but you’ll notice all of the links are just text.

7. Download and install the Autolink URI plugin and activate it. This will take all of the text links in your tweets and convert them to functional URLs.

8. Next you’ll notice that all Twitter handles are not links either. The way I made this work was to use TwitterEverywhere. There is a really good how-to on the WPBeginner site. I used the “Auto Link all Twitter Usernames with Hovercard” and the “Smart Follow Button (in the header of my Twitter Archive site). The API stuff – you can just use the same one you created from step 4 above. That links all twitter names and adds a cool “hovercard” with info on the twitter username that you hover your mouse over. (This code is included in my theme if you decide to use it, just change out your Twitter handle and the API with the dummy content I have in there)

So, that’s what I did…and it works great. I also edited the theme somewhat for my liking, and I’m going to let you have that if you want as well (with a PSD to edit the header graphic). The theme is very simple and nice and optimized to be used for this purpose. It “did” contain ONLY CSS, but I added a background image and header image to it, but besides that, it’s all CSS.

The only thing that I notice is that hashtags are not links on imported tweets…I’m still researching that one, but if you know (or find) a way to do this, please feel free to comment and let me know!

Good luck – and here is my edited theme if you want to use it.

Oh, and the URL to my Twitter Archive site – http://shaynesanderson.com/tweet