Archive for the ‘WordPress’ Category

An Intro to WordPress 3.0 – Navigational Menus

Sunday, June 20th, 2010

WordPress 3.0 has plenty of new features, and all of them are worth mentioning and diving deeper into.  Over the next few days I’ll be diving into the finer features of the newest incarnation of the WordPress platform.  Everything from Custom Post Types and Taxonomies to navigational menus and all of the custom functions you can sink your teeth into.  Today, we start with the most prolific change to hit WordPress 3.0 – the inclusion of a navigational menu generator.

WordPress’ navigation options before 3.0 were very… eclectic.  There were about 3 to 4 different plugins I used to achieve the desired effect (My Page Order, Exclude from Page Nav, 301 Redirect, etc).  With the advent of WordPress 3.0 came a breakthrough in its jump from a blog platform to a content management platform: navigational menus.

Example of a drop down navigation menu.

The menu above looks like any typical navigational menu, but the difference lies in the backend.  You don’t need to know page ID numbers, you don’t need to use funky page reordering to get things to work right – all you need is two snippits of code and you can add dynamic navigation to any WordPress site.

First, the function (place this code in your functions.php file):

add_theme_support( 'nav-menus' );

That’s it – for the function, anyways.  Now, find in your theme where you want to put your navigation.  You’re looking for either a hard coded navigation, an unordered list (a typically form of navigation styling and structure), or the function <?php wp_list_pages( ); ?>.  Once you’ve found that, replace it (or add in) this code set:

<?php wp_nav_menu( ); ?>

That’s all there is to it.  Your theme is set up for  navigational menus that you can control in the WordPress backend.  One thing worth mentioning is that this is the default setting.  It will pull the class from whatever you name your menu in the next screen.

What’s that?  You want to add some pages?  Sounds great – click on the Menus tab under appearance over on the left side of your dashboard.

Menu Screen in WordPress 3.0

You’ll notice three things on the left side of the menu: Custom Links, Pages, and Categories.  Pages and categories are pretty self explanatory: you can add links to category listings or the pages of your WordPress site.  The custom links box allows you to give an external or custom link/label a place in your navigational menu – good for linking to social networks, other sites, etc.

Up on the top-right corner of the page is a tab called “screen options”.  Clicking this will bring up the advanced options for the menu navigation, such as the class you wish to give your links, XFN relationships, etc.  It also brings up menus for inserting posts and tags into your navigational menu – good if you have an intro post you like to point your visitors to.

You should be looking at the new

WordPress 3.0 RC1 – a look

Monday, May 31st, 2010

Screenshot If you missed my session at WordCampFayetteville over the new awesome features WordPress 3.0 will have, never fear.  For one, the new release candidate (a stable version, but not quite ready for deployment) is out, and most of the bugs have been squashed.  Not all, but that’s ok, I’ll talk about that in a bit.

So, what do you have to look forward to in the newest version of the most popular blog/CMS ever?  Well…

1) A New Default Theme (Hallelujah!)

Gone are the nasty default blue chunky headers, and in its place is an elegant, streamlined photo header complete with drop down navigation and stylish polished features.  There are a total of 6 sidebar areas (2 side, 4 footer) and loads of customization options (background, header, etc).

2) MultiUser (MultiSite)

Taking the golden child of automattic and the still-ok-but-not-one-you’d-take-home-to-your-mother stepchild and merging them together has been no easy task.  But, the awesome people at Automattic have done just that – they’ve merged the codebase for MU and WordPress together to one.  This means that now there’s a new “MultiSite” WordPress option when you’re installing your new WP installation, and you can convert existing installations over with a few simple edits to your wp-config.php file.  There’s also a new role – the SuperAdmin, which will have admin access to all sites, and let the individual sites have their own separate admins.

3) The Menu System

Screenshot-1

In my opinion this is the “game changer” for the new WP release.  This custom navigational menu system will allow you to create menus from pages, categories, and even external URL’s.  Support for drop-downs can be styled in, as does the new theme, and allows for a super-easy way to customize WordPress like never before (without having to move around, code, or plugin your way to a nice navigation menu).

