2011-02-15 36 views
3

我仍然固執反對wordpress似乎。我添加窗口小部件的「檔案」,以我的側邊欄,並再次,HTML輸出是胡扯,它基本上具有這樣的結構:WordPress的檔案小工具 - 自定義html輸出

<li><a href="somelink">text</a> - (# of posts)</li> 

我想把它改造成:

<li><a href="somelink">text <small># of posts</small></a> 

不像插件然而,我無法找到在wordpress社區建議/提到的php頁面中創建html輸出的行,即functions.php,widgets.php和default-widgets.php

我已經使用了google關於此事的每一個可能的關鍵字組合,我無法找到事情相關。

所有幫助表示讚賞

問候

G.Campos

回答

2

退房一般的template.php。兩個函數wp_get_archives和get_archives_link。您必須破解wp_get_archives才能更改在$ text中加載的內容。帖子數被加載到放置在get_archives_link鏈接之外的$ after變量中。取而代之的是:

$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year); 
if ($show_post_count) 
    $after = '&nbsp;('.$arcresult->posts.')' . $afterafter; 

是這樣的:

$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year); 
if ($show_post_count) 
    $text= $text.'&nbsp;<small>'.$arcresult->posts.'</small>'; 

這還只是每月存檔。您必須對每年,每週和每日塊進行修改。

編輯:排除來自鏈接的標題<small>元件最簡單方法是加載它在每個塊中一個單獨的變量,然後將其通入經修飾的get_archives_link。在上面的例子中,右後$文本被載入了剛剛加載值到$標題:

$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year); 
$title = $text; 
if ($show_post_count) 
    $text= $text.'&nbsp;<small>'.$arcresult->posts.'</small>'; 
$output .= get_archives_link($url, $text, $format, $before, $after, $title); 

然後修改get_archives_link:

function get_archives_link($url, $text, $format = 'html', $before = '', $after = '', $title = '') { 
    $text = wptexturize($text); 

    if($title == '') 
     $title = $text; 

    $title_text = esc_attr($title); 
    $url = esc_url($url); 

    if ('link' == $format) 
     $link_html = "\t<link rel='archives' title='$title_text' href='$url' />\n"; 
    elseif ('option' == $format) 
     $link_html = "\t<option value='$url'>$before $text $after</option>\n"; 
    elseif ('html' == $format) 
     $link_html = "\t<li>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n"; 
    else // custom 
     $link_html = "\t$before<a href='$url' title='$title_text'>$text</a>$after\n"; 

    $link_html = apply_filters("get_archives_link", $link_html); 

    return $link_html; 
} 
相關問題