[wp-trac] [WordPress Trac] #21995: (get/the)_archive_title and (get/the)_archive_description functions

WordPress Trac wp-trac at lists.automattic.com
Tue Sep 25 23:44:53 UTC 2012


#21995: (get/the)_archive_title and (get/the)_archive_description functions
-----------------------------+-----------------------------
 Reporter:  thomask          |       Type:  feature request
   Status:  new              |   Priority:  normal
Milestone:  Awaiting Review  |  Component:  General
  Version:                   |   Severity:  normal
 Keywords:                   |
-----------------------------+-----------------------------
 Current theme archive got problem with complexity - archive template is
 used for taxonomy, category, tag, author, date and custom post types
 archives and every type of archive got special function for showing title
 and special function for showing description.

 So now theme developers fight with two evils - one very big archive.php
 file with a lot of conditions, or tons of separate simple .php files for
 each archive type. See #21951 for example.

 Other problem of current solution is that templates are not future-proof -
 when new archive types are added, archive.php must be rewritten.

 My idea is to create 2 simple functions (+ 2 echoing)
 get_archive_title + the_archive_title
 get_archive_description + the_archive_description

 in those function would be all the complexity, which is now in the
 template, plus the filter, so something like


 {{{
 function get_archive_title() {
 if ( is_day() ) {
         $title = sprintf( __( 'Daily Archives: %s' ), '<span>' .
 get_the_date() . '</span>' );
 } elseif ( is_month() ) {
         $title = sprintf( __( 'Monthly Archives: %s' ), '<span>' .
 get_the_date( _x( 'F Y', 'monthly archives date format' ) ) . '</span>' );
 } elseif ( is_year() ) {
         $title = sprintf( __( 'Yearly Archives: %s' ), '<span>' .
 get_the_date( _x( 'Y', 'yearly archives date format' ) ) . '</span>' );
 } elseif ( is_tag() ) {
         $title = sprintf( __( 'Tag Archives: %s' ), '<span>' .
 single_tag_title( '', false ) . '</span>' );
 } elseif ( is_category() ) {
         $title = sprintf( __( 'Category Archives: %s' ), '<span>' .
 single_cat_title( '', false ) . '</span>' );
 } elseif ( is_post_type_archive() ) {
         $title =  sprintf( __( 'Archives: %s' ), '<span>' .
 post_type_archive_title( '', false ) . '</span>' );
 } else {
         $title = _e( 'Blog Archives' );
 }
 return ( add_filter ( 'get_archive_title', $title ) );
 }
 }}}

 (imo it could be a bit more complex, so that we could add a param to this
 function for simple rewritting the title for some particular type without
 filtering whole output)

 Finally the archive template would be as simple as


 {{{
 <header class="archive-header">
 <h1 class="archive-title"><?php the_archive_title() ?></h1>

 <div class="archive-meta"><?php the_archive_description ?></div>

 </header><!-- .archive-header -->
 }}}

 this way we will get all we need
 1. one archive file
 2. very short file without any conditions
 3. easy to filter the output
 4. future-proof as when adding new wp archive type, the function would be
 updated

 Of course, for backwards compatibility of current themes, this function
 can be copied to the theme functions.php as well with !if (function_exist(
 'get_archive_title'))

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/21995>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list