Filter Content by Author, for WP 1.2+

Here is my updated hack to allow you to filter the front page of your blog by author if you have more than one as I do:

<?php
function author_list() {
global $tableusers;
$query = ("SELECT ID, user_nickname from $tableusers ORDER BY user_nickname");
while ($data = mysql_fetch_row($result)) {
echo "<a href="".$blog_file."?author=$data[0]">$data[1]</a> ::<br />n";
} ?>

Place this in your my-hacks.php file and then place the function call <? author_list() ?> in the page where you would like to have this list displayed and that is it.  If you would like to have a text file of this to download, you can find it here (if you are using Safari, you won’t see the code, just save the file).  And remember this code is realeased under the same license that is in use on this site, so use it accordingly.

  1. personal avatar clkung
    Stroll on over and visit clkung
    March 1, 2007

    Can you advise how to use if I only need one author ID #1 to be selected ?

  2. personal avatar Chris J. Davis
    Stroll on over and visit Chris J. Davis
    March 1, 2007

    Well if I am understanding you correctly, you only want posts from ID #1 to show up even though you have multiple authors?

    Well then in index.php find this:<?php
    require('./wp-blog-header.php');
    ?>
    add $author="1"; to it so that you have this:<?php
    $author="1";
    require('./wp-blog-header.php');
    ?>

    This will restrict the index page to only posts from the author whose ID = 1.

    Hope that helps.

  3. personal avatar Matt
    Stroll on over and visit Matt
    March 1, 2007

    A few thoughts:

    Found on the wordpress Wiki @ wiki.wordpress.org/index.php/Filter content by Author

  4. personal avatar Anonymous
    Stroll on over and visit Anonymous
    March 1, 2007

    Your site has made me smile :-)

  5. personal avatar Anonymous
    Stroll on over and visit Anonymous
    March 1, 2007

    I love everything about this site!!

  6. personal avatar Yasir
    Stroll on over and visit Yasir
    March 1, 2007

    I think your tutorial on using Wordpress as a CMS parts 1 and 2 are great! I followed the steps and even being a beginner in creating a Wordpress blog (I just started two days ago), I got it up and running!

    BUT

    The last step reguarding adding the code in .htaccess… I was having great problems in. The snippet of code you told to place into the .htaccess file:

    Options MultiViews

    for some reason doesnt work… I’m sure I’m making a simple dumb mistake but I just cant seem to figure it out? i went into my hosting provider account and found out that my directory for the .htaccess is:

    /www/y/yasirhossain/htdocs/.htaccess

    so i was thinking maybe you meant to change “sitename” to that path… but that didnt work either?

    Any help on this would be greatly appreciated! Thanks for the great tutorial, I can’t wait to get the url masking to work! And congrats on your new addition!

Leave a Reply