The MU forums have moved to WordPress.org

Want a single menu for a website (5 posts)

  1. TonyVitabile
    Member
    Posted 14 years ago #

    I've got my primary blog working, and it's got all the pages I want, organized as I want. I've got a drop down menu that's working with all of those pages, and I'm happy with it.

    I've got a need for creating several (2 or 3) sub blogs that need to look like they're part of the main blog. Basically, the site is for a church and we want to publish our sermons as video & audio files, hosted on our server. I figure the best way to do this would be to make a secondary blog at http://church.org/worship/sermons, where /worship/ is where WPMU is installed. Then users can subscribe to an RSS feed of sermon media.

    However, I want the sermon blog to appear as though it were a part of the main blog, in that the menu will be identical. The rest of the pages are using the same theme so that's good. It's just that wp_list_pages() in the second blog is returning the list of pages created for the second blog.

    I can think of one way to make this work off the top of my head, and that's to modify the header.php for the theme so the menu is hard coded in it. But that means that if I ever want to change the menu (as in add a page, remove a page, or move a page from one menu to another), I have to do it in the header.php or menu.php that header.php uses. Yeah, this works, but I've got the User Access Manager plugin running, which means that certain pages aren't supposed to be visible to certain users.

    I've been peeking at the code in wpdb.php and wpsettings.php and I think I have another way:

    I. I create a plug-in with a single admin page where the user specifies the primary blog (the one that has the menu that is supposed to be on all of the pages) and the sub-blogs that it is supposed to affect.

    II. I create a function (tag?) in the plugin that performs the following actions:
    1. Retrieves the value of the $wpdb->blog_id parameter from $wpdb

    2. If the value of $wpdb->blog_id is in the list of blogs to be affected:
    a. It puts the value of $wpdb->blog_id in a static variable
    b. It changes the value of $wpdb->blog_id to the primary blog by calling $wpdb->set_blog_id().

    III. I create another function (tag?) in the plug in that resets the $wpdb->blog_id back to the original blog_id.

    IV. I modify my theme header so it calls the first function (tag?) before it calls wp_list_pages(), then calls the second function (tag?) after it calls wp_list_pages().

    Do any of you who know more about the inner workings of WordPress MU than I do see any issues or concerns with doing it this way? The advantages for me are that all my plug-ins that filter wp_list_pages() get called properly so pages that are supposed to be hidden remain hidden, and I get my common menu without having to effectively maintain it twice.

    Thank for the feedback.

    Tony

  2. andrea_r
    Moderator
    Posted 14 years ago #

    just before the nav bar code put

    <?php switch_to_blog(1); ?>

    right after the navbar code put

    <?php restore_current_blog(); ?>

    then it will always show the pages from Blog #1.

  3. TonyVitabile
    Member
    Posted 14 years ago #

    Thank you! You just saved me a couple of days of development! Had no idea those functions were there!

    Thanks again!

    Tony

  4. andrea_r
    Moderator
    Posted 14 years ago #

    I keep these things in a handy text file. :)

  5. milanmk
    Member
    Posted 14 years ago #

    @andrea_r

    Thank you so much for recollecting those magic functions.

About this Topic

  • Started 14 years ago by TonyVitabile
  • Latest reply from milanmk