WordPress.org

Plugin Directory

Changeset 629831


Ignore:
Timestamp:
11/25/12 22:21:48 (17 months ago)
Author:
eskapism
Message:

fix post count

Location:
cms-tree-page-view/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cms-tree-page-view/trunk/functions.php

    r629638 r629831  
    482482} 
    483483 
     484 
     485function cms_tpv_get_wpml_post_counts($post_type) { 
     486 
     487    global $wpdb; 
     488 
     489    $arr_statuses = array("publish", "draft", "trash"); 
     490    $arr_counts = array(); 
     491 
     492    foreach ($arr_statuses as $post_status) { 
     493 
     494        $extra_cond = ""; 
     495        if ($post_status){ 
     496            $extra_cond .= " AND post_status = '" . $post_status . "'"; 
     497        } 
     498        if ($post_status != 'trash'){ 
     499            $extra_cond .= " AND post_status <> 'trash'"; 
     500        } 
     501        $extra_cond .= " AND post_status <> 'auto-draft'"; 
     502        $sql = " 
     503            SELECT language_code, COUNT(p.ID) AS c FROM {$wpdb->prefix}icl_translations t 
     504            JOIN {$wpdb->posts} p ON t.element_id=p.ID 
     505            JOIN {$wpdb->prefix}icl_languages l ON t.language_code=l.code AND l.active = 1 
     506            WHERE p.post_type='{$post_type}' AND t.element_type='post_{$post_type}' {$extra_cond} 
     507            GROUP BY language_code 
     508        "; 
     509        $res = $wpdb->get_results($sql); 
     510 
     511        $langs['all'] = 0; 
     512        foreach($res as $r) { 
     513            $langs[$r->language_code] = $r->c; 
     514            $langs['all'] += $r->c; 
     515        } 
     516 
     517        $arr_counts[$post_status] = $langs; 
     518 
     519    } 
     520 
     521    return $arr_counts; 
     522 
     523} 
     524 
     525 
    484526/** 
    485527 * Print tree stuff that is common for both dashboard and page 
     
    487529function cms_tpv_print_common_tree_stuff($post_type = "") { 
    488530 
    489     global $sitepress, $cms_tpv_view; 
     531    global $sitepress, $cms_tpv_view, $wpdb; 
    490532 
    491533    if (!$post_type) { 
     
    509551        } 
    510552     
     553    } 
     554 
     555    $status_data_attributes = array("all" => "", "publish" => "", "trash" => ""); 
     556 
     557    // Calculate post counts 
     558    if ($wpml_current_lang) { 
     559 
     560        // Count code for WPML, mostly taken/inspired from  WPML Multilingual CMS, sitepress.class.php 
     561        $langs = array(); 
     562         
     563        $wpml_post_counts = cms_tpv_get_wpml_post_counts($post_type); 
     564         
     565        $post_count_all = $wpml_post_counts["publish"][$wpml_current_lang] + $wpml_post_counts["draft"][$wpml_current_lang]; 
     566        $post_count_publish = $wpml_post_counts["publish"][$wpml_current_lang]; 
     567        $post_count_trash   = $wpml_post_counts["trash"][$wpml_current_lang]; 
     568     
     569        foreach ($wpml_post_counts["publish"] as $one_wpml_lang => $one_wpml_lang_count) { 
     570            if ("all" === $one_wpml_lang) continue; 
     571            $lang_post_count_all        = $wpml_post_counts["publish"][$one_wpml_lang] + $wpml_post_counts["draft"][$one_wpml_lang]; 
     572            $lang_post_count_publish    = $wpml_post_counts["publish"][$one_wpml_lang]; 
     573            $lang_post_count_trash      = $wpml_post_counts["trash"][$one_wpml_lang]; 
     574            $status_data_attributes["all"]      .= " data-post-count-{$one_wpml_lang}='{$lang_post_count_all}' "; 
     575            $status_data_attributes["publish"]  .= " data-post-count-{$one_wpml_lang}='{$lang_post_count_publish}' "; 
     576            $status_data_attributes["trash"]    .= " data-post-count-{$one_wpml_lang}='{$lang_post_count_trash}' "; 
     577        } 
     578 
     579    } else { 
     580        $post_count = wp_count_posts($post_type); 
     581        $post_count_all = $post_count->publish + $post_count->future + $post_count->draft + $post_count->pending + $post_count->private; 
     582        $post_count_publish = $post_count->publish; 
     583        $post_count_trash = $post_count->trash; 
    511584    } 
    512585 
     
    552625                        $selected = "current"; 
    553626                    } 
    554                     $lang_out .= "<li><a class='cms_tvp_switch_lang $selected cms_tpv_switch_language_code_{$one_lang["language_code"]}' href='#'>$one_lang_details[display_name]</a> | </li>"; 
     627 
     628                    $lang_count = $wpml_post_counts["publish"][$one_lang["language_code"]] + $wpml_post_counts["draft"][$one_lang["language_code"]]; 
     629 
     630                    $lang_out .= " 
     631                        <li> 
     632                            <a class='cms_tvp_switch_lang $selected cms_tpv_switch_language_code_{$one_lang["language_code"]}' href='#'> 
     633                                $one_lang_details[display_name] 
     634                                <span class='count'>(" . $lang_count . ")</span> 
     635                            </a> | </li>"; 
    555636                } 
    556637                $lang_out = preg_replace('/ \| <\/li>$/', "</li>", $lang_out); 
     
    564645            echo '<div class="updated fade below-h2"><p>' . __("No posts found.", 'cms-tree-page-view') . '</p></div>'; 
    565646        } else { 
     647 
    566648            // start the party! 
     649 
    567650            ?> 
    568      
    569651            <ul class="cms-tpv-subsubsub"> 
    570                 <li><a class="cms_tvp_view_all <?php echo ($cms_tpv_view=="all") ? "current" : "" ?>" href="#"><?php _e("All", 'cms-tree-page-view') ?></a> |</li> 
    571                 <li><a class="cms_tvp_view_public <?php echo ($cms_tpv_view=="public") ? "current" : "" ?>" href="#"><?php _e("Public", 'cms-tree-page-view') ?></a> |</li> 
    572                 <li><a class="cms_tvp_view_trash <?php echo ($cms_tpv_view=="trash") ? "current" : "" ?>" href="#"><?php _e("Trash", 'cms-tree-page-view') ?></a></li> 
     652                <li> 
     653                    <a class="cms_tvp_view_all <?php echo ($cms_tpv_view=="all") ? "current" : "" ?>" href="#" <?php echo $status_data_attributes["all"] ?>> 
     654                        <?php _e("All", 'cms-tree-page-view') ?> 
     655                        <span class="count">(<?php echo $post_count_all ?>)</span> 
     656                    </a> | 
     657                </li> 
     658                <li> 
     659                    <a class="cms_tvp_view_public <?php echo ($cms_tpv_view=="public") ? "current" : "" ?>" href="#" <?php echo $status_data_attributes["publish"] ?>> 
     660                        <?php _e("Public", 'cms-tree-page-view') ?> 
     661                        <span class="count">(<?php echo $post_count_publish ?>)</span> 
     662                    </a> | 
     663                </li> 
     664                <li> 
     665                    <a class="cms_tvp_view_trash <?php echo ($cms_tpv_view=="trash") ? "current" : "" ?>" href="#" <?php echo $status_data_attributes["trash"] ?>> 
     666                        <?php _e("Trash", 'cms-tree-page-view') ?> 
     667                        <span class="count">(<?php echo $post_count_trash ?>)</span> 
     668                    </a> 
     669                </li> 
    573670     
    574671                <?php 
     
    590687                    </form> 
    591688                </li> 
     689 
    592690            </ul> 
    593691                 
     
    711809    $post_type = cms_tpv_get_selected_post_type(); 
    712810    $post_type_object = get_post_type_object($post_type); 
     811 
     812    if ( 'post' != $post_type ) { 
     813        $post_new_file = "post-new.php?post_type=$post_type"; 
     814    } else { 
     815        $post_new_file = 'post-new.php'; 
     816    } 
    713817     
    714818    ?> 
     
    718822            $page_title = _x(sprintf('%1$s Tree View', $post_type_object->labels->name), "headline of page with tree", "cms-tree-page-view"); 
    719823            echo $page_title; 
     824 
     825            // Add "add new" link the same way as the regular post page has 
     826            if ( current_user_can( $post_type_object->cap->create_posts ) ) { 
     827                echo ' <a href="' . esc_url( $post_new_file ) . '" class="add-new-h2">' . esc_html( $post_type_object->labels->add_new ) . '</a>'; 
     828            } 
     829 
     830 
     831 
     832 
    720833        ?></h2> 
    721834         
  • cms-tree-page-view/trunk/readme.txt

    r629645 r629831  
    9292== Changelog == 
    9393 
     94= 1.x = 
     95- Added "Add new"-link next to headline, to better match the regular post overview page + it makes it possible to add new pages/posts when there are no pages/posts added (previously there needed to be at least one post added to be able to add new posts) 
     96- Added post count in parenthesis after each post status. Also makes the page match the regular post overview page a it more. Works for both built in post types and custom post types + if WPML is installed it will show post count for each language too. 
     97 
    9498= 1.0 = 
    9599- New: create multiple pages at once! Add multiple pages faster than ever before! You can ever select if the new pages should be drafts or published. And ever drag and drop the pages to get the correct order even before adding them. I know - it's awesome! 
  • cms-tree-page-view/trunk/styles/styles.css

    r627924 r629831  
    4141} 
    4242 
     43.cms-tpv-subsubsub li a { 
     44    text-decoration: none; 
     45} 
     46 
    4347.cms-tpv-subsubsub li a.current { 
    4448    font-weight: bold; 
    45     text-decoration: none; 
    4649    color: black; 
     50} 
     51 
     52.cms-tpv-subsubsub li a.current .count { 
     53    font-weight: normal; 
     54    color: #999x; 
    4755} 
    4856 
Note: See TracChangeset for help on using the changeset viewer.