2014-01-12 43 views
0

我是一個運行項目主題Wordpress網站的noob。有一個小部件在列中顯示「按類別瀏覽」列表。從Wordpress自定義小部件中刪除帖子數

小部件在類別標題旁邊的括號內顯示帖子數。我想刪除它。

任何幫助將不勝感激。

這是插件的代碼:

add_action('widgets_init', 'register_browse_by_category_widget'); 
    function register_browse_by_category_widget() { 
    register_widget('ProjectTheme_browse_by_category'); 
} 

class ProjectTheme_browse_by_category extends WP_Widget { 

    function ProjectTheme_browse_by_category() { 
     $widget_ops = array('classname' => 'browse-by-category', 'description' => 'Show all categories and browse by category'); 
     $control_ops = array('width' => 200, 'height' => 250, 'id_base' => 'browse-by-category'); 
     $this->WP_Widget('browse-by-category', 'ProjectTheme - Browse by Category', $widget_ops, $control_ops); 
    } 

    function widget($args, $instance) { 
     extract($args); 

     echo $before_widget; 

     if ($instance['title']) echo $before_title . apply_filters('widget_title', $instance['title']) . $after_title; 

     $loc_per_row = $instance['loc_per_row']; 
     $widget_id  = $args['widget_id']; 
     $nr_rows  = $instance['nr_rows']; 
     $only_these  = $instance['only_these']; 
     $only_parents = $instance['only_parents']; 

     if($only_parents == "on") $only_parents = true; 
     else $only_parents = false; 


     $nr = 4; 

     if(!empty($loc_per_row)) $nr = $loc_per_row; 
     echo '<style>#'.$widget_id.' #location-stuff li>ul { width: '.(round(100/$nr)-0.5).'%}</style>'; 

     if($nr_rows > 0) $jk = "&number=".($nr_rows * $loc_per_row); 

     $terms_k = get_terms("project_cat","parent=0&hide_empty=0"); 
     $terms = get_terms("project_cat","parent=0&hide_empty=0".$jk); 


     //$term = get_term($term_id, $taxonomy); 

     if($only_these == "1") 
     { 
      $terms = array(); 

      foreach($terms_k as $trm) 
      { 
       if($instance['term_' . $trm->term_id] == $trm->term_id) 
        array_push($terms, $trm); 
      } 

     } 


     //----------------------------- 

     if(count($terms) < count($terms_k)) $disp_btn = 1; 
     else $disp_btn = 0; 


     $count = count($terms); $i = 0; 
     if ($count > 0){ 
      echo "<ul id='location-stuff'>"; 
      foreach ($terms as $term) { 

       if($i%$nr == 0) echo "<li>"; 
       $total_ads = 0; 
       $terms2 = ''; 
       $terms2 = get_terms("project_cat","parent=".$term->term_id."&hide_empty=0"); 

       $mese = ''; 

        $mese .= '<ul>'; 
        $mese .= "<img src=\"".get_bloginfo('template_url')."/images/posted.png\" width=\"20\" height=\"20\" /> 
        <h3><a class='parent_taxe' rel='taxe_project_cat_".$term->term_id."' href='".get_term_link($term->slug,"project_cat")."'>" . $term->name; 

        //."</a></h3>"; 

       $total_ads = ProjectTheme_get_custom_taxonomy_count('project',$term->slug); 

       $mese2 = ''; 
       if($terms2 && $only_parents == false) 
       { 

        foreach ($terms2 as $term2) 
        { 
         $tt = ProjectTheme_get_custom_taxonomy_count('project',$term2->slug); 
         $total_ads += $tt; 
         //$mese2 .= "<li><a href='".get_term_link($term2->slug,"project_cat")."'>" . $term2->name." (".$tt.")</a></li>"; 
         $mese2 .= "<li><a href='".get_term_link($term2->slug,"project_cat")."'>" . $term2->name." </a></li>"; 
        } 
       } 

        echo $mese."(".$total_ads.")</a></h3>"; 
        echo '<ul id="_project_cat_'.$term->term_id.'">'.$mese2."</ul>"; 

        echo '</ul>'; 


       if(($i+1) % $nr == 0) echo "</li>"; 

       $i++; 

      } 

       //if(($i+1) % $nr != 0) echo "</li>"; 


      echo "</ul>"; 

     }   

     if($disp_btn == 1) 
     { 
       echo '<br/><b><a href="'.get_permalink(get_option('ProjectTheme_all_categories_page_id')).'">'.__('See More Categories','ProjectTheme').'</a></b>';  
     }  



     echo $after_widget; 
    } 

