Esempio n. 1
0
  public function link($args = array()) {
    // get an <a> tag linking to the archive page of the post type
    // by default the text will be the plural label for the post type
    // if the post type doesn't have an archive, an empty string will be returned.
  
    $defaults = array(
      'text' => $this->plural_label(),
      'root_relative' => true,
      'current_class' => 'current'
    );
  
    $r = wp_parse_args( $args, $defaults );

    $post_type_archive_url = $this->archive_url($r["root_relative"]);
    
    if (!$post_type_archive_url) {
      return '';
    }
    
    if ( $r['current_class'] && trim($_SERVER["REQUEST_URI"], "/") == trim($post_type_archive_url, "/") ) {
      if (isset($r['class'])) {
        $r['class'] .= (' '.$r['current_class']);
      } else {
        $r['class'] = $r['current_class'];
      }
    }

 
    if ($r["root_relative"]) {
      $tag = '<a href="'.WOOF::lpad($post_type_archive_url, "/").'"';
    } else {
      $tag = '<a href="'.get_bloginfo("home").$post_type_archive_url.'"';
    }

    foreach ($r as $key => $value) {
      if ($key != "text" && $key != "href" && $key != "current_class" && $key != "root_relative") {
        $tag .= ' '.$key.'="'.esc_attr($value).'"';
      }
    }
  
    $tag .= '>'.$r['text'].'</a>';

    return $tag;
  }