Making WordPress.org


Ignore:
Timestamp:
06/16/2014 11:56:42 PM (10 years ago)
Author:
coffee2code
Message:

Handbook plugin: abstract post-type handling to allow for multiple post-type usage, namely for Devhub. props nicolealleyinteractivecom. See #250

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/table-of-contents.php

    r609 r705  
    66 */
    77class WPorg_Handbook_TOC {
    8     protected $post_type = 'handbook';
     8    protected $post_types = array();
    99
    1010    protected $styles = '<style> .toc-jump { text-align: right; font-size: 12px; } .page .toc-heading { margin-top: -50px; padding-top: 50px !important; }</style>';
    1111
    12     function __construct() {
     12    function __construct( $post_types ) {
     13        $this->post_types = $post_types;
    1314        add_action( 'template_redirect', array( $this, 'load_filters' ) );
    1415    }
    1516
    1617    function load_filters() {
    17         if ( is_singular( $this->post_type ) )
     18        $this->post_types = array_map( array( $this, 'append_suffix' ), $this->post_types );
     19
     20        if ( is_singular( $this->post_types ) )
    1821            add_filter( 'the_content', array( $this, 'add_toc' ) );
     22    }
     23
     24    function append_suffix( $t ) {
     25        if ( 'handbook' == $t )
     26            return $t;
     27
     28        return $t . '-handbook';
    1929    }
    2030
     
    3242            $pages_header = 'h3';
    3343
    34         if ( $pages = wp_list_pages( array( 'child_of' => get_the_ID(), 'echo' => false, 'title_li' => false, 'post_type' => $this->post_type ) ) ) 
    35             $toc .= "<$pages_header>Pages</$pages_header><ul class=\"items\">$pages</ul>";
     44        if ( $pages = wp_list_pages( array( 'child_of' => get_the_ID(), 'echo' => false, 'title_li' => false, 'post_type' => $this->post_type ) ) )
     45            $toc .= "<$pages_header>Pages</$pages_header><ul class=\"items\">$pages</ul>";
    3646
    3747        if ( $items ) {
    3848            $toc .= $this->styles;
    3949            $toc .= '<div class="table-of-contents">';
    40             $toc .= "<$contents_header>Topics</$contents_header><ul class=\"items\">";
     50            $toc .= "<$contents_header>Contents</$contents_header><ul class=\"items\">";
    4151            $last_item = false;
    4252            foreach ( $items as $item ) {
Note: See TracChangeset for help on using the changeset viewer.