4) Custom Taxonomies and Post Types

They’ve “sort of” been around a bit, but not in an easy to use form.  Now, they are.  Custom taxonomies allow you to sort posts outside of the normal category/tag elements.  Have a certain color you reference in every post?  Create a color taxonomy and let your users search by color, and not category.  Custom post types let you specify taxonomies inside of them, giving you even further separation (a custom post type would be similar to how Tumblr does things – photos, text, etc.)

5) Choosing Your Own Dang Username

Been missing, been needed, and it’s here – and it should help eliminate 33% of all of the security issues for brute-force attacks.  And, please, don’t set your username as admin – do us all a favor.

6) More Features

Some minor features, such as author templates, a welcome guide, URL shortlinks, automatic inclusion of feeds with a function and others are also included.

What can I do to help?

If you’re willing to go ahead and run the RC (I did, and I have been since beta with 0 problems) then do so.  That way, if you find a bug, you can submit a ticket for it and help out 1000s of other users who may have that same bug.  If you’re a developer, submit your tickets to trac and watch the fun.  Get involved with the mailing list, the IRC chat, or other places to help submit the tickets and get it fixed.  We are what makes WordPress so awesome – the community.

So what about you? What are you most looking forward to about WordPress 3.0?

Adding a Facebook “Like” Button to WordPress – the (Somewhat) Easy Way

Friday, April 23rd, 2010

UPDATE: I managed to write this into a plugin – Facebook Like Button

Since Facebook announced a few days ago that you would be able to use its OpenGraph technology to “like” pretty much anything on the Internet, I took it upon myself to test out a few solutions for adding a “Like” button on the site.

It turned out to be fairly easy, but not as easy as just adding a plugin and doing forth (at least, it’s not yet, anyway).

Our Plan of Action:

  1. Download and Install the plugin
  2. Editing the core file to allow for correct width and color scheme

Step 1: Downoading the Plugin

I looked through quite a bit of plugins to find this one, and I had to get it from his website because it’s an alpha release, but the Facebook Like Widget does it cleanly and with little fuss.

Step 2: Customizing the Plugin

OK.  Editors note: normally I do not advocate editing the core of a plugin.  Why? Because when you update (and you should!) it will over-write what you did.  However, since this is an alpha release, and I’m almost positive the next changes will allow you easily do these changes, I think once or twice is ok.

You’re going to want to click into Plugins > Editor, and choose the “Facebook Like Widget” plugin from the list.

There’s literally about 20 lines of code:

<?php
/*
Plugin Name: Facebook Like Widget
Plugin URI:
http://allanjosephbatac.com
Description: Add a Facebook ‘Like’ Button Widget to your post pages. Increase visitors!
Author: AJ Batac
Version: 0.1
Author URI:
http://allanjosephbatac.com
*/

function add_facebook_like($the_iframe = ”)
{
    $the_perma    = rawurlencode(get_permalink());
    $the_iframe    .= ‘<div id=”facebook_like”><iframe src=”
http://www.facebook.com/plugins/like.php?href=’.$the_perma.’&amp;layout=standard&amp;show-faces=true&amp;width=600&amp;action=like&amp;font=arial&amp;colorscheme=dark” scrolling=”no” frameborder=”0″ allowTransparency=”true” style=”border:none; overflow:hidden; width:600px; height:auto;”></iframe></div>’;
    return $the_iframe;
}

add_action(‘the_content’, ‘add_facebook_like’);
?>

The bold, color coded areas above show the areas you can change. The width corresponds to how wide your blog is.  if you don’t know, then just leave it at the default (450px) and you should be OK.  However, your friend’s “faces” won’t go to the edge of your content.  In yellow is the “color scheme”.  If you have a light background, choose “light”.  If you have a darker background, like my site, choose “dark”. 

That’s it – the like badge will show up at the bottom:

image

And will also show up on your friend’s “Recent Activity” stream:

Capture

Keep in mind, this is not the most elegant solution, but until others come, this is a great way to get it on your site quickly and with very little editing.

