0

I have created a block that generates some links. I want to display these links as menu tabs in my website. This is the php code I have written inside block.

<?php
  $current_url = current_path();
  $param = explode("/", $current_url);
  $nid = $param[1];

  $type = db_select("node", "n")
            ->fields("n", array("type"))
            ->condition("nid", $nid, "=")
            ->execute()
            ->fetchAssoc();

  switch($type['type']) {
    case "description":
      $current_desc_link = $current_url;
      $current_demo_link = db_select("field_data_field_desc_demolink", "fddd")
                          ->fields("fddd", array("field_desc_demolink_url"))
                          ->condition("entity_id", $nid, "=")
                          ->execute()
                          ->fetchAssoc();

      $howto_entityid = db_select("field_data_field_howto_demolink", "fdhd")
                          ->fields("fdhd", array("entity_id"))
                          ->condition("field_howto_demolink_url", $current_demo_link['field_desc_demolink_url'], "=")
                          ->execute()
                          ->fetchAssoc();

      $current_howto_link = "node/" . $howto_entityid;

      break;

    case "how_to":
      $current_howto_link = $current_url;
      $current_demo_link = db_select("field_data_field_howto_demolink", "fdhd")
                          ->fields("fdhd", array("field_howto_demolink_url"))
                          ->condition("entity_id", $nid, "=")
                          ->execute()
                          ->fetchAssoc();

      $desc_entityid = db_select("field_data_field_desc_demolink", "fddd")
                          ->fields("fddd", array("entity_id"))
                          ->condition("field_desc_demolink_url", $current_demo_link['field_howto_demolink_url'], "=")
                          ->execute()
                          ->fetchAssoc();

      $current_desc_link = "node/" . $desc_entityid;

      break;


    default:
      $desc_entityid = db_select("field_data_field_desc_demolink", "fddd")
                          ->fields("fddd", array("entity_id"))
                          ->condition("field_desc_demolink_url", $current_url, "=")
                          ->execute()
                          ->fetchAssoc();

      $howto_entityid = db_select("field_data_field_howto_demolink", "fdhd")
                          ->fields("fdhd", array("entity_id"))
                          ->condition("field_howto_demolink_url", $current_url, "=")
                          ->execute()
                          ->fetchAssoc();

      $current_demo_link = current_url;
      $current_desc_link = "node/" . $desc_entityid;
      $current_howto_link = "node/" . $howto_entityid;

      break;
}
?>

I want to render $current_demo_link, $current_desc_link, $current_howto_link as menu tabs in drupal webiste. I have tried menu_tree_output but I have to create menu links in Db. Is there any other way to render the links as menu without converting this as menu links.

1 Answer 1

1

Maybe try something like this?

$output = '<ul class="tabs primary">';
$output .= '<li><a href="' . url($current_demo_link) . '">demo link title</a>';
$output .= '<li><a href="' . url($current_desc_link) . '">desc link title</a>'
$output .= '<li><a href="' . url($current_howto_link) . '">hot to link title</a>'
$output .= '</ul>';
1
  • simple and a perfect answer Commented May 5, 2012 at 4:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.