The following warnings occurred:
Warning [2] Undefined array key "threadviews_countguests" - Line: 745 - File: showthread.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php 745 errorHandler->error_callback
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/inc/functions_post.php 830 postParser->parse_message
/showthread.php 916 build_postbit
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/inc/functions_post.php 861 postParser->parse_message
/showthread.php 916 build_postbit
Warning [2] Undefined property: MyLanguage::$thread_modes - Line: 46 - File: showthread.php(1650) : eval()'d code PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php(1650) : eval()'d code 46 errorHandler->error_callback
/showthread.php 1650 eval




Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QUESTION How to Convert Component to a Function?
#2
Of course it is possible. In your functions.php file, simply wrap all of that code in a custom function & call it in your template. However, I don't know of any I18n parameter in that function to use custom markup (not a component), so you might need to use the return_i18n_menu_data function, like this:

PHP Code:
<?php
 
  
function build_i18n_nav($data$loop 0) {
    
$activeClass 'active';
    
$subMenuClass 'dropdown';
    
$output '<ul' . ($loop !== ' class="' $subMenuClass '"' '') . '>';
    for (
$i 0$i count($data); $i++) {
      
$item $data[$i];
      
$output .= '<li' . ($item['current'] ? ' class="' $activeClass '"' '' ) . '><a href="' htmlspecialchars(find_i18n_url($item['url'], $item['parent'])) . '">' $item['menu'] . '</a>';
      if (
$item['haschildren']) 
         
$output .= build_i18n_nav($item['children'], ++$loop);
      
$output .= '</li>';
    }
    
$output .= '</ul>';
    return 
$output;
  }
  
  function 
output_i18n_nav($url$minlevel$maxlevel$showtype) {
    
$menu_data return_i18n_menu_data($url$minlevel$maxlevel$showtype);
    echo 
build_i18n_nav($menu_data);
  }
?>

Then in your template, do eg.

PHP Code:
<div id="site-nav"><?php output_i18n_nav(return_page_slug(), 02I18N_SHOW_MENU?></div> 

For documentation on the return_i18n_menu_data function, refer to the website docs or this documentation page I built to provide extra-detailed info.
Reply


Messages In This Thread
RE: How to Convert Component to a Function? - by Tyblitz - 2015-06-16, 07:19:04



Users browsing this thread: 1 Guest(s)