
P2 is one of the sweetest wordpress themes out there (see http://ma.tt/2009/05/how-p2-changed-automattic/), but for certain applications it needs tweaking. At MyChances.net, we wanted to give each of our members their own blog so they could write about the college application process. To accomplish this, we needed two additional features: 1) Threaded comments for author pages. If members are going to feel like they have a legit blog, they need to have user comments on the articles they are writing. 2.) If the logged in user is the author of the blog, that user should see the “Hi, watcha up to?” quick post box on their blog – NOT just on the main page (aka the “firehose” – thanks Twitter!).
Adding comments to author pages in the P2 wordpress theme is an easy process. You just need a few minutes and a very small amount of programming knowledge.
Step 1: Open up wp-content > themes > P2 > entry.php.
Step 2: find the following line: if ( ( is_home() || is_front_page() )) $withcomments = true;
Step 3: change the line to if ( ( is_home() || is_front_page() || is_author() ) ) $withcomments = true;
Step 4: Save entry.php, and make sure that you upload it to your P2 directory.
Step 5: Profit.
If you need comments on the tags page, you can simply change the line to this:
if ( ( is_home() || is_front_page() || is_author() || is_tag() ) ) $withcomments = true;
Essentially you are adding in some logic so that if the page the user is looking at “is an author page” OR “is a tag page” then turn on the withcomments variable so the page is allowed to show the threaded comments feature which we all love.
You can see this functionality live here:
http://www.mychances.net/membership/blog/author/Brent/
and here:
http://www.mychances.net/membership/blog/tag/member-blogs/
Now for our second need, showing the quick post box on author’s own author page (if the logged in user is the author).
Step 1: Open up wp-content > themes > P2 > author.php.
Step 2: At the very top of the page, add this line in the php brackets like so:
<?
get_currentuserinfo();
?>
This allows you to access information about the current user, such as their username. To let php see the username, you can access the data like this:
$current_user->user_login (So if you want to echo out the username of the logged in user, you can put <?=$current_user->user_login?>
Step 3: Just below the line that has <div class=”sleeve_main” id=”userpage”> insert this block of code:
<?
if( current_user_can( ‘publish_posts’ ) && $current_user->user_login==$author->user_nicename) require_once dirname( __FILE__ ) . ‘/post-form.php’;
?>
This checks two things. 1) Can the current user even post things. 2) If the current username is equal to that of the author. If these criteria are met, it will display the “post form” which is the quick post box. Otherwise, nothing shows up, so it just looks like a blog page for a normal visitor.
That’s it! Please let me know if you have implementation questions.
Brent