    function update($new_instance, $old_instance) { 

     return $new_instance; 
    } 

    function form($instance) { ?> 
     <p> 
      <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title'); ?>:</label> 
      <input type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" 
      value="<?php echo esc_attr($instance['title']); ?>" style="width:95%;" /> 
     </p> 

     <p> 
      <label for="<?php echo $this->get_field_id('only_parents'); ?>"><?php _e('Only show parent categories'); ?>:</label> 
      <input type="checkbox" id="<?php echo $this->get_field_id('only_parents'); ?>" name="<?php echo $this->get_field_name('only_parents'); ?>" 
      <?php echo (esc_attr($instance['only_parents']) == "on" ? "checked='checked'" : ""); ?> /> 
     </p> 


     <p> 
      <label for="<?php echo $this->get_field_id('loc_per_row'); ?>"><?php _e('Number of Columns'); ?>:</label> 
      <input type="text" id="<?php echo $this->get_field_id('loc_per_row'); ?>" name="<?php echo $this->get_field_name('loc_per_row'); ?>" 
      value="<?php echo esc_attr($instance['loc_per_row']); ?>" style="width:20%;" /> 
     </p> 

     <p> 
      <label for="<?php echo $this->get_field_id('nr_rows'); ?>"><?php _e('Number of Rows'); ?>:</label> 
      <input type="text" id="<?php echo $this->get_field_id('nr_rows'); ?>" name="<?php echo $this->get_field_name('nr_rows'); ?>" 
      value="<?php echo esc_attr($instance['nr_rows']); ?>" style="width:20%;" /> 
     </p> 


     <p> 
      <label for="<?php echo $this->get_field_id('nr_rows'); ?>"><?php _e('Only show categories below'); ?>:</label> 
      <?php echo '<input type="checkbox" name="'.$this->get_field_name('only_these').'" value="1" '.(
    $instance['only_these'] == "1" ? ' checked="checked" ' : "").' /> '; ?> 
     </p> 

     <p> 
      <label for="<?php echo $this->get_field_id('nr_rows'); ?>"><?php _e('Categories to show'); ?>:</label> 

       <div style=" width:220px; 
    height:180px; 
    background-color:#ffffff; 
    overflow:auto;border:1px solid #ccc"> 
    <?php 

    $terms = get_terms("project_cat","parent=0&hide_empty=0"); 
    foreach ($terms as $term) { 

    echo '<input type="checkbox" name="'.$this->get_field_name('term_'.$term->term_id).'" value="'.$term->term_id.'" '.(
    $instance['term_'.$term->term_id] == $term->term_id ? ' checked="checked" ' : "").' /> '; 
    echo $term->name.'<br/>'; 

    } 

    ?> 

    </div> 



     </p> 


    <?php 
    } 
} 

?> 
+0

有什麼理由w你不使用函數get_categories? http://codex.wordpress.org/Function_Reference/get_categories – archetipo

+0

你好。感謝您的迴應。這是因爲它被寫入,並且是一個自定義小部件,它構成了它們的一部分,我剛剛開始嘗試學習。 – user3003638

回答

0

這是寫入按類別的職位數的代碼部分...

改變這種

echo $mese."(".$total_ads.")</a> 

echo $mese."</a>"; 
+0

嗨there.Thanks的建議,但是打破了一些東西,頁面不會給出錯誤,但只是顯示一個空白的屏幕。 – user3003638

+0

我有正確的代碼...現在..試試 – archetipo

+0

非常感謝!這工作完美。 – user3003638

相關問題