Page 1 of 1
Feed CMSMS menu through to Wordpress [SOLVED]
Posted: Thu Feb 20, 2014 9:33 am
by JM6891
I'm not sure if this is possible or if there is a module to achieve what we need here, but is it possible to feed a navigation menu from CMSMS to a Wordpress template?
A client of ours has a CMSMS site and a Wordpress blog. They both have the same theme, but menu on the Wordpress blog is static (it reflects the CMSMS menu but is updated via the template manually).
This hasn't been an issue up until now as the page names didn't change frequently, but I'm just wondering if it is possible to make this a bit more userfriendly so that the wordpress templates don't have to be updated manually?
Re: Feed CMSMS menu through to Wordpress
Posted: Thu Feb 20, 2014 10:31 am
by Rolf
This is why I made
http://dev.cmsmadesimple.org/projects/cacheremotefile
I use it for several sites, in example the menu of the docs site is taken from the main cmsms site.
Re: Feed CMSMS menu through to Wordpress
Posted: Thu Feb 20, 2014 11:06 am
by JM6891
Thank you very much Rolf. I shall take a look at that module.
Re: Feed CMSMS menu through to Wordpress
Posted: Thu Feb 20, 2014 12:01 pm
by Rolf
JM6891 wrote:Thank you very much Rolf. I shall take a look at that module.
It is a tag/plugin

Re: Feed CMSMS menu through to Wordpress
Posted: Thu Feb 20, 2014 3:11 pm
by JM6891
Hi Rolf, did you say there was an example somewhere?
Thanks
Re: Feed CMSMS menu through to Wordpress
Posted: Thu Feb 20, 2014 3:13 pm
by JM6891
Don't worry I've found the help text in the php file!
Re: Feed CMSMS menu through to Wordpress
Posted: Thu Feb 20, 2014 3:39 pm
by JM6891
Hi Rolf,
I have installed the tag and created the necessary blank template and hidden page. I can see that cache files have been created in the tmp/cache_remote_file directory.
Do you know how I would retrieve the information from this onto a Wordpress site? So my cmsms is the master site and the Wordpress site is the 'recipient' site. I assume the following smarty tag is for use on other cmsms websites?
Code: Select all
{cache_remote_file url="http://www.website.com/index.php?page=page_alias"}
Any help or pointers in the right direction would be very much appreciated as I'm a php noob.
Re: Feed CMSMS menu through to Wordpress
Posted: Thu Feb 20, 2014 4:29 pm
by calguy1000
This involves just a few easy steps.
a: create a simple page template with just {content} in it. lets call this 'basic'
b: create a new content page using the basic template, lets call this 'menu-only'
- in that page include your menu tag. {menu} or whatever you need.
- mark that page as not searchable, not visible in menu, but cachable
- note the url to this page.
Browsing to that url... like: "
www.mysite.com/index.php?page=menu-only should now output the HTML code for the navigation, and ONLY that html code.
That's all you have to do with CMSMS. The rest of the work is done in your other system. Syntax and methods may vary.
c: include that URL in your code for the other system. something like:
Code: Select all
echo file_get_contents('http://www.mysite.com/index.php?page=menu-only'); // requires allow-url-fopen
d:
OPTIONAL
if you want the menu cached in wordpress or your other system, and allow-url-fopen is turned on you can use a method like this (untested) to cache the file
Code: Select all
$cache_file = 'some_temporary_location';
if( !file_exists($cache_file) || filemtime($cache_file) < time() - 3600 ) {
@copy('http://www.mysite.com/index.php?page=menu-only',$cache_file);
}
echo file_get_contents($cache_file);
NOTE:
Using the same methodology, with a few more steps you could also have the other system using the CMSMS stylesheets.
Re: Feed CMSMS menu through to Wordpress
Posted: Thu Feb 20, 2014 5:49 pm
by Rolf
Ohw, you need CMSMS -> WP in that case my tag won't help you...
Try Calguy's solution!
Re: Feed CMSMS menu through to Wordpress
Posted: Thu Feb 20, 2014 7:24 pm
by JohnnyB
I used to use an old plugin that would cache the menu to a file and then I would include that file using PHP into the WP template. Robert's example seems easy.
But, shouldn't something like this work too?
A UDT that writes the menu to a file? And then the file can be included into the WP template.
UDT
Code: Select all
$config = cmsms()->GetConfig();
// params
if (isset($params['filename']) && $params['filename'] != '') {
$filename = $params['filename'];
} else {
$filename = 'my_menu';
}
if (isset($params['expire']) && $params['expire'] != '') {
$expire = $params['expire'];
} else {
$expire = 60; // default 1 hour
}
if (isset($params['template']) && $params['template'] != '') {
$tpl_name = $params['template'];
} else {
echo 'template is required';
}
if( endswith($tpl_name, '.tpl') ) {
$usefile = true;
} else {
$usefile = false;
}
// set menu path and name
$tmpdir = $config['css_path']; // path to /tmp/cache/
$File = $tmpdir."/".$filename.".inc";
// check if menu exists and the age. Show cached menu or generate a new one
$menucache = time() - ($expire * 60);
$menudate = file_exists($File) ? filemtime($File) : -1;
if ($menudate > $menucache) {
// do nothing
} else {
$menumgr = cms_utils::get_module('MenuManager');
if ($usefile) {
$menu = $menumgr->ProcessTemplate($tpl_name);
} else {
$menu = $menumgr->ProcessTemplateFromDatabase($tpl_name);
}
file_put_contents($File,$menu);
}
Call it in a template like
{cachedmenu template='YourMenuTemplate' filename='menu'}
Right now, I'm just getting an empty file.

Re: Feed CMSMS menu through to Wordpress
Posted: Mon Feb 24, 2014 4:27 pm
by JM6891
Calguy's solution has worked perfectly for me, so thank you very much for your help!
Thank you to all who responded to this post too.