How to Create a Dynamic Sidebar Controlled with Custom Fields in WordPress

Wednesday, April 14th, 2010

OK, so it’s not the most original title in the world, but it gets the point across :)

I’ve been working with the fantastic Jeff Brown and the Way-FM crew to create a site for their Nashville presence that will allow them super-quick, easy content management and a place they can post local stories and events.  WordPress, of course, is the logical choice, but then they presented me with an interesting conundrum: make their “jock” bio pages fun and engaging.  And make it have all of their social bells and whistles on it.

I took up the challenge.

And honestly, it’s super-freakin’ easy to do.

Our to do list:

  • Define a global variable in WordPress that will carry outside of the post loop
  • Create the custom field, and set the key names
  • Create a template tag that will showcase only the custom field data I want
  • Create an IF statement to, if there’s nothing in the field, collapse the field (the cool part!)

Step 1: Define our Global Variable

A Global Variable (looks like this: $variable) is basically a proxy for some other piece of code.  When we set one, and we can set a variable to anything we want, we’re saying “Instead of saying this long random code string, we’re going to say one word and a dollar sign.  Makes for much easier querying in WordPress.

Look for the code line:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

Right after that, add this line:

<?php global $globalvar; $globalvar = $post->ID; ?>

You can name it whatever you want, just make sure to carry the new name throughout the code.

Step 2: Create the custom fields

Remember how to create custom fields?  Below the post editor look for these boxes:

image

If you’ve never created a field, that will be blank.  Enter in your key (the name) and the value and hit “update”.  The yellow flash will tell you it was a success.  Remember that key name: it’ll come in handy later </resident Evil>

Step 3: Create a template tag to call the data.

I’m going to keep a standard format to these, just for ease of use.  I’ve formatted this like a normal sidebar widget is, just so I can have consistency between the main site and these special pages.

Head over to the sidebar.php file (or whatever file you want to drop this code into) in the Appearance > Editor. 

<?php $globalvarcheck=get_post_meta($globalvar, ‘keyname’, true); ?>

<li class=”widget”>
    <h4 class=”widgettitle”>Facebook</h4>
      <?php echo $globalvarcheck ?>

    </li>

get_post_meta is our tag of choice.  There are three, comma separated options: 1) Post ID, 2) key name, and 3) do we want to display it, or queue it in an array.  Basically, we call another global variable to specifically call the first variable as the post id, and give it the correct key name to make sure we call the right variable.

Step 4: Preventing Empty Widgets with an If Statement

But, Mitch, what happens if we don’t have a value set for a key? Never fear.  You can use a simple check with the same global variable to only display the data if that custom field has information in it. 

Here’s a facebook widget I developed (so you can drop in a Fan Page box) and showcase it on a particular page.  It shows the full IF statement with some example verbage:

<!–Facebook Widget Start–>
<?php $facebookcheck=get_post_meta($globalvar, ‘facebook’, true); ?>
    <?php if ( $facebookcheck ) { ?>

<li class=”widget”>
    <h4 class=”widgettitle”>Facebook</h4>
      <?php echo $facebookcheck ?>

    </li>
<?php  } ?>
<!–Facebook Widget End—>

Usage

Obviously, dropping in random social media widgets is a great way to use this, but I have a bonus for all you twitter-ites out there.  Ricardo González created a plugin called Twitter for WordPress, and it’s one of the few that uses template tags as a way of insertion (you see where this is going?):

<!–Twitter Widget Start–>
<?php $twittercheck=get_post_meta($globalvar, ‘twitter’, true); ?>
    <?php if ( $twittercheck ) { ?>

<li class=”widget”>
    <h4 class=”widgettitle”>Latest Tweets</h4>
     <?php twitter_messages($key_1_value = get_post_meta($twitterID, ‘twitter’, true), 5); ?>

    </li>
<?php  } ?>
<!–Twitter Widget End—>

I know that looks like a lot of code, but I basically embedded one template tag in another.  The first value in the twitter_messages tag is the global variable calling a twitter username.  The second calls the number of tweets.  Basically, enter in a twitter username, and if you do, this will display 5 tweets from it.  Pretty cool eh?

