public
Created

CPT archive pages

  • Download Gist
cpt-archive.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
<?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();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.