简体   繁体   中英

Sitemap custom module

I am writing a custom module for site map in drupal 7. What I had done is below.

function escorts_sitemap_render_menu ($menu) 
  {
   $output = "<ul>";
   foreach ($menu as $item) 
   {
   $link = $item["link"];
   if ($link["hidden"])
     {
     continue;
     }
   $output .= "<li><a href=\"" . check_url(url($link["href"], $link["options"])) . "\">" . $link["title"] . "</a></li>";
   if ($item["below"]) 
     {
     $output .= sitemap_render_menu($item["below"]);
     }
   }
   $output .= "</ul>";
   return $output;
  }
function escorts_sitemap_content () 
  {
   $output = "<h1>Escorts Sitemap</h1>";
   $output .= "<ul class=\"site_map_list\">";
   $output .= sitemap_render_menu(menu_tree_all_data("main-menu"));
   return $output;
  }
function escorts_sitemap_menu () 
  {
   $items = array();
   $items["sitemap"] = array (
   "title" => "Escorts Sitemap",
   "page callback" => "escorts_sitemap_content",
   "access arguments" => array("access content"),
   "type" => MENU_CALLBACK);
    return $items;
  }

then in template.php I implemented hook_theme too, below is the code :

 function escorts_theme() {
 return array(
'escorts_sitemap_content' => array(
   'render element' => 'content',
    'template' => 'page--sitemap',
    'path' => drupal_get_path('theme', 'escorts') . '/templates'
 ),
 );
 }

But it is not appearing as I have my custom template file page--sitemap.tpl.php , can any one please guide me. But now what should I write in page--sitemap.tpl.php in order to render my sitemap

Maybe You should try next:

  function escorts_theme() {
    return array(
      'escorts_sitemap_content' => array(
         'variables' => array('content' => NULL)
         /**
          * I would not call template like this, cause it looks like 
          * pattern page--[node-type]
          */
         'template' => 'page--sitemap',
      )
    );
  }

And inside of menu callback function

function escorts_sitemap_content () {
  $output = "<h1>Escorts Sitemap</h1>";
  $output .= "<ul class=\"site_map_list\">";
  $output .= sitemap_render_menu(menu_tree_all_data("main-menu"));
  return theme('escorts_sitemap_content', $output);
}

This is one of ways. Also look in preprocess functions, and Drupal theme layer at all. And maybe ready module XML sitemap will be useful. Also be careful, if file is really located there.

And in template file just paste

<?php print $content; ?>

Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM