管理者サイドバーの内容を変更して、保留中の投稿インジケーターを表示します
質問
保留中のコメントのために表示される小さなバブルのように、保留中の投稿のために、私は管理サイドバーに保留中のカウントを取得しようとしています。
オフトピック: :これがコアの動作であるべきだと思うのは私だけですか?この機能はどこに提案すればよいですか?
とにかく、私は見つけました このプラグイン, 、しかし、私はそれが常に機能していなかったことに気づきました。時々、通知者がページまたはその他のアイテムに表示されます。
保留中のカウントを追加するために使用するコードは次のようになります。
$menu[5][0] .= " <span class='update-plugins count-$pending_count'><span class='plugin-count'>" . number_format_i18n($pending_count) . '</span></span>';
それで、明らかに問題はハードコーディングされた5です5ですが、どうすればそれを更新できるように、それは常に投稿を指しますか?
答えを知っていれば、この変更をプラグインにコミットできることを嬉しく思います。
ありがとう!
解決
@ign
投稿したコードの行を次のものに置き換えます。
foreach( $menu as $menu_key => $menu_data ) :
if( 'edit.php' != $menu_data[2] )
continue;
$menu[$menu_key][0] .= " <span class='update-plugins count-$pending_count'><span class='plugin-count'>" . number_format_i18n($pending_count) . '</span></span>';
endforeach;
..それ したほうがいい 特定のキーを知る必要性を避けてください。(問題があるかどうか教えてください)。
それが役立つことを願っています.. :)
他のヒント
T31OSの回答のフォローアップとして、必要な完全なコード(T31OSの修正で言及されたプラグインのコンテンツを組み合わせて)と、カスタムポストタイプを処理する修正とともに次のようになります。
add_filter( 'add_menu_classes', 'show_pending_number');
function show_pending_number( $menu ) {
$type = "animals";
$status = "pending";
$num_posts = wp_count_posts( $type, 'readable' );
$pending_count = 0;
if ( !empty($num_posts->$status) )
$pending_count = $num_posts->$status;
// build string to match in $menu array
if ($type == 'post') {
$menu_str = 'edit.php';
} else {
$menu_str = 'edit.php?post_type=' . $type;
}
// loop through $menu items, find match, add indicator
foreach( $menu as $menu_key => $menu_data ) {
if( $menu_str != $menu_data[2] )
continue;
$menu[$menu_key][0] .= " <span class='update-plugins count-$pending_count'><span class='plugin-count'>" . number_format_i18n($pending_count) . '</span></span>';
}
return $menu;
}
これをfunctions.phpに配置します。プラグインは必要ありません。
私は、複数のポストタイプを可能にするSomaticの投稿をわずかに変更しました。
// Add pending numbers to post types on admin menu
function show_pending_number($menu) {
$types = array("post", "page", "custom-post-type");
$status = "pending";
foreach($types as $type) {
$num_posts = wp_count_posts($type, 'readable');
$pending_count = 0;
if (!empty($num_posts->$status)) $pending_count = $num_posts->$status;
if ($type == 'post') {
$menu_str = 'edit.php';
} else {
$menu_str = 'edit.php?post_type=' . $type;
}
foreach( $menu as $menu_key => $menu_data ) {
if( $menu_str != $menu_data[2] )
continue;
$menu[$menu_key][0] .= " <span class='update-plugins count-$pending_count'><span class='plugin-count'>" . number_format_i18n($pending_count) . '</span></span>';
}
}
return $menu;
}
add_filter('add_menu_classes', 'show_pending_number');
所属していません wordpress.stackexchange