Skip to content

Instantly share code, notes, and snippets.

@norcross
Created January 31, 2013 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save norcross/4687698 to your computer and use it in GitHub Desktop.
Save norcross/4687698 to your computer and use it in GitHub Desktop.
CPT archive pages
<?php
// Start up the engine
class CPT_Archive_Content
{
/**
* Static property to hold our singleton instance
* @var CPT_Archive_Content
*
* @since 1.0
*/
static $instance = false;
/**
* This is our constructor, which is private to force the use of
* getInstance() to make this a Singleton
*
* @return CPT_Archive_Content
*
* @since 1.0
*/
public function __construct() {
add_action ( 'admin_menu', array( $this, 'menu_create' ) );
}
/**
* If an instance exists, this returns it. If not, it creates one and
* retuns it.
*
* @return CPT_Archive_Content
*/
public static function getInstance() {
if ( !self::$instance )
self::$instance = new self;
return self::$instance;
}
/**
* Post type helper
*
* @return CPT_Archive_Content
*/
private function post_types() {
// grab post types
$args = array(
'public' => true,
'_builtin' => false
);
$output = 'objects';
$types = get_post_types($args, $output);
return $types;
}
/**
* call loop of types and add page
*
* @return CPT_Archive_Content
*/
public function menu_create() {
// get post type array
$types = $this->post_types();
foreach ($types as $type ):
// variables
$slug = $type->name;
$name = $type->label;
// page call
add_submenu_page('edit.php?post_type='.$slug.'', __( $name .' Archives', 'cptarch' ), __( $name .' Archives', 'cptarch' ), 'edit_posts', $slug.'-archive', array( $this, $slug.'_archive_layout' ));
endforeach;
}
public function layout_setup() {
// get post type array
$types = $this->post_types();
foreach ($types as $type ):
// variables
$slug = $type->name;
// NEED DYNAMIC FUNCTION HERE
endforeach;
}
/// end class
}
// Instantiate our class
$CPT_Archive_Content = new CPT_Archive_Content();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment