Moving your WordPress site from one server to another

We had a great meetup tonight! The livestream lost connection briefly towards the end of the presentation, but we restarted it and recorded both pieces. The topic was how to move a WordPress site from host to host. For example, you’re developing a new site on your laptop using MAMP, WAMP, XAMP, etc. The steps we went through tonight were that exact scenario. Bill Erickson, who wrote an outstanding blog post on moving a WordPress site, had several tips and caveats for different scenarios: you’re developing a theme for a client’s existing site. You’re building a whole new version of a live site, etc. Nick Batik brought in some more considerations as well.

The first part of the presentation is below:

The second portion is next:

DiY content slideshow in WordPress

Content rotators or faders are everywhere, it seems. There are several plugins for WordPress that enable this on your site. In the mix, there are some very useful & handy ones. Dynamic Content Gallery, WP-Cycle, and WP-Rotator are three excellent slideshow plugins that I have used and are in my go-to list of WordPress plugins. That said, there always seems to be something that I don’t need or that I wish I had in one of these plugins. That’s when I look to writing my own custom slideshow tool using some WordPress code, CSS, and javascript to do exactly what I want.

There are three steps in this process:

  1. Write the query to grab the content. This is a custom Loop. Nothing really fancy there.
  2. Write the CSS to style the content.
  3. Include and write the necessary javascript to make it behave the way we want.

Writing the query

I believe it’s best to write the query in its own php template file. I created a file in my theme’s directory called slider.php. All my code for the custom Loop and the output will go here. Edit slider.php and add this code:

<div id="featured"> <!--The main container for our featured content -->
<?php
$featured_query = new WP_Query('cat=3&showposts=5'); // We create the query. Grab the 5 most recent posts in the category ID '3'
while ($featured_query->have_posts()) : $featured_query->the_post(); // Start our Custom Loop
$do_not_duplicate[] = get_the_ID(); ?>

<div class="featuredcontent">
<?php the_post_thumbnail( 'Featured_Slider' ); ?>
<div>

<h3><a href="<?php the_permalink() ?>">?php the_title(); ?></a></h3>

<p><a href="<?php the_permalink() ?>"><?php get_the_excerpt(); ?></a></p>
</div>
</div>
<?php endwhile; ?>
</div>

In the beginning of the code, we create a new query:

$featured_query = new WP_Query('cat=3&showposts=5');

You can customize this to your needs – I advise reading up on query_posts and wp_query in WordPress’s Codex.

After we create our new query, we output the results. In our case, we show the Featured Image, the title and the excerpt, both linked to the Post’s permalink. Slider.php is included in my theme using the get_template_part(); template tag in my index.php file. Place get_template_part(); where you want the slider to appear:

<?php get_template_part('slider'); ?>

The CSS

Now we need to write some CSS rules to format the content for our slider:

#featured {
position: relative;
z-index: 1;
height: 420px;
margin-bottom: 1.3em;
background-color: #000;
}

#featured .featuredContent {
overflow: hidden;
float:left;
width: 640px;
height: 420px;
}

#featured .featuredContent .featured_text {
position: absolute;
top: 310px;
width: 620px;
height: 100px;
padding: 10px 0 0 20px;
background-color: rgba(0,0,0,0.8);
z-index: 2;
}

#featured .featuredContent h3 {
color: #fff;
margin: 0 0 0 0;
}

#featured .featuredContent h3 a,
#featured .featuredContent h3 a:visited {
color: #fff;
font-weight: 800;
font-family: Helvetica,San-serif;
text-decoration: none;
}

#featured .featuredContent p {
color: #fff;
margin: 0 0 0 0;
font-family: Helvetica,San-serif;
font-size: 0.9em;
line-height: 1em;
}

#featured .featuredContent p a,
#featured .featuredContent p a:visited {
color: #fff;
text-decoration: none;
}

Make slider go fast now

We’ve created our new query, we’ve styled its content, now we add in the behavior – the sliding, fading, etc. The first example is a bit of javascript, using jQuery, that makes the divs with the class of featuredContent fade in & out. The second example uses jQuery Cycle. Both examples require you to enqueue WordPress’s included jQuery and an external javascript file you’ll create in your theme’s directory.

First, how do you properly load jQuery and your external javascript? If you add script tags in your theme’s header, you run the risk of loading javascript twice & possibly conflicting with javascript loaded by a plugin. The proper way to load javascript is to use the wp_enqueue_script function.

In your theme’s functions.php, add this code:

add_action('init','my_scripts');
function my_scripts() {
wp_enqueue_script(
'my.js',
get_bloginfo('template_directory') .'/js/my.js',
array('jquery'),
'1.1',
false
);
}

You can repeat the wp_enqueue_script function for other scripts you need to load.

For both examples, I created a file in my theme’s directory called my.js. This is where we write any custom javascript.

A simple fader using just jQuery

This example calls jQuery, then runs a script which fades the .featuredContent divs.

jQuery(document).ready(function($) {

var jS = $('div.featuredContent');
jS.hide(); // not needed if css hides elements initially
var i = 0;
function do_ticker() {
jS.eq(i).fadeIn(500, function() {
var me = $(this);
setTimeout(function() { me.fadeOut(500,
function() {
i = ++i % jS.length;
do_ticker();
});
}, 5000); // setTimeout
});
};
do_ticker();

});

The first and last lines load jQuery, in-between goes our custom javascript.

var jS = $('div.featuredContent'); //the element that's fading in & out - div class="featuredContent"

jS.eq(i).fadeIn(500, function() {
var me = $(this);
setTimeout(function() { me.fadeOut(500,

//500 is the duration of the transition in milliseconds (half a second) - how long both the fadein & fadeout take


}, 5000); // setTimeout in milliseconds (5 seconds) - how long each slide is visible

Why use the custom jQuery code instead of an effects plugin like jQuery Cycle? 1) You just want a fader, nothing more. 2) You want to minimize the amount of code you’re loading. That said, if you need some flexibility in the transitions, something like jQuery Cycle might be best.

Using jQuery Cycle.

jQuery Cycle is a slideshow plugin for jQuery that lets you use many different types of transitions – not just fading. To use it, we need to do two things differently:

1) load jQuery Cycle using wp_enqueue_script.

2) write some custom javascript.

Using our my.js file, we replace the custom javascript with this:

jQuery(document).ready(function($) {

$('#featured').cycle({
fx: 'fade', //replace fade with other transition types to use different effects
speed:500, //how fast the fade takes place
timeout:5000 //how long each slide stays on screen
});

});

You’ll want to load jQuery Cycle before you load your custom javascript.

add_action('init','my_scripts');
function my_scripts() {
wp_enqueue_script(
'cycle',
'http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js',
array('jquery'),
'1.1',
false
);
wp_enqueue_script(
'my.js',
get_bloginfo('template_directory') .'/js/my.js',
array('jquery'),
'1.1',
false
);
}

You’ll notice we’re loading jQuery Cycle from Github. If you want, you can place a copy in your theme’s directory and include it from there, as we do with my.js.

There we have it. A custom query, some CSS, and some javascript and you have a customized content slideshow in your WordPress theme. At the May Austin WordPress Meetup, I presented this using TwentyTen as the base theme. I’ve zipped that copy of TwentyTen with the custom code included. Enjoy!

 

Meta Boxes

At last night’s WordPress Meetup, we looked at ways you can add meta boxes to your WordPress content. When the basic “chunks” of content aren’t enough (title, content, excerpt, category, tag), adding meta boxes is a great way to add those extra bits of information & are easier to work with than Custom Fields.

The first method was the plugin More Fields. Easy to use interface for creating boxes with all the different input types you might need. Pros: easy to use. Cons: easy for someone to mess up or uninstall.

The second method was using the Custom Meta Box code developed by Bill Erickson, Andrew Norcross & Jared Atchison. This code allows you to build meta boxes into your theme. Pros: no plugin to install, harder for someone to muck up after you’ve got it set ‘just right’. Cons: If you’re not comfortable editing your functions.php, this may be intimidating for you to work with.

Delicious to WordPress Importer

Stephanie linked to a post today where Guillermo wrote a rough importer for WordPress back in 2009 that imports a Delicious XML export into your WordPress install as Posts. It needed some reformatting of the functions to register properly with WordPress & not cause errors.

Download the Delicious Importer here.

How do you get your Delicious bookmarks as an XML file?

Use this URL: https://api.del.icio.us/v1/posts/all but place your username / password inbetween the :// and the rest of the URL with an @ before the URL. Example:

https://my_username:my_password@api.del.icio.us/v1/posts/all

Once you have the exported XML file, install and activate the Delicious Importer plugin and import the XML file as you would a WordPress XML file.

Important – all your bookmarks will be imported, private ones, too. If you don’t want it imported, you will need to edit the XML file beforehand.

Update: Stephanie’s got a version on her site & hers handles private tags as private posts or invisible links. Grab a copy of it here.

WordPress 3.1 sneak peek

Here are the links from tonight’s early look at WordPress 3.1.

WP Beginner – What’s Coming in WordPress 3.1

WordPress Development Updates

Make WordPress UI

WordPress Demo Site

Here’s a post from Jane back in September on the Process & Scope for WordPress 3.1. This is a nice outline n what’s being worked on for the upcoming release.

WordPress in the Workplace – Nov 18th.

The WordPress Developer and Technical User Group in Dallas/Fort Worth is having a panel on  “WordPress in the Workplace” on November 18th.

We all know WordPress works great for personal blogs and affiliate marketers, but WordPress is being used more and more for company web sites. Whether it be agencies building sites for clients, companies selling digital goods, or university departments providing instructional content, many designers and developers at these organizations use WordPress as part of their day jobs. Our panelists will discuss their experience using WordPress in their Workplace.

Location:

Hickory Street Annex
501 Second Avenue
Dallas, Texas 75226

Looks like an interesting trip worth a drive up to Dallas. Free, with a suggested $5 donation for pizza. More info & registration here.

How I Learned to Stop Worrying and Love WordPress

photoThe Austin WordPress Meetup Group

There’s a change in the air here in Austin. Temperatures are down as Autumn moves in, we live in one of the best cities for just about everything in the United States and WordPress just keeps getting better and better.

Next week is the WordPress Meetup for October. We’re not doing a structured meetup this time. What I thought we’d do is talk about the upcoming WordCamp Austin. Plans are in the works, speakers are being talked with and we’d love to entertain your ideas and thoughts as the date approaches.

In addition, we can break out into informal problem-solving sessions to talk about your WordPress questions – theme problems, plugins, processes, etc.

Austin, TX 78757 – USA

Tuesday, October 5 at 7:00 PM

Details: http://www.meetup.com/austinwordpress/calendar/14928256/

WordPress in Art

I call it WPtruvian:

WPtruvian - wpinart

See more artistic mashups of the WordPress logo in art.

WPEngine launched – WordPress hosting

Cullen Wilson, Jason Cohen and Aaron Brazell have launched WPEngine this week. Hosting WordPress sites to the point where you just worry about themes, plugins & content – they take care of the rest of it.

WPEngine’s sponsored the WordPress Austin meetups & we’re proud to see them open for business.

Cheers!

Child Themes

I get asked more and more, “What is a child theme?” Even though child themes have been in existence for a few years, they’re still not something the average WordPress user understands, but that’s changing and the topic is at the forefront of people’s minds when they’re thinking about their site’s design. WordPress users want to know if they should use a child theme instead of their existing theme, be it custom or prebuilt.

First, what is a child theme. A WordPress child theme is a theme that relies on another theme being installed. A child theme can’t stand on its own. At the simplest, the child theme is just a style.css file with an extra commented line. That’s it.

Using the Twenty Ten theme, let’s look at the comment block at the top of that theme’s style.css:

/*
Theme Name: Twenty Ten
Theme URI: http://wordpress.org/
Description: The 2010 default theme for WordPress.
Author: the WordPress team
Version: 1.0
Tags: black, blue, white, two-columns, fixed-width, custom-header, custom-background, threaded-comments, sticky-post, translation-ready, microformats, rtl-language-support, editor-style
*/

For a child theme, we’ll create a css file called style.css. We have to place a comment block at the top of the file in order for WordPress to recognize it as a theme – with one extra line that begins with “Template”:


/*
Theme Name: My Awesomest Theme
Theme URI: http://123.com/
Description: Uber-awesomeness incarnate.
Author: Me
Version: 1.0a
Tags: optional
Template: twentyten
*/

That extra line “Template:” is what makes this a child theme. It has the directory name of the theme you want as a parent. In this case, Twenty Ten is going to be our parent theme. Its directory is named twentyten, so that’s the name we use in the Template line. If we activated My Awesomest Theme in the Appearance panel, (Remember, we only have the CSS file as our child theme – nothing else.) WordPress will use Twenty Ten’s templates for the site’s framework, but it will look to My Awesomest Theme for the CSS.

Inheriting the parent theme’s CSS

Say you want to use the parent’s CSS. Maybe you like 99% of it & you’re just going to override a few parts of it. Using the @import statement, you can import the parent theme’s styles and then add your own declarations below it. Browsers read CSS in a specific order (this is the Cascade part of Cascading Style Sheets) so it makes it easy to override specific styles while keeping the rest.

Below your comment block, add this line:
@import url(../twentyten/style.css);

Your child theme will now look just like Twenty Ten. All of Twenty Ten’s styles in style.css get imported to your theme. In Twenty Ten, this is the basic declaration for H1 through H6:

h1, h2, h3, h4, h5, h6 {
font-weight: normal;
clear: both;
}

In our child theme style.css, under the @import line, add this line:

h2 { font-weight:800;color:red;}

Save your changes and we’ve now made heading 2′s bold and red. Everything else stays according to Twenty Ten’s styles.

What about customizing template files?

What if you wanted to make structural changes to say, the header.php file? How would you do this in a child theme? It’s really simple. Copy the header.php file from the parent theme to your child theme’s directory and make your edits. WordPress will use your child theme’s header.php in place of the one in the parent theme.

That’s all there is to it.

Why use a child theme?

One very basic reason makes child themes beneficial: You can upgrade your parent theme without losing your design. A good child theme can persist through several WordPress upgrades. As a time-saver, this is pretty awesome. If you use Twenty Ten as a parent theme, there will be upgrades for Twenty Ten released. Version 1.1 just came out, in fact. Using a child theme on top of Twenty Ten, you in essence inherit those upgrades without having to redo your theme. Of course, the caveat exists that if you’re replacing template files, it’s on you to make sure your template files are up to date with released upgrades. That being the case, you’re still saving time and effort with a child theme as there are fewer files to go through than in a whole theme.

Another benefit of using child themes is for designers. Designers don’t have to build out a whole theme. They can create just a CSS file or a CSS file and the necessary templates.

Child themes present some serious advantages and they’re not that complicated to create. Give them a try.

More on child themes: