我在一个wp网站上工作,在那里我需要为一个页面管理500个子页面,例如“关于”菜单可以有更多子页面需要作为子菜单管理这些子页面,我有5个以上这样的菜单。
我的客户说这会导致服务器加载。这是否会在服务器中造成问题?如果是,是否有任何加载菜单的方法不会对服务器造成任何问题。
提前感谢。。。
我在一个wp网站上工作,在那里我需要为一个页面管理500个子页面,例如“关于”菜单可以有更多子页面需要作为子菜单管理这些子页面,我有5个以上这样的菜单。
我的客户说这会导致服务器加载。这是否会在服务器中造成问题?如果是,是否有任何加载菜单的方法不会对服务器造成任何问题。
提前感谢。。。
总的来说,这应该不是什么大问题。菜单的构建速度可能很慢,因此您最好的选择是使用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\' );
}
通过这种方式,与每次构建整个菜单相比,您可以将数据库查询减少到最小。为避免更改和保存菜单后出现错误的菜单,请删除wp_update_nav_menu
行动
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.
}
目前一切都清楚了吗?是的,它将为基本WordPress安装创建高负载。为了能够有一个正常运行的站点,您必须使用缓存。如果站点本质上是静态的,那么使用缓存插件super-cache 或w3tc 这就足够了,但是如果你不能使用其中的任何一个,因为网站是非常动态的,你将不得不在你的代码中缓存菜单,并执行如下操作
在主题的功能中。php文件添加
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
}
在主题的标题中。php文件将菜单生成代码替换为echo get_option(\'my_menu_cache\');
此代码的缺点是,每次保存帖子/页面/附件等时,您都会重新计算菜单,这可能会降低保存速度,因此您可能希望重新计算仅限于更改菜单上的页面时。旁注:由于层次结构中的页面太多,页面管理可能会变得很慢。
我们希望为作者使用插件或自定义设置来创建页面或帖子,并将其发布为单个HTML文件。该文件可以保存在服务器上的特定目录中,或者在编辑器中有一个下载按钮。到目前为止,我们已经找到了2个几乎可以实现此功能的插件:WP Static OutputReally Static两者的工作方式非常相似,但需要管理员访问才能生成。它们还以以下方式创建文件:服务器上的目录/页面标题/索引。html我需要的地方服务器上的目录/页面标题/页面标题。html对此有何想法?有人做过类似的事情吗?提前谢谢。