I can’t show the full site example because it’s not launched yet, but here’s a sneak peek at the new Way-FM site, and this code in action:

image

WordPress Plugin: Author Spotlight

Monday, March 22nd, 2010

I’ve been doing a lot of looking into using WordPress as a multi-author website/blog lately.  A few of my clients have requested the need to handle (elegantly) multiple authors, so (being fresh on my mind) I feel inclined to share.

One of the coolest plugin combinations I’ve come across recently is using Author Spotlight and Authors Widget in combination with a custom author template to create a really fun way to showcase authors both in the sidebar, on their own page, and on a single page.  The first two are easy, but the third one takes a small tweak to get things going.

The easiest way I’ve seen is to add a sidebar widget spot to the single post page with this code:

  <ul id=”spotlight”>
            <?php     /* Widgetized sidebar, if you have the plugin installed. */
                    if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(2) ) : ?>
            <?php endif; ?>

   </ul>

Then, hit up your functions.php and make the necessary changes to add in a second (third, fourth, etc) sidebar:

<?php
if ( function_exists(‘register_sidebars) )
    register_sidebars(2,array(
        ‘before_widget’ => ‘<li id=”%1$s” class=”widget %2$s”>’,
        ‘after_widget’ => ‘</li>’,
        ‘before_title’ => ‘<h2 class=”widgettitle”>’,
        ‘after_title’ => ‘</h2>’,
    ));

?>

Finally, download and install Author Spotlight and drag it to your second sidebar.

You’ll have to do a bit of styling to get things looking nice (like the screenshot below), so here’s what I recommend:

image

#author_spotlight{
margin: 0;
list-style: none;
border: 1px solid black;
padding: 0 15px;
margin: 10px 0;
min-height: 150px;
}

#author_spotlight i a{
display: none;
}

#author_spotlight img{
float: left;
margin-right: 15px;
}

h4#author_name{
display: none;
}

#author_spotlight h2.widgettitle{
background-image: none !important;
padding-left: 0px !important;
}

Special thanks to Aaron, Mark, and Kelly over at The Periscope Group for letting me (aka, they just launched and I’m sending some traffic their way) take a peek inside his CSS code and use his site as an example.

How to Create a Slick Javascript Sliding RSS Reader in WordPress

Friday, March 19th, 2010

I’ve been learning lots of new WordPress tricks this past week.  Writing them down is two-fold win for me because 1) you guys get a look into how I do some of the stuff I do, and 2) I don’t forget how to do these tutorials later on when I need them again.  Yes, that can be a problem sometimes for me.  Don’t judge me.

Anyway, Scott Raynovich over at the Rayno Report wanted a fantastic way to showcase RSS feeds from around the web.  He wanted something that would allow more than four or five feeds without taking up the whole sidebar.

The result?  This really slick Accordion based feed sidebar:

image

Clicking on one of the titles…

image

Everything slides down to make room. 

It was actually really simple to create, and the best part: it’s widgetized!  That’s right, any feed that needs to be added in is simply added in as an RSS widget to a special sidebar.

So, onto the how-to!

Our process includes the following:

  1. Set up and Install the Accordion Script (and Google-Load jQuery)
  2. Set up a second sidebar (or third, or whatever number you have)
  3. Add the appropriate code to the sidebar.php file
  4. Add in a few widgets to test

Step 1: The Accordion Script

I know that there’s a jQuery-UI accordion script that’s floating around, but we’re going to be using a bit of a modified version that’s set up specifically for WordPress.  I like to pre-load via Google jQuery as well – takes some of the load off of the server and allows it to do its thing, letting Google fit the processing power for the actual framework.

Insert this code into your header:

