Plugin Directory

Changeset 843479


Ignore:
Timestamp:
01/23/2014 02:01:13 AM (12 years ago)
Author:
mikeselander
Message:

0.3.0 commit to trunk

Location:
simple-frontend-template-display/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • simple-frontend-template-display/trunk/readme.txt

    r829641 r843479  
    55Requires at least: 3.4
    66Tested up to: 3.8
    7 Stable tag: 0.2.0
     7Stable tag: 0.3.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3333== Upgrade Notice ==
    3434
     35= 0.3.0 =
     36Adds drop down items to show pages with the same page template (up to 15) and a banner to the landing page
     37
    3538= 0.2.0 =
    3639Adds a drop down item to show the page template filename & improves several methods
     
    4043
    4144== Changelog ==
     45
     46= 0.3.0 =
     47* Added get_similar_pages function to retrieve pages with the same template
    4248
    4349= 0.2.0 =
  • simple-frontend-template-display/trunk/simple-frontend-template-display.php

    r829641 r843479  
    44Plugin Name: Simple Frontend Template Display
    55Plugin URI: http://www.mikeselander.com/
    6 Description: Displays the current page template in the admin bar for quick & easy reference
    7 Version: 0.2
     6Description: Displays the current page template in the admin toolbar for quick & easy reference
     7Version: 0.3
    88Author: Mike Selander
    99Author URI: http://www.mikeselander.com/
     
    2020 * @author Mike Selander
    2121 * @since 0.0.0
    22  * @link      http://mikeselander.com
     22 * @link http://mikeselander.com
    2323 * @copyright 2013 Mike Selander
    2424 */
    2525class PageTemplateDisplay{
    2626
    27     const VERSION = '0.2.0';
     27    const VERSION = '0.3.0';
    2828
    2929    /**
     
    3737
    3838        add_action('admin_bar_menu', array( $this, "page_template_display" ), 500 );
     39        add_action('admin_bar_menu', array( $this, "get_similar_pages" ), 501 );
    3940
    4041    } // end __construct()
     
    5758            // if get_current_template_name returns - set the menu item
    5859            if ( $this->get_current_template_name() ) {
     60
    5961                $wp_admin_bar->add_node(
    6062                    array(
     
    6567                    )
    6668                );
     69
     70                // if get_current_page_slug returns - set the next menu item
    6771                if ( $this->get_current_page_slug() ) {
    6872                    $wp_admin_bar->add_node(
     
    7680                }
    7781
    78 
    79 
    8082            } // end if template name is returned
    8183
     
    127129    } // end get_current_page_slug()
    128130
     131    /**
     132     * Grabs other pages with the same template
     133     *
     134     * @access public
     135     * @since 0.3.0
     136     * @return list of pages with
     137     */
     138    public function get_similar_pages( $wp_admin_bar ){
     139        global $wp_query;
     140
     141        if (!is_super_admin() || !is_admin_bar_showing() )
     142            return;
     143
     144        // if you're not in the admin backend & it's a page
     145        if ( ( !is_admin() ) && ( is_page() ) ){
     146
     147            // define the variables
     148            $template = $this->get_current_page_slug();
     149            $post_id = $wp_query->post->ID;
     150            $i = 1;
     151
     152            // query the pages
     153            $args = array(
     154               'post_type'  => 'page',
     155               'meta_key'   => '_wp_page_template',
     156               'meta_value' => $template,
     157               'exclude'    => $post_id
     158            );
     159
     160            $pages = get_pages( $args );
     161
     162            // if the query returns results, add a header node
     163            if ( !empty( $pages ) ) {
     164
     165                $wp_admin_bar->add_node(
     166                    array(
     167                        'id'        => 'similar_pages',
     168                        'title'     => "<strong>".__( 'Similar Pages:', 'page_template' )."</strong>",
     169                        'parent'    => page_template,
     170                        'href'      => false
     171                    )
     172                );
     173
     174                // Loop through the results
     175                foreach( $pages as $page ){
     176
     177                    // Loop until we hit 15
     178                    if ( $i < 16 ) {
     179
     180                        $wp_admin_bar->add_node(
     181                            array(
     182                                'id'        => 'similar_page_'.$i,
     183                                'title'     => $page->post_title,
     184                                'parent'    => page_template,
     185                                'href'      => get_permalink($page->ID)
     186                            )
     187                        );
     188
     189                    } // end if
     190
     191                    $i++;
     192
     193                } // end foreach
     194
     195            } // end if have posts
     196
     197        } // end if !is_admin && is_page()
     198
     199    } // end get_similar_pages()
     200
    129201} // end PageTemplateDisplay
    130202
Note: See TracChangeset for help on using the changeset viewer.