admin管理员组文章数量:1330592
I have added custom column to all posts page by this code:
// ADD NEW COLUMN
function len_columns_head($defaults) {
$defaults['post_len'] = 'Symbols';
return $defaults;
}
// SHOW POST LENGTH
function len_columns_content($column_name, $post_ID) {
if ($column_name == 'post_len') {
$post = get_post($post_ID);
$content = $post->post_content;
$length = strlen($content);
if ($length) {
echo $length.' symbols';
}
}
}
add_filter('manage_posts_columns', 'len_columns_head');
add_action('manage_posts_custom_column', 'len_columns_content', 10, 2);
but now i need to add total count of symbols to column title like this: "Symbols, 123456 total". How can i achieve this? I have tried to add global variable to functions.php and add $length to it on every len_columns_content call, but that didn't work
I have added custom column to all posts page by this code:
// ADD NEW COLUMN
function len_columns_head($defaults) {
$defaults['post_len'] = 'Symbols';
return $defaults;
}
// SHOW POST LENGTH
function len_columns_content($column_name, $post_ID) {
if ($column_name == 'post_len') {
$post = get_post($post_ID);
$content = $post->post_content;
$length = strlen($content);
if ($length) {
echo $length.' symbols';
}
}
}
add_filter('manage_posts_columns', 'len_columns_head');
add_action('manage_posts_custom_column', 'len_columns_content', 10, 2);
but now i need to add total count of symbols to column title like this: "Symbols, 123456 total". How can i achieve this? I have tried to add global variable to functions.php and add $length to it on every len_columns_content call, but that didn't work
Share Improve this question asked Jul 17, 2020 at 15:40 dmitrydmitry 111 bronze badge 1 |1 Answer
Reset to default 1WebElaine, if you are asking about global variable, i am doing something like this:
global $total_len;
...
function len_columns_content($column_name, $post_ID) {
...
if ($length) {
$total_len += $length;
echo $length.' symbols'.'total: '.$total_len;
}
...
and in every string i have get $total_len equal $length, as if $total_len is not global
本文标签: filtersHow to add 39total39 value to custom column title on the posts list page
版权声明:本文标题:filters - How to add 'total' value to custom column title on the posts list page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742251975a2440932.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
var_dump()
of$content
to verify that it's a string? – WebElaine Commented Jul 17, 2020 at 15:51