PHP 根据类别覆盖theme_links中的特定链接。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 根据类别覆盖theme_links中的特定链接。相关的知识,希望对你有一定的参考价值。

/**
 * Return a themed set of links.
 *
 * @param $links
 *   A keyed array of links to be themed.
 * @param $attributes
 *   A keyed array of attributes
 * @return
 *   A string containing an unordered list of links.
 */
function phptemplate_links($links, $attributes = array('class' => 'links')) {
  $output = '';

  if (count($links) > 0) {
    $num_links = count($links);
    $i = 1;

    $items_str = '';
    foreach ($links as $key => $link) {
      $class = '';

      // Automatically add a class to each link and also to each LI
      if (isset($link['attributes']) && isset($link['attributes']['class'])) {
        $link['attributes']['class'] .= ' ' . $key;
        $class = $key;
      }
      else {
        $link['attributes']['class'] = $key;
        $class = $key;
      }

      // Add first and last classes to the list of links to help out themers.
      $extra_class = '';
      if ($i == 1) {
        $extra_class .= 'first ';
      }
      if ($i == $num_links) {
        $extra_class .= 'last ';
      }
      
      // Is the title HTML?
      $html = isset($link['html']) && $link['html'];

      // Initialize fragment and query variables.
      $link['query'] = isset($link['query']) ? $link['query'] : NULL;
      $link['fragment'] = isset($link['fragment']) ? $link['fragment'] : NULL;


      //Check if we have a link, for sometimes we need to output just a splain string.
      //A class can only contain spaces, hyphens or underscores. Translate these to underscores.
      $func_class = strtr($link['attributes']['class'], '- ', '__');
      //dpm($func_class);
      if (isset($link['href'])) {
        //First, see if we have a theme function for this class
        if (!empty($func_class) && ($function = theme_get_function('links_'. $func_class))) { //then,  look for a theme function based on the class.
          dpm($function);
          $items_str .= theme('links_'. $func_class, $link);
        }
        else { //If no specific function was found, fall back to a default.
          $items_str .= '<li class="'. $extra_class . $class .'">';
          $items_str .= l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html);          $items_str .= "</li>\n";  
        }
      }  
      else if ($link['title']) {
        //Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (!$html) {
          $link['title'] = check_plain($link['title']);
        }
        $items_str .= '<span'. drupal_attributes($link['attributes']) .'>'. $link['title'] .'</span>';
      }
    
      $i++;
    }
    $output = '<ul'. drupal_attributes($attributes) .'>'. $items_str .'</ul>';
  }

  return $output;
}

/**
 * Theme callbakc from theme_links, renders the comment_add link
 **/
function phptemplate_links_comment_add($ink) {
  $output =  '"<li class="'. $extra_class . $class .'">';
  $output .= l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html);
  $output .= "</li>\n";  
}

以上是关于PHP 根据类别覆盖theme_links中的特定链接。的主要内容,如果未能解决你的问题,请参考以下文章

PHP 从Wordpress中的搜索结果中排除特定类别

s-s-rS 根据矩阵/tablix 中的特定列类别添加百分比列

PHP Wordpress根据页面显示类别中的帖子。

百度地图根据类别不同做不同的标注

从 WordPress 中的特定类别获取置顶帖子

从 WooCommerce 中的类别价格后缀更改中排除特定产品 ID