Creating a static copy of a custom menu
-
Hi everyone,
I began this discussion in the wrong subforum (here). It’s a more general question than I realized, and the solution seems simpler and possibly of interest to many people.
Like many people, I’m interested in integrating a menu generated by wordpress into a non-wordpress site. In my case, the awkward dance partner is OpenCart, but people do this for Magento, etc.
After playing around with a direct query of the WordPress database (which seems inefficient for a menu, and causes quite a few conflicts with OpenCart), it struck me that the best solution was to create a static copy of the navigation menu as a temporary file, and to access the temporary file with a simple include_once from my OpenCart template. Here’s a test version that I wrote:
// no theme output define('WP_USE_THEMES', false); require_once('wp-load.php'); //define temporary file for static output $file="static/nav.tmp"; //use buffering to capture HTML ob_start(); //Wordpress template file with only the HTML I want require_once('wp-content/themes/twenty-twelve-child/opencartheader.php'); //Save buffer to variable $output = ob_get_contents(); //End buffering ob_end_clean(); //Save stored buffer to temp file file_put_contents($file, $output);
Simple, once I realized this was actually what I needed.
Now I’d like to create a plugin that will do this automatically whenever a custom menu is saved. I’ve downloaded a few caching plugins, and am reading the code for inspiration, but this seems as though it should also be easy. Unfortunately, my Google skills don’t seem up to finding out how.
Could someone steer me in the right direction?
Thanks,
Brit
- The topic ‘Creating a static copy of a custom menu’ is closed to new replies.