Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4021200
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:19:20+00:00 2026-05-20T10:19:20+00:00

I need to take some simple UL tag generated in PHP (Joomla 1.5) and

  • 0

I need to take some simple UL tag generated in PHP (Joomla 1.5) and wrap each anchor tag’s text content with a SPAN tag. The incoming HTML looks like this:

<ul>
  <li>
      <a href="#">Home</a>
    </li>
    <li>
      <a href="#">Watch UNC-TV</a>
    </li>
    <li>
      <a href="#" >Contact</a>
    </li>
</ul>

The output needs to look like this:

<ul id="top-nav" class="flatList">
  <li class="selected">
      <a href="#"><span class="embed embed-top-nav">Home</span>
        <p >news, highlights</p></a>
    </li>
    <li>
      <a href="#"><span class="embed embed-top-nav">Watch UNC-TV</span>
        <p>schedule, local programs</p></a>
    </li>
    <li id="nav-last">
      <a href="#"><span class="embed embed-top-nav">Contact</span>
        <p>feedback, connect, share</p></a>
    </li>
</ul>

Also note the class added to the active LI tag (“selected”) and the class added to the last one in the list (“nav-last”). This is in Joomla 1.5, where I’m overriding the mod_mainmenu module used by the Main Menu. The code uses the SimpleXML library to read and write the HTML in the modMainMenuXMLCallback(&$node, $args):

<?php
defined('_JEXEC') or die('Restricted access');

if ( ! defined('fancyMenuPatch') ) 
{
  function fancyMenuPatch($result,$tag){
    // Replace UL tag with ours. 
    // Replace LI tag with ours.

    // Add to the start of the UL tag.
    $begin_ul = "<ul id=\"top-nav\" class=\"flatList\">";
    $begin_li = "<li>"; //not sure what to do with this.

    // do the replacement
    $result = str_replace("<ul>",$begin_ul, $result);
    $result = str_replace("<li>", $begin_li, $result);

    return $result;
  }

  define('fancyMenuPatch', true);
}

if ( ! defined('modMainMenuXMLCallbackDefined') )
{
function modMainMenuXMLCallback(&$node, $args)
{
  $user = &JFactory::getUser();
  $menu = &JSite::getMenu();
  $active   = $menu->getActive();
  $path = isset($active) ? array_reverse($active->tree) : null;

  if (($args['end']) && ($node->attributes('level') >= $args['end']))
  {
    $children = $node->children();
    foreach ($node->children() as $child)
    {
      if ($child->name() == 'ul') {
        $node->removeChild($child);
      }
    }
  }

  if ($node->name() == 'ul') {
    foreach ($node->children() as $child)
    {
      if ($child->attributes('access') > $user->get('aid', 0)) {
        $node->removeChild($child);
      }
    }
  }

  if (($node->name() == 'li') && isset($node->ul)) {
    $node->addAttribute('class', 'parent');
  }

  if (isset($path) && (in_array($node->attributes('id'), $path) || in_array($node->attributes('rel'), $path)))
  {
    if ($node->attributes('class')) {
      $node->addAttribute('class', $node->attributes('class').' active');
    } else {
      $node->addAttribute('class', 'active');
    }
  }
  else
  {
    if (isset($args['children']) && !$args['children'])
    {
      $children = $node->children();
      foreach ($node->children() as $child)
      {
        if ($child->name() == 'ul') {
          $node->removeChild($child);
        }
      }
    }
  }

  if (($node->name() == 'li') && ($id = $node->attributes('id'))) {
    if ($node->attributes('class')) {
      $node->addAttribute('class', $node->attributes('class').' item'.$id);
    } else {
      $node->addAttribute('class', 'item'.$id);
    }
  }

  if (isset($path) && $node->attributes('id') == $path[0]) {
    $node->addAttribute('id', 'current');
  } else {
    $node->removeAttribute('id');
  }
  $node->removeAttribute('rel');
  $node->removeAttribute('level');
  $node->removeAttribute('access');
}
  define('modMainMenuXMLCallbackDefined', true);
}

ob_start();

modMainMenuHelper::render($params, 'modMyMainMenuXMLCallback');
$menu_html = ob_get_contents();
ob_end_clean(); 

if($params->get('menutype')=="primarynav"){
  $tag = $params->get('tag_id');
  }
//output the menu!
echo fancyMenuPatch($menu_html,$tag);
?>

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:19:21+00:00Added an answer on May 20, 2026 at 10:19 am

    Ok so here is how you want to do this. Jump out of the default.php script you posted above. As Joomla! uses the core mainmenu module for all menus and trees down from that you will need to edit the helper script. This should stick regardless of any 3rd party menu extension you may be using.

    rootdirectory/modules/mod_mainmenu/helper.php
    

    Now jump down to the switch statement at line 358. Specifically we want to edit line 363. It looks like this:

    $data = '<a href="'.$tmp->url.'">'.$image.$tmp->name.'</a>';
    

    Now edit it to be this:

    $data = '<span class="embed embed-top-nav"><a href="'.$tmp->url.'">'.$image.$tmp->name.'</a></span>';
    

    there you go, now menus utilized by the Joomla! getMenu class will add this span tag around the links.

    Note that you may also want to do this to line 375 for links that will open in a new window et cetra. Also note Louis’ funny comment ” // hrm…this is a bit dickey”.

    cheers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.