|
|
Want to know more about Packt's Article Network? Interested in contributing your article ideas? Please visit our FAQ for more information. See More BROWSE
All Titles WordPress Web Services SOA BPEL Web Graphics & Video Web Development RAW Portugues, Espanol, Italiano, French PHP/MySQL Oracle Open Source Networking & Telephony Moodle Microsoft & .NET Linux Servers jQuery Joomla! JBoss Java e-Learning e-Commerce Dynamics Drupal CRM Cookbook Content Management Beginner Guides Architecture and Analysis AJAX Future Titles Recently Published Titles In this two-part article by Jean Baptiste-Jung, we shall learn about managing and enhancing a multi-author blog. Are you running a multi-author blog, or at least hiring some guest bloggers? Indeed, the more authors you have, the more content you will have, along with a greater number of visits. In the beginning of 2009, many successful blogs such as, Smashing Magazine, Lifehacker, or Mashable, were powered by a team of bloggers. In this article, we are going to learn how to create, enhance, and get the most out of your multi-author WordPress blog. In this part, you will learn:
See More |
Managing and Enhancing Multi-Author Blogs with WordPress 2.7(Part 2)
Displaying author picture on postsDid you like the previous recipe in the first part? I hope you did! But personally, I must admit that even though displaying author information looks very cool, something is missing from the previous recipe. Can you guess what is it? It is a picture of the author, of course. Even if your author-related information is precise and complete, a picture is still essential. This is because it is the easiest, and quickest, way for a reader to recognize an author. But sadly, WordPress can't handle author pictures by default. Let's learn how to create a hack that will allow us to display the author's picture in the way that we want to. Getting readyAs we'll be using author pictures in this recipe, you should start by requesting a picture of all of your authors. Although it isn't necessary, it will be really better if all of the pictures have the same width and height. A square of 80 to 110 pixels is a good standard. Also, make sure that all of your pictures have the same format, such as .jpg, .png, or .gif. How to do itNow that you have collected pictures of all of your authors, we can start to hack WordPress and insert author pictures in the posts
How it worksThe working of this code is pretty simple. You simply concatenated the result of the the_author_ID() function with the theme URL to build an absolute URL to the image. As the images are named with the author ID (for example, 1.jpg, 4.jpg, 17.jpg, and so on), the the_author_ID() function gives us the name of the picture to be displayed. You just have to add the .jpg extension. There's more...Now that you've learnt how to display the picture of the current author, you should definitely use this recipe to enhance the previous recipe. The following code will retrieve the author information, and display the author picture as we have learnt earlier: <div id="author-info"> The outcome of the preceding piece of code will look similar to the following screenshot:
Displaying the author's gravatar picture on postsGravatars (which stands for Globally recognized avatars) is a popular service, that allows you to associate an avatar image to your email address. On October 18, 2007, Automattic (The company behind WordPress) acquired Gravatar. Since WordPress 2.5 the popular blogging engine is fully gravatar-compatible, which results, in the ability to include gravatars in comments. In this recipe, I'll show you how to modify the previous code to use the author gravatar instead of a personal picture. Getting readyAs we're going to use Gravatars, you (and each of your authors) first need a gravatar account. Carry out the following steps to create a gravatar account and associate an image to your email address.
How to do itOpen the file single.php from the theme you're using and paste the following code: $md5 = md5(get_the_author_email()); How it worksThe first thing to do is to get an md5 sum from the author's email address. To do so, I used the php md5() function along with the get_the_author_email() function. I didn't use the_author_email() because this function directly prints the result without allowing you to manipulate it with php I then encoded the URL of a default picture that is to be shown if the author hasn't signed up to Gravatar yet. Once done, the gravatar can be displayed. To do so, visit the web site: http://www.gravatar.com/avatar.php with the following parameters:
Adding moderation buttons to the commentsA common problem with comments is spam. Sure, you can moderate comments and use the Akismet plugin. However, sometimes someone leaves a normal comment, you approve it, and then the spammer—who knows that his comments aren't being accepted by the moderator—starts to spam your blog. Even though you can do nothing against this (except moderating all of the comments), a good idea is to either add spam and delete buttons to all of the comments. This way, if you see a comment saying spam while reading your blog, then you can edit it, delete it, or mark it as spam. I got this useful tip from Joost de Valk, who blogs at www.yoast.com Getting readyThe following screenshot shows normal comments without the edit, delete and spam buttons:
There's nothing complicated at all with this recipe. However, you must be sure to know which kind of blog the users are allowed to edit or delete your comments. For a list of actions and user roles, see the section named Controlling what users can do, which is later in this article. How to do it
How it worksIn this recipe we started by creating a function. This function first verifies whether the current user has the right to edit posts. If yes, then the admin URLs to mark the comment as spam or delete it are created and displayed. In the file comments.php, we have used the edit_comment_link(), which is a built-in WordPress function. Some themes include this by default. We then used the comment ID as a parameter to the delete_comment_link() function that you had created earlier. WordPress 2.7 Cookbook
Getting notified when a new draft is savedAs a blog administrator, you have to know what your authors and contributors are working on. Sure you can ask them, but it can become a boring task quickly if you have many different contributors. Getting readyThe solution to the stated problem is a plugin called Draft Notification. When someone creates a new draft on your blog, you'll automatically receive an email. How to do it
How it worksOnce installed, the Draft Notification plugin starts to look up when a draft is saved. When it does, the plugin automatically sends an email to the blog admin. Allowing multiple authors on postsIn a multi-author blog, sometimes an author starts a post and another one finishes it. Or, perhaps, two (or more) contributors share their ideas and create a great article together. Unfortunately, by default, WordPress allows only one author per post. Although this is good for most blogs, it can quickly become very frustrating for contributors on a multi-author blog. Just imagine that two authors have worked together to write a post, but only one can be rewarded. In my opinion, that's not a very comfortable situation for either of them. Getting readyLuckily, a very cool WordPress plugin allows your blog to assign more than one author to a post. The plugin is simply named Co-Authors and was created by Weston Ruter.
How to do it
How it worksWhen installed, the Co-Authors plugins creates news tags to return multiple authors. If only one author wrote the post, only his name is displayed. In the preceding piece of code, we check if the coauthors() function exists. If yes, then we use it to display co-authors. If the function doesn't exist (which means that the plugin isn't installed) we use the built-in the_author() function instead. Displaying a list of all of the authorsIn my opinion, in a multi-author blog it is a good thing to display a list of all of the authors, such as in your About page. In this recipe, I'm going to show you how to easily display the list of your authors and control its display. Getting readyTo achieve this recipe and enhance your About page, you should definitely create a page template. This is not mandatory, though. How to do itEdit the desired file and insert the following line of code to where you want your list of authors to be displayed: <?php wp_list_authors(); ?> Save the file, publish the page, and visit your blog. You will notice that all of your authors are now listed. How it worksTo display the list of your blog authors, you only need the wp_list_authors() function. This function can be inserted anywhere into your theme files. Once called, wp_list_authors() executes a database query to get the list of authors. The function can be controlled with parameters. There's more...Now that we have learned how to display the list of authors, let's learn how to the function used to display the list of authors. Controlling the wp_list_authors() functionThe wp_list_authors() function can be controlled with a few parameters:
The following line of code will list the author's full names along with the number of posts that they have published: <?php wp_list_authors('show_fullname=1&optioncount=1'); ?>The following code will not exclude the admin, as well as the authors who haven't published any post yet: <?php wp_list_authors('exclude_admin=0&hide_empty=0'); ?>SummaryIn this article, we have learned how to glorify a multi-author blog. We have also learned:
If you have read this article you may be interested to view :
WordPress 2.7 Cookbook
About the AuthorJean-Baptiste Jung is a Web developer, Web designer, and blogger born in Paris, France and now living in Wallonia (French-speaking part of Belgium) with his wife and cat. Jean unearthed the World Wide Web in 1998 and started creating web sites three years later. In 2006, while working as a freelance Web developer for a well known French TV channel, Jean started to work with blogs and WordPress. A few months later, he created his first blog. He became immensely passionate about WordPress and launched a blog dedicated to WordPress hacks, http://www.wprecipes.com, which quickly managed to become one of the most popular WP-related web sites over the Internet. Meanwhile, Jean is also an author on some prestigious blogs, such as WpHacks, ProBlogDesign, and Smashing Magazine. Books from Packt
|
In this two-part article by Jean-Baptiste Jung, we will see what can be done for enhancing user experience and making your WordPress blog a better place. In this part, you will learn:
See More |
| ||||||||