2012-10-27 27 views
1

我正在使用wordpress的Origin主題,並且我正試圖自定義帖子上方的評論鏈接。現在它顯示了評論的數量和文字「評論」,但我只想顯示數字(沒有評論時顯示0)。我在shortcodes.php的主題>庫>函數文件夾中找到了相關的代碼。原始wordpress主題中的簡碼中的意見鏈接

如何編輯此項僅顯示沒有「註釋」文本的註釋數量,例如: 「1」而不是「1評論」?

這是當前的代碼:你只需要刪除單詞「註釋」,或在相關位「意見」

function hybrid_entry_comments_link_shortcode($attr) { 

    $comments_link = ''; 
    $number = doubleval(get_comments_number()); 
    $attr = shortcode_atts(array('zero' => __('Leave a comment', 'hybrid-core'), 'one' => __('%1$s comment', 'hybrid-core'), 'more' => __('%1$s comments', 'hybrid-core'), 'css_class' => 'comments-link', 'none' => '', 'before' => '', 'after' => ''), $attr); 

    if (0 == $number && !comments_open() && !pings_open()) { 
     if ($attr['none']) 
      $comments_link = '<span class="' . esc_attr($attr['css_class']) . '">' . sprintf($attr['none'], number_format_i18n($number)) . '</span>'; 
    } 
    elseif (0 == $number) 
     $comments_link = '<a class="' . esc_attr($attr['css_class']) . '" href="' . get_permalink() . '#respond" title="' . sprintf(esc_attr__('Comment on %1$s', 'hybrid-core'), the_title_attribute('echo=0')) . '">' . sprintf($attr['zero'], number_format_i18n($number)) . '</a>'; 
    elseif (1 == $number) 
     $comments_link = '<a class="' . esc_attr($attr['css_class']) . '" href="' . get_comments_link() . '" title="' . sprintf(esc_attr__('Comment on %1$s', 'hybrid-core'), the_title_attribute('echo=0')) . '">' . sprintf($attr['one'], number_format_i18n($number)) . '</a>'; 
    elseif (1 < $number) 
     $comments_link = '<a class="' . esc_attr($attr['css_class']) . '" href="' . get_comments_link() . '" title="' . sprintf(esc_attr__('Comment on %1$s', 'hybrid-core'), the_title_attribute('echo=0')) . '">' . sprintf($attr['more'], number_format_i18n($number)) . '</a>'; 

    if ($comments_link) 
     $comments_link = $attr['before'] . $comments_link . $attr['after']; 

    return $comments_link; 
} 

回答

0

有問題的行以$attr = shortcode_atts(....

這被修改爲您:

function hybrid_entry_comments_link_shortcode($attr) { 

    $comments_link = ''; 
    $number = doubleval(get_comments_number()); 
    $attr = shortcode_atts(array('zero' => __('Leave a comment', 'hybrid-core'), 'one' => __('%1$s', 'hybrid-core'), 'more' => __('%1$s', 'hybrid-core'), 'css_class' => 'comments-link', 'none' => '', 'before' => '', 'after' => ''), $attr); 

    if (0 == $number && !comments_open() && !pings_open()) { 
     if ($attr['none']) 
      $comments_link = '<span class="' . esc_attr($attr['css_class']) . '">' . sprintf($attr['none'], number_format_i18n($number)) . '</span>'; 
    } 
    elseif (0 == $number) 
     $comments_link = '<a class="' . esc_attr($attr['css_class']) . '" href="' . get_permalink() . '#respond" title="' . sprintf(esc_attr__('Comment on %1$s', 'hybrid-core'), the_title_attribute('echo=0')) . '">' . sprintf($attr['zero'], number_format_i18n($number)) . '</a>'; 
    elseif (1 == $number) 
     $comments_link = '<a class="' . esc_attr($attr['css_class']) . '" href="' . get_comments_link() . '" title="' . sprintf(esc_attr__('Comment on %1$s', 'hybrid-core'), the_title_attribute('echo=0')) . '">' . sprintf($attr['one'], number_format_i18n($number)) . '</a>'; 
    elseif (1 < $number) 
     $comments_link = '<a class="' . esc_attr($attr['css_class']) . '" href="' . get_comments_link() . '" title="' . sprintf(esc_attr__('Comment on %1$s', 'hybrid-core'), the_title_attribute('echo=0')) . '">' . sprintf($attr['more'], number_format_i18n($number)) . '</a>'; 

    if ($comments_link) 
     $comments_link = $attr['before'] . $comments_link . $attr['after']; 

    return $comments_link; 
} 
+0

這工作!謝謝cale_b! – HelloYellow