<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js”></script>
<script type=”text/javascript”>
function initMenus() {
    $(‘ul#accordion li ul’).hide();
    $.each($(‘ul#accordion’), function(){
        $(‘#’ + this.id + ‘.expandfirst ul:first’).show();
    });
    $(‘ul#accordion li h2.widgettitle’).click(
        function() {
            var checkElement = $(this).next();
            var parent = this.parentNode.parentNode.id;

            if($(‘#’ + parent).hasClass(‘noaccordion’)) {
                $(this).next().slideToggle(‘normal’);
                return false;
            }
            if((checkElement.is(‘ul’)) && (checkElement.is(‘:visible’))) {
                if($(‘#’ + parent).hasClass(‘collapsible’)) {
                    $(‘#’ + parent + ‘ ul:visible’).slideUp(‘normal’);
                }
                return false;
            }
            if((checkElement.is(‘ul’)) && (!checkElement.is(‘:visible’))) {
                $(‘#’ + parent + ‘ ul:visible’).slideUp(‘normal’);
                checkElement.slideDown(‘normal’);
                return false;
            }
        }
    );
}
$(document).ready(function() {initMenus();});
</script>

The first script tag loads jQuery, the second the accordion script.  Notice how we’re targeting ul#accordion as the feed sidebar, and h2.widgettitle as the trigger.

Step 2: Adding a Second Sidebar into the Functions

Head into the theme editor and navigate to your theme functions file (functions.php).  We’re going to 1) make sure there’s widgetized sidebar code inside and 2) make sure that it calls for more than one sidebar.

If you have:

<?php
if ( function_exists(‘register_sidebars) )
    register_sidebar(array(
        ‘before_widget’ => ‘<li id=”%1$s” class=”widget %2$s”>’,
        ‘after_widget’ => ‘</li>’,
        ‘before_title’ => ‘<h2 class=”widgettitle”>’,
        ‘after_title’ => ‘</h2>’,
    ));

?>

or something similar, you’re already widgetized.  Change that code to what comes next to get it multiple-sidebar ready.  If you aren’t widgetized, add in this bit of code at your own risk:

<?php
if ( function_exists(‘register_sidebars’) )
    register_sidebars(2,array(
        ‘before_widget’ => ‘<li id=”%1$s” class=”widget %2$s”>’,
        ‘after_widget’ => ‘</li>’,
        ‘before_title’ => ‘<h2 class=”widgettitle”>’,
        ‘after_title’ => ‘</h2>’,
    ));

?>

This sets up two sidebars.  The second sidebar will be where our feeds go.

Step 3: Adding a Second Sidebar

Save your file and switch to sidebar.php.  If you’re widgetized you should see something like this:

  <ul id=”sidebar”>
            <?php     /* Widgetized sidebar, if you have the plugin installed. */
                    if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar() ) : ?>
            <?php endif; ?>

   <!—OTHER SIDEBAR STUFF—>

   </ul>

Somewhere in that file (either before the if statement, or after), you want to add in this:

<li class=”feedreader”>
  <h2 class=”widgettitle”>RSS Feeds</h2>
  <ul id=”accordion” class=”collapsible”>
                <?php     /* Widgetized sidebar, if you have the plugin installed. */
                    if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(2) ) : ?>
            <?php endif; ?>
</ul></li>

This adds in a widget that will serve as the container for the accordion file.  Then, we have another unordered list that will contain the feed widgets we drop in.

You should have something that looks like this:

  <ul id=”sidebar”>
            <?php     /* Widgetized sidebar, if you have the plugin installed. */
                    if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar() ) : ?>
            <?php endif; ?>

<li class=”feedreader”>
  <h2 class=”widgettitle”>RSS Feeds</h2>
  <ul id=”accordion” class=”collapsible”>
                <?php     /* Widgetized sidebar, if you have the plugin installed. */
                    if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(2) ) : ?>
            <?php endif; ?>
</ul></li>

   <!—OTHER SIDEBAR STUFF—>

   </ul>

That will insert your new sidebar. 

Step 4: Adding Widgets

After that, the last thing to do is to add in some feeds to test out in the Widgets panel of the Appearance tab.  Add in two or three to get a test, then view the page.

Any styles can be applied to make things look better, and here’s what you can expect to be able to change:

ul#accordion – controls the entire accordion box

ul#accordion h2.widgettitle – controls what the title feed of the individual feeds looks like

