2011-02-15 37 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; 
} 
相关问题