我似乎仍然反对 wordpress。我将小部件“Archives”添加到我的侧边栏,再次,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
我用谷歌搜索了所有可能的关键字组合,但找不到相关内容。
感谢所有帮助
问候
G.坎波斯
最佳答案
查看 general-template.php。两个函数 wp_get_archives 和 get_archives_link。您必须破解 wp_get_archives 才能更改 $text 中加载的内容。帖子计数被加载到 $after 变量中,该变量位于 get_archives_link 中的链接之外。而不是这个:
$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
if ( $show_post_count )
$after = ' ('.$arcresult->posts.')' . $afterafter;
像这样:
$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
if ( $show_post_count )
$text= $text.' <small>'.$arcresult->posts.'</small>';
这仅适用于每月存档。您必须对每年、每周和每天的 block 进行修改。
编辑:排除 <small>
的最简单方法链接标题中的元素是将其加载到每个 block 中的单独变量中,然后将其传递到修改后的 get_archives_link 中。在上面的示例中,在 $text 加载后立即将该值加载到 $title 中:
$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
$title = $text;
if ( $show_post_count )
$text= $text.' <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;
}
关于php - Wordpress 文件小部件 - 自定义 html 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5009488/