ul#accordion li li – individual feed items

ul#accordion li a – individual feed link properties

Head over to the Rayno Report to see it in action (and read his content – LOTS of great tech tips from the financial side).

How to Make a Royally Awesome Author Template in WordPress

Wednesday, March 17th, 2010

I’ve been trying some new stuff with my client’s websites as of late.  I wanted something where a multi-blog site could get the most out of as few plugins as possible, and still have a really awesome way to display their author’s main information.  But, the information they ask for doesn’t have everything.  What about twitter profiles? Facebook links?

There’s a few things we can do to enhance the process.

We’re going to be accomplishing a few things here:

  1. Building an author.php template to take care of author links
  2. Downloading and installing any necessary plugins
  3. Customizing the author profile with new fields.
  4. Calling those new variables in the author template.

Step 1: Building an Author.php template

So, WordPress’ structure for templates goes as follows:

  • author.php
  • archive.php
  • index.php

It looks for files (top to bottom) and uses whichever one it finds to do its bidding.  Since default templates don’t usually have one, we’re going to build an author.php file.  To start with, let’s make it look something like this:

<?php get_header(); ?> <div id="content" class="narrowcolumn"> <!-- This sets the $curauth variable --> <?php if(isset($_GET['author_name'])) : $curauth = get_userdatabylogin($author_name); else : $curauth = get_userdata(intval($author)); endif;  ?> <h2>About: <?php echo $curauth->nickname; ?></h2> <dl> <dt>Website</dt> <dd><a href="<?php echo $curauth->user_url; ?>"><?php echo $curauth->user_url; ?></a></dd> <dt>Profile</dt> <dd><?php echo $curauth->user_description; ?></dd> </dl> <h2>Posts by <?php echo $curauth->nickname; ?>:</h2> <ul> <!-- The Loop --> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <li> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"> <?php the_title(); ?></a>, <?php the_time('d M Y'); ?> in <?php the_category('&');?> </li> <?php endwhile; else: ?> <p><?php _e('No posts by this author.'); ?></p> <?php endif; ?> <!-- End Loop --> </ul> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>

What this does is set up the author variables, calls some basic variables like name, url, and a bio (description), and displays the last X posts (defined by the number set in the options menu).  We’re going to be modifying this quite a bit, but this gives us a good start point.

Save this as author.php, send it to your server via FTP, and open it in your theme editor to make sure it looks OK.

Step 2: Plugins We’ll Need

Actually, we’ll only need one plugin to really get the most out of this: the Authors Widget plugin. This gives us a really cool widget that pulls the author’s name and gravatar (if you choose) and displays post counts (also if you choose – lots of options).  It’s a fast way to showcase all the authors in the sidebar.  If you click on the author’s name, it takes you to their author page (which is what you just build [author.php]).

Step 3: Adding Fields to the User Profile

Open the theme editor and edit (or create an upload if you don’t have one) the functions.php file.  This file has lots of drop-in options you can get from Google to enhance your theme.  Widgetized sidebar code goes here too, so most people have one already.

Drop in this data:

add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );

function my_show_extra_profile_fields( $user ) { ?>

<h3>Extra profile information</h3>

<table class="form-table">

<tr>
<th><label for="twitter">Twitter</label></th>

<td>
<input type="text" name="twitter" id="twitter" value="<?php echo esc_attr
( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Please enter your Twitter profile URL.</span>
</td>
</tr>

<tr>
<th><label for="facebook">Facebook</label></th>

<td>
<input type="text" name="facebook" id="facebook" value="<?php echo esc_attr
( get_the_author_meta( 'facebook', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Please enter your facebook profile URL.</span>
</td>
</tr>

<tr>
<th><label for="linkedin">LinkedIn</label></th>

<td>
<input type="text" name="linkedin" id="linkedin" value="<?php echo esc_attr
( get_the_author_meta( 'linkedin', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Please enter your linkedin profile URL.</span>
</td>
</tr>

</table>
<?php }

add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );

function my_save_extra_profile_fields( $user_id ) {

if ( !current_user_can( 'edit_user', $user_id ) )
return false;

/* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
update_usermeta( $user_id, 'twitter', $_POST['twitter'] );
update_usermeta( $user_id, 'facebook', $_POST['facebook'] );
update_usermeta( $user_id, 'linkedin', $_POST['linkedin'] );
}

This dataset is for adding a twitter, linkedin, and facebook profile link box to each user profile.  You can customize it however you need to, just add:

<tr>
<th><label for="twitter">Twitter</label></th>

<td>
<input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta
( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Please enter your Twitter profile URL.</span>
</td>
</tr>

and change the values from “twitter” to whatever you want the field to be called.  Also, add a line like this:

update_usermeta( $user_id, 'linkedin', $_POST['linkedin'] );

under the rest.  That will allow the data to be saved.

4. Changing the Author Template

Now that we have some really cool custom values, let’s edit our template a little bit.  We’re going to change it to this:

<!-- This sets the $curauth variable -->

<?php
if(isset($_GET['author_name'])) :
$curauth = get_userdatabylogin($author_name);
else :
$curauth = get_userdata(intval($author));
endif;
?>
<div class="author_bio">
<h2><span><?php echo $curauth->first_name; ?> <?php echo $curauth->last_name; ?></span></h2>
<div class="floatLeft" style="margin-right: 10px"><?php echo get_avatar($curauth->ID, $size = '96'); ?></div>

<p><?php echo $curauth->user_description; ?></p>
<div class="clear"></div>
<h2 class="connectwith"><span>Connect with <?php echo $curauth->first_name; ?>:</span></h2>
<div class="clear"></div>

<ul>
<li><a class="linkedin" href="<?php echo $curauth->linkedin; ?>">linkedin profile</a></li>
<li><a class="facebook" href="<?php echo $curauth->facebook; ?>">facebook profile</a></li>
<li><a class="twitter" href="<?php echo $curauth->twitter; ?>">twitter profile</a></li>

</ul>
<div class="clear"></div>
<h2 class="postsby"><span>Posts by <?php echo $curauth->first_name; ?>:</span></h2>
</div>
<!-- The Loop -->

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="post">
<h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

<div class="entry">
<?php the_content('<p class="serif">Read the rest of this entry &raquo;</p>'); ?>
<div class="clear"></div>
<div class="tags"><?php the_tags( '<p>Tags: ', ', ', '</p>'); ?></div>

</div>

</div>

<?php endwhile; else: ?>
<p><?php _e('No posts by this author.'); ?></p>

<?php endif; ?>

Notice the changes we’ve made:

  • We’ve added the user’s first name and last name.  This will allow users to know exactly who the author is
  • We’ve added the gravatar by user ID and given it a right margin to prevent text-bumping
  • There’s a new section called “Connect With X” – it has an unordered list that contains the three fields we just created, echoed in a hyperlink to allow for automatic linking to profiles.

You can style this, or modify it, however you want, but this is a fairly simple technique to allow authors to have an automatically generated page with 1) their information, 2) their picture/avatar, and 3) their latest posts.

Things I Learned from #wcatl (and a Few I Learned on My Own)

Monday, January 11th, 2010

4260969659_2e4cd7ce99_b[1]

Photo by Adria Richards

Holly is driving and I’m on the way back home from WordCampAtlanta (well, from staying in Montgomery with her family for a while) and I’m finally getting a chance to reflect and collect my thoughts and what I learned.  WCATL was a fantastic event, and with over 400 people there the number of people I met, saw, and interacted with is too many to put into one post (also, thanks again to everyone who dropped by my presentation – it was a good crowd and I’m glad to hear that you got something out of it!)

But, I’m the first to admit I learn something every time I head to a conference, and this time was no exception. Here are a few of the high points I learned from WordCampAtlanta:

1. WordPress 3.0 is going to be Killer!

Jane Wells (@JaneForShort) gave a fantastic presentation on the future of WordPress, and the future is looking awesome. From the WPMU + WP Merger to a new theme for 3.0, lots of exciting things are in the works.  Her slides are below:

2. The PHP and WordPress communities can learn a lot from each other.

@technosailor gave a fantastic presentation (re: lecture in a discussion-y way) on how the core communities of both the PHP world and the WordPress world could stand to play nicer to each other.  Personally, I think that the problem comes from WP people starting out in WordPress and learning PHP (top down) instead of learning PHP then jumping into WordPress (bottom up). 

3. People will do just about anything for a copy of “Crush It”.

‘Nuff said.

4. The more I talk about WordPress at a conference, the more I realize I know nothing about WordPress.

Getting to meet giants like John Saddington (@Human3rror), talking to Jane Wells, and hearing Mark Jaqueth (@markjaqueth) made me realize that not only do I still have a lot to learn, but by not helping to make WordPress better I am hurting the platform more than I am helping it.  I submitted my first patch to the TRAC, but that’s only a small step in making WordPress even better than it already is.

5. The Atlanta WordPress scene is hopping!

There are a lot of people in Atlanta who are passionate about WordPress, and the community there is fantastic (how could 400 people otherwise justify getting out in the ice and show to come to the SCAD to hear about WordPress, yes?).  I was glad to meet a lot of you, and I hope we can keep in touch.

Better Know a WordPress Tag: ‘siteurl’

Thursday, September 24th, 2009

When you’re working on a development site it’s hard to set things up correctly because you know you’re going to change the site, and putting in elements that are more than likely “stationary”, such as links, will have to be changed, and that causes un-necessary headache when it comes time to move the site live.  But, in the light of wanting to make your lives easier as a developer, there is a WordPress tag that can make your life much easier: ‘bloginfo’.  the ‘bloginfo’ tag can be given various arguments to make it bend to your will.  But, one of the most useful I’ve found:

<?php bloginfo(‘siteurl’); ?>

Instead of putting links in with just a leading slash (/about/), adding <?php bloginfo(‘siteurl’); ?> will automatically append the full site url before the sub-pages. Since most developers have their dev sites as a subfolder of a current site, this allows you to skip adding the development folder before each and every URL.  It’s also good for adding links into hardcoded content, such as graphical navigation, or specially coded front-page templates.

Example code:

<a href=”<?php bloginfo(‘siteurl’); ?>”>home</a>

this link will lead you to the home page.

<a href=”<?php bloginfo(‘siteurl’); ?>/about/”>about</a>

this link (if you have custom permalinks) will take you to the about page, no matter what website or server it’s hosted on.

Latest WordPress Hack – Check your Permalinks, People!

Friday, September 4th, 2009

I’ll type this without the normal pleasantries to make sure this gets out quickly.

There’s a WordPress hacker on the loose, and he’s pretty sneaky – he creates a user unseeable to the naked eye (except for the one extra user in the administrator users menu) and masks himself to you, making it easy for him to sneak in and out of the site and do stuff (like change your permalinks) without you knowing.

If your permalinks have some funky stuff going on, like this:

/wordpress %&evalbase64_decode_SERVERHTTP_REFERER.+&%/

then you’ve been hacked. 

Head into your WordPress backend and click on “users” – there are ways to sort the users by their user role, so click on Administrator.  You’re going to compare the number of administrators to the number next to the administrator tab.

If the two match, you’re OK.

If you see 3 grid lines, but the tab says Administrator (4), then you’ve got a hacker in your database.

Click on “View Source” and search the page for “user-1”.  If you’re the only administrator, you’re looking for this code:

<div id=”user_superuser”>

This person is the hacker, and there’s a way to find him and delete him.

Your administrator account is user-1, so find a user around that code that’s not that one and nearby you’ll find a code:

user-edit.php?user_id=NNN

NNN is the user-id.  I know these are vague, but without another account to screenshot, it’s hard to explain.

Replace the URL (http://youriste.com/wp-admin/whatever with http://youriste.com/wp-admin/user-edit.php?user_id=NNN and hit enter.

Enter a fake email address for the spammer, demote him to “Subscriber” and change his password.

Once that’s done, view all users and delete him.

And that’s how to get rid of him.

Better instructions are here:

http://blog.nachotech.com/?p=125