Making a member list blog directory

Posted by Andrea under how to

Sorry for the convoluted title, it’s more for search engines. I’ve found there’s quite a few different ways people phrase what they want, but here’s how to do it. Ultimately, you will wind up with a separate page off the main blog with a list of all your public member blogs.

You will need:
- a copy of the list_all plugin
- a copy of the page.php file from your main admin blog’s template

Place the list_all plugin in your mu-plugins folder if you have not already done so. Some things to remember are that this plugin does not have an admin menu, so you won’t see any changes on the back end. You’ll have to call it directly to use it, which is good as you don’t want your members making lists too.

Save a copy of your theme’s page.php file to your desktop or working folder on your computer, somewhere that you can find it later. Open it up in your favorite text editor. If I have to work on windows, I like to use jEdit or Notepad++ because the default notepad sometimes screws things up. On Linux, I happen to love gPHPedit because of the code highlighting and the instant visuals if I happen to accidentally delete closing tags.

Allrighty, with the page.php template open in front of you, you should see something like this:

<?php get_header(); ?>

<div id=”content” class=”narrowcolumn”>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class=”post” id=”post-<?php the_ID(); ?>”>
<h2><?php the_title(); ?></h2>
<div class=”entry”>
<?php the_content(’<p class=”serif”>Read the rest of this page »</p>’); ?>

<?php wp_link_pages(array(’before’ => ‘<p><strong>Pages:</strong> ‘, ‘after’ => ‘</p>’, ‘next_or_number’ => ‘number’)); ?>

</div>
</div>
<?php endwhile; endif; ?>
<?php edit_post_link(’Edit this entry.’, ‘<p>’, ‘</p>’); ?>
</div>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

The first thing we are going to do is add some comments at the top, so the system will know it is a new page template and what to call it. Add this at the top of the file:

<?php
/*
Template Name: Member Listing
*/
?>

You don’t have to call it Member Listing, you can call it whatever you like. If you read further down in the template, there is a div next, then the Loop. That’s the code that pulls in the actual content of the page. In this case, we don’t want it. Delete everything from <?php if (have_posts to <?php edit_post_link(’Edit this entry.’, ‘<p>’, ‘</p>’); ?>. Your page template should look pretty empty.

Now here comes the good stuff; insert the code from the list_all plugin to generate our list of member blogs. This plugin has a few options that you can play with too, but for now you’ll tell it to pull a full listing of blogs in alphabetical order. The function for that is this:

<?php list_all_wpmu_blogs(’500′, ‘name’, ”, ‘<br />’, ‘blog_name’); ?>

Paste that between the opening and closing content div tags, replacing the Loop that you just removed. It should look something like this:

<?php
/*
Template Name: Member Listing
*/
?>
<?php get_header(); ?>

<div id=”content” class=”narrowcolumn”>
<?php list_all_wpmu_blogs(’500′, ‘name’, ”, ‘<br />’, ‘blog_name’); ?>
</div>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

The paramaters passed are the detail in brackets to tell it to show 500 blogs, displayed by name, no HTML in front and a carriage return after each, sorted by name. Please note that this plugin will not display blogs that are listed as private. They have to be set to public to show up.

Now, save your template as a new file, called something like members.php or even listing.php, as long as it doesn’t interfere with other template files. Upload this new template file to your mu site to your main blog’s theme folder; ie - wp-content/themes/yourmainblogtheme/

Login to MU at the main blog and go to Write Page. Choose a title for your new page, such as “Member Listing”. Don’t write any text in the post area, as we’ve taken out the code to make it show up. Here’s the important bit though: down the right side, there should now be a blue bar there that says “Page template”. Expand it and have a look at the drop-down box. There should be a list that says “default template” and right under it the name of the new page template we just created; in this case it says “members” or whatever you saved the file as. Select this template and publish the page.

If you’ve chosen a particularly nice theme, there will likely be a navigation bar that automatically pulls in page names for menu items. You’ll find your new page there.

Last but not least, make sure your main blog theme is not accessable to your users by following the instructions here.

Based on instruction from Creating your own page templates from the Wordpress Codex. If you just scrape the code from this page and copy and paste it, the formatting will be off. So type it in. :)

Don’t forget to leave me a comment and show off your new page-making skills. You can see mine here.

6 Responses to “Making a member list blog directory”

  1. Dr. Mike Wendell Says:

    The problem with that, and I notice it when I try to pull up your example, is that the data is not cached in any way. It’s a fresh copy every single time which is going to cause processor strain and long delays. Took about 90 seconds for your example page to come up.

    A better idea, no offense Andrea, would be create the output once an hour or so via a cron job and either dump it into a static page or into a database as a single record and use that.

  2. Andrea Says:

    Good tip though. :) Maybe I’ll write up that next. :D

    Actually, that highlights issues the new MU site owner might never think of until the first server crash.

  3. Dr. Mike Wendell Says:

    Another way to do it is like how mu generates the blog count as it only gets updated once an hour. Take a look within wp-includes/wpmu-functions.php for the get_sitestats() function. It saves the data as a site option but will only update it once an hour. That may be another solution/ option here. Save the list as a site option and, if it’s been less than an hour, just grab it out of the site option table. If it’s been more than an hour, recreate the list.

  4. Linux-Benutzung » Re: Auf dem Desktop-Markt hat Linux nichts zu suchen ! Die Linux-Lemminge … - Konsortium will Linux auf die Desktops b… Says:

    […] es kein einziger professioneller > > > > Designer. Viel Spaß mit dem Schrott. > > > und was ist an macromedia so professionell? ich kenne viele, die das > > > Plugin nicht installiert haben und die supertollen […]

  5. brandon Says:

    how can i do this with the authors avatar showing up?

  6. Improved Search Engine Placement Using Unique Internet Business Training Program Says:

    Improved Search Engine Placement Using Unique Internet Business Training Program…

    It\’s been really long since I started reading your posts and today I just want to say that your blog is great!…

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-Spam Image



google.load("language", "1"); var curstate = 0; var hasloaded = 0; function bnc_show_translated() { if (hasloaded == 0) { bnc_lang_callback(); hasloaded = 1; } for (i = 0; i < 6; i++) { var elem = $("bnc_original_" + i); if (elem) { if (curstate) { elem.show(); } else { elem.hide(); } } } for (i = 0; i < 6; i++) { var elem = $("bnc_trans_" + i); if (elem) { if (curstate) { elem.hide(); } else { elem.show(); } } } if (curstate) { $("bnc_trans_state1").show(); $("bnc_trans_state2").hide(); curstate = 0; } else { $("bnc_trans_state1").hide(); $("bnc_trans_state2").show(); curstate = 1; } } function bnc_detect_div(div_id) { var text = document.getElementById(div_id); if (text) { text = text.innerHTML; if (text.length > 0) { google.language.detect(text, function(result) { if (!result.error) { if (result.language != "en") { if (result.confidence > 0.25) { $("bnc_translating").show(); bnc_xlate_div(result.language, div_id, "en"); } } } } ); } } } function bnc_xlate_div(src_lang,div_id,o_lang) { var text = document.getElementById(div_id); if (text) { text = text.innerHTML; google.language.translate(text, src_lang, o_lang, function(result) { var translated = document.getElementById(div_id); if (result.translation) { translated.innerHTML = result.translation; } }); } } function bnc_lang_callback() { bnc_xlate_div("en", "bnc_lang_i_0_64", "en"); bnc_xlate_div("en", "bnc_lang_i_1_64", "en"); bnc_xlate_div("en", "bnc_lang_i_2_64", "en"); bnc_xlate_div("en", "bnc_lang_i_3_64", "en"); bnc_xlate_div("en", "bnc_lang_i_4_64", "en"); bnc_xlate_div("en", "bnc_lang_i_5_64", "en"); bnc_xlate_div("en", "bnc_lang_i_6_64", "en"); bnc_xlate_div("en", "bnc_lang_i_7_64", "en"); bnc_xlate_div("en", "bnc_lang_i_8_64", "en"); bnc_xlate_div("en", "bnc_lang_i_9_64", "en"); bnc_xlate_div("en", "bnc_lang_i_10_64", "en"); } function bnc_startup() { bnc_xlate_div("en", "bnc_translate_info", "en"); bnc_xlate_div("en", "bnc_translate_info2", "en"); bnc_detect_div("bnc_lang_i_0_64");bnc_detect_div("bnc_lang_i_1_64");bnc_detect_div("bnc_lang_i_2_64");bnc_detect_div("bnc_lang_i_3_64");bnc_detect_div("bnc_lang_i_4_64");bnc_detect_div("bnc_lang_i_5_64");bnc_detect_div("bnc_lang_i_6_64");bnc_detect_div("bnc_lang_i_7_64");bnc_detect_div("bnc_lang_i_8_64");bnc_detect_div("bnc_lang_i_9_64");bnc_detect_div("bnc_lang_i_10_64"); } google.setOnLoadCallback(bnc_startup);
Close
E-mail It