Home » Posts tagged 'wordpress'
Tag Archives: wordpress
This is a little (hell, VERY) technical–but it might be useful to some, and it seems like my most technical posts get the most attention somehow! 🙂
When running a WordPress site with multiple authors (a class site is a perfect example), sometimes you want to see all the posts by one author gathered together. WordPress makes this quite easy–you can just go to www.name-of-site/author/authors-username . Or there is even a sidebar widget to automatically list all the authors names, linked to those pages with all their posts.
But we’ve found that many times, on a class site, a professor (or maybe even visitors to the site like other students) will want to easily review everything that a given student has done. In other words, they want an author archive page that includes all the posts by that author, and also all the comments that that author has left on posts written by others
This was surprisingly difficult to find a way to accomplish. There are a couple of plugins that do something like this–but not exactly–and I couldn’t even get the best candidate among them to work at all.
So I decided to get my hands dirty. When WordPress displays that author’s page, it looks (first) for a file called author.php . And you can (in a child theme or editing a theme or creating a theme) customize that file to display what you want.
I made a child theme of the Twentyeleven default theme, and put a new author.php file in that child. The code is already there in the existing author.php to queue the first post, identifying the author, and then run the loop to pull all posts by that author.
I added a small piece of code–of course this has to be enclosed in the usual <?php and ?>
$comment_author = get_the_author_id()
That just pulls the author_id that we’re going to need in the next bit of code to find all the comments by that author.
Then the next bit of code, which took me far too long to figure out how to write, grabs all the comments by that author, and displays them one by one, with each one including a line about when it is was posted, and what post (with a link) it was commenting on. This could all be customized–and yes, this also needs to be enclosed in <?php and ?>
$comments = get_comments(array(user_id=>$comment_author));
foreach($comments as $comment) :
$url = ‘<a href=”‘ . get_permalink($comment->comment_post_ID) . ‘”>’ . get_the_title($comment->comment_post_ID) . ‘</a>’;
echo (‘”‘ . $comment->comment_content . ‘” <br> –( posted on ‘ . get_comment_date(‘M j, Y’) . ‘, commenting on the post ‘ . $url . ‘ )<br /> <br>’);
If you try copying and pasting that code, do be careful about the single and double quotes. I’m not going to bother fixing them all, but they do need to be plain, not curly or “smart” single and double quotation marks. The code is fussy that way!
That’s about it. I also changed the template a bit so that the posts would not be displayed in their entirety, but just as titles linking to the full posts. And I turned off pagination for this page.
An example of it in action, which may not last, since it’s a demo site I use for lots of things, is here.
Hope this is useful for anyone who comes across it!
Coming this Saturday, and it should be a great day. Many CUNY colleagues presenting and (I hope) attending, too. I’ll be on the roundtable on the future of WordPress in Education, and presenting my own eportfolio spiel:
Eportfolios are (too often) seen as tools for assessment, for assignments, or for career placement. But thanks to WordPress and BuddyPress, at Macaulay Honors College, we’ve been able to set up an entirely flexible and free tool, allowing students (and faculty, and instructional technology fellows) to redefine the term “Eportfolio” and to let them each create a “Cabinet of Curiosities” or a “Museum of Me,” which promotes reflection, interaction, and truly integrative learning. These eportfolios are student-driven and student-designed, and the flexibility of WordPress allows us to watch as students forge new paths, and create an eportfolio model which is new in higher education, and which has the potential to work for students beyond the classroom, beyond the college.