Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am working on a wp site where I need to manage 500s of child pages for a single page such as About menu can have more child pages need to manage those child pages as sub menu and I have more than 5 such menus.

My client is saying that it will cause load to the server. Does this create a problem in server? If yes, is there any way to load the menu that will not cause any problem to the server.

Thanks in advance...

share|improve this question
    
You may want to consider accepting answers on many of your questions if you have found solutions for them, if there are no answers suitable feel free to add your own if you've solved it yourself. :) –  Jared Dec 4 '12 at 6:34
    
Sure, I will do that –  user478 Dec 4 '12 at 6:56

2 Answers 2

up vote 1 down vote accepted

In general it should not be a big problem. The built of the menu could be slow, so your best option here is to cache the menus with transient.

if ( !get_transient( 'first_menu_transient' ) ) {

    ob_start(); // do not directly output the menu

    // build the menu
    $first_menu = ob_get_contents();
    ob_end_clean();
    echo $first_menu;
    set_transient( 'first_menu_transient', $first_menu );

} else {

    echo get_transient( 'first_menu_transient' );

}

In this way you reduce the databasequeries to a minimum, compared to building the whole menu each time.

To avoid having the wrong menu after changing and saving the menu, delete the transient on the wp_update_nav_menu action.

add_action('wp_update_nav_menu', 'my_delete_menu_transients');

function my_delete_menu_transients($nav_menu_selected_id) {

    delete_transient( 'first_menu_transient' ); // you should also just delete the transient of the updated menu, but you get my point - you would have to write the function for linking the menu-IDs to your transient names. For example, just put the ID of the menu in the transient name.

}

Everything clear so far?

share|improve this answer
    
Thank you @fischi. I will try this. –  user478 Dec 4 '12 at 6:56
    
@fischi.. thanks a lot it worked –  user478 Dec 24 '12 at 9:22
    
You're welcome. Merry Christmas :-) –  fischi Dec 24 '12 at 9:56
    
Thanks.... Merry Christmas and happy new year!! –  user478 Dec 24 '12 at 10:39

Yes, it will create high load for the basic WordPress installation. To be able to have a functioning site you will have to employ caching. If the site is static in nature then using caching plugins like super-cache or w3tc can be enough, but if you can't use any of them because the site is very dynamic you will have to cache the menu in your code and do something like

In your theme's functions.php file add

add_action('save_post','regenrate_menu_cache'); // regenerate the cache when a new page might have been added
add_action('delete_post','regenrate_menu_cache'); // regenerate the cache when a page might have been deleted

function regenrate_menu_cache() {
  $menu = wp_nav_menu(array("echo" => false,"menu" => "my_menu")); // get the HTML that is generated for the menu
  update_option('my_menu_cache',$menu); // and store it in the DB as an option
}

in your theme's header.php file replace the menu generation code with

echo get_option('my_menu_cache');

The drawback with this code is that each time a post/page/attachment etc is saved you recalculate the menu which might make saving slower, so you might want the recalculation to be limited to only when a page on menu is changed.

Side note: With so many pages in hierarchy the pages admin might become slow.

share|improve this answer
    
As you said, if you have a much updated site, it will slow it down really bad, and may become unusable for editing content. –  fischi Dec 4 '12 at 7:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.