MODx site menu in external PHP app

From MODx Wiki

Jump to: navigation, search

So, you would like to get your MODx menu in to some other PHP app, like in forum or online shop? It's easy! Here's the steps:

  • Download MODxAPI and add it to the root of your site.
  • Create a file called sitemenu.php (or use some other name) with the following contents:
<?php
 
$path = '/path/to/site/root/';
include_once($path.'modxapi.php');
 
$modx = new MODxAPI();
// connect to db and load settings
$modx->connect();
$modx->getSettings();
 
$html = $modx->getChunk('Menu-StyleSheet');
$html.= $modx->runSnippet('DropMenu', array('topnavClass' => 'nav', 'selfAsLink' => 'true'));
echo $html;
 
?>
  • Modify your external PHP application's template to include the sitemenu.php file
  • That's that!


An Alternative Method

Here is the method that I use, and you don't have to install any extra scripts.

  1. Create a new page on the site with these settings:
    1. Title: Menu Include
    2. Alias: menu-include
    3. Template: blank
    4. Show in menu: Unchecked
    5. Rich text: Unchecked
    6. Log visits: Unchecked
    7. Published: Checked
    8. Cacheable: Unchecked
    9. Content: [[Wayfinder?startId=`0`]] (or whatever your menu snippet call is)
  2. Then, in your external app create a php include where you want your menu to be:
    <?php include("http://www.example.com/menu-include"); ?>
  3. Make sure the same menu styles from your MODx site are used in your external app.

In order for this to work URL fopen wrappers must be enabled in PHP. See the php include docs for more info.

By DEVTRENCH 12:36, 18 July 2007 (PDT)

Personal tools