-
-
Save candyappledesign/ebfb944e284a7a0b39babbb6cf35a81c to your computer and use it in GitHub Desktop.
Sidebars for custom post types in GeneratePress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* GeneratePress child theme functions and definitions. | |
* | |
* Add your custom PHP in this file. | |
* Only edit this file if you have direct access to it on your server (to fix errors if they happen). | |
*/ | |
function generatepress_child_enqueue_scripts() { | |
if ( is_rtl() ) { | |
wp_enqueue_style( 'generatepress-rtl', trailingslashit( get_template_directory_uri() ) . 'rtl.css' ); | |
} | |
} | |
add_action( 'wp_enqueue_scripts', 'generatepress_child_enqueue_scripts', 100 ); | |
/** | |
* Add is_tree function | |
*/ | |
function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath | |
global $post; // load details about this page | |
if(is_page()&&($post->post_parent==$pid||is_page($pid))) | |
return true; // we're at the page or at a sub page | |
else | |
return false; // we're elsewhere | |
}; | |
// Show Webinars sidebar for the custom post type tdiwebinars | |
add_filter( 'generate_sidebar_layout','cpt_tdiwebinars_sidebar_layout' ); | |
function cpt_tdiwebinars_sidebar_layout( $layout ) | |
{ | |
// If we are on a webinars single page, set the sidebar | |
if ( is_singular( 'tdiwebinars' ) ) | |
return 'webinars_sidebar'; | |
// Or else, set the regular layout | |
return $layout; | |
} | |
// Add Custom Sidebars | |
function page_widgets_init() { | |
register_sidebar( array( | |
'name' => 'Page Sidebar', | |
'id' => 'page_sidebar', | |
'before_widget' => '<aside class="widget_text">', | |
'after_widget' => '</aside>', | |
'before_title' => '<h2 class="widget-title">', | |
'after_title' => '</h2>', | |
) ); | |
register_sidebar( array( | |
'name' => 'Thermography Sidebar', | |
'id' => 'thermography_sidebar', | |
'before_widget' => '<aside class="widget_text">', | |
'after_widget' => '</aside>', | |
'before_title' => '<h2 class="widget-title">', | |
'after_title' => '</h2>', | |
) ); | |
register_sidebar( array( | |
'name' => 'Wellness Sidebar', | |
'id' => 'wellness_sidebar', | |
'before_widget' => '<aside class="widget_text">', | |
'after_widget' => '</aside>', | |
'before_title' => '<h2 class="widget-title">', | |
'after_title' => '</h2>', | |
) ); | |
register_sidebar( array( | |
'name' => 'Patient Resources Sidebar', | |
'id' => 'patient_resources_sidebar', | |
'before_widget' => '<aside class="widget_text">', | |
'after_widget' => '</aside>', | |
'before_title' => '<h2 class="widget-title">', | |
'after_title' => '</h2>', | |
) ); | |
register_sidebar( array( | |
'name' => 'Webinars Sidebar', | |
'id' => 'webinars_sidebar', | |
'before_widget' => '<aside class="widget_text">', | |
'after_widget' => '</aside>', | |
'before_title' => '<h2 class="widget-title">', | |
'after_title' => '</h2>', | |
) ); | |
} | |
add_action( 'widgets_init', 'page_widgets_init' ); | |
// Add the Custom Post Types | |
add_action ( 'init', 'create_post_type' ) ; | |
function create_post_type ( ) { | |
// Webinars | |
register_post_type ( 'tdiwebinars', | |
array ( | |
'labels' => array ( | |
'name' => __( 'TDI Webinars' ), | |
'singular_name' => __( 'TDI Webinar' ), | |
'add_new' => _x( 'Add a Webinar', 'tdiwebinar' ), | |
'all_items' => __( 'All Webinars' ), | |
'add_new_item' => __( 'Add a Webinar' ), | |
'edit_item' => __( 'Edit Webinar' ), | |
'new_item' => __( 'New Webinar' ), | |
'view_item' => __( 'View this Webinar' ), | |
'search_items' => __( 'Search Webinars' ), | |
'not_found' => __( 'No Matching Webinar Found' ) | |
), | |
'supports' => array ( | |
'title', | |
'editor', | |
'excerpt', | |
'thumbnail', | |
'custom-fields', | |
'revisions', | |
'author', | |
'custom-fields', | |
'tags' | |
), | |
'rewrite' => array ( | |
'slug' => 'tdiwebinars', | |
'with_front' => false | |
), | |
'show_in_rest' => true, | |
'label' => 'TDI Webinars', | |
'description' => 'TDI Webinars', | |
'public' => true, | |
'exclude_from_search' => true, | |
'show_in_nav_menus' => false, | |
'has_archive' => true, | |
'menu_icon' => 'dashicons-video-alt2' | |
) | |
) ; | |
// Resources | |
register_post_type ( 'tdiresources', | |
array ( | |
'labels' => array ( | |
'name' => __( 'TDI Resources' ), | |
'singular_name' => __( 'TDI Resource' ), | |
'add_new' => _x( 'Add a Resource', 'article' ), | |
'all_items' => __( 'All Resources' ), | |
'add_new_item' => __( 'Add a Resources' ), | |
'edit_item' => __( 'Edit Resource' ), | |
'new_item' => __( 'New Resource' ), | |
'view_item' => __( 'View this Resource' ), | |
'search_items' => __( 'Search Resources' ), | |
'not_found' => __( 'No Matching Resource Found' ) | |
), | |
'supports' => array ( | |
'title', | |
'editor', | |
'excerpt', | |
'thumbnail', | |
'custom-fields', | |
'page-attributes', | |
'revisions' | |
), | |
'rewrite' => array ( | |
'slug' => 'resources', | |
'with_front' => false | |
), | |
'show_in_rest' => true, | |
'label' => 'TDI Resources', | |
'description' => 'TDI Resources', | |
'public' => true, | |
'exclude_from_search' => true, | |
'show_in_nav_menus' => false, | |
'has_archive' => false, | |
'menu_icon' => 'dashicons-exerpt-view' | |
) | |
) ; | |
// Press Releases | |
register_post_type ( 'testing', | |
array ( | |
'labels' => array ( | |
'name' => __( 'Satellite' ), | |
'singular_name' => __( 'Satellite' ), | |
'add_new' => _x( 'Add a Satellite Location', 'testing' ), | |
'all_items' => __( 'Satellite Locations' ), | |
'add_new_item' => __( 'Add a Satellite Location' ), | |
'edit_item' => __( 'Edit Satellite Location' ), | |
'new_item' => __( 'New Satellite Location' ), | |
'view_item' => __( 'View this Satellite Location' ), | |
'search_items' => __( 'Search Satellite Locations' ), | |
'not_found' => __( 'No Matching Satellite Location Found' ) | |
), | |
'supports' => array ( | |
'title', | |
'thumbnail', | |
'custom-fields', | |
'revisions' | |
), | |
'rewrite' => array ( | |
'slug' => 'testing', | |
'with_front' => false | |
), | |
'show_in_rest' => true, | |
'label' => 'Off-Site Testing Locations', | |
'description' => 'Off-Site Testing Locations', | |
'public' => true, | |
'exclude_from_search' => true, | |
'show_in_nav_menus' => false, | |
'has_archive' => true, | |
'menu_icon' => 'dashicons-location-alt' | |
) | |
) ; | |
// Initialise custom post type | |
add_action('init', 'codex_custom_init'); | |
} | |
// Add Taxonomies for Custom Post Types | |
add_action( 'init', 'create_topics_hierarchical_taxonomy', 0 ); | |
//Create a custom taxonomy for Resources | |
function create_topics_hierarchical_taxonomy() { | |
// Add new taxonomy, make it hierarchical like categories | |
$labels = array( | |
'name' => _x( 'Services Provided', 'taxonomy general name' ), | |
'singular_name' => _x( 'Service Provided', 'taxonomy singular name' ), | |
'search_items' => __( 'Search Services Provided' ), | |
'all_items' => __( 'All Services Provided' ), | |
'parent_item' => __( 'Parent Service' ), | |
'parent_item_colon' => __( 'Parent Service:' ), | |
'edit_item' => __( 'Edit Service' ), | |
'update_item' => __( 'Update Service' ), | |
'add_new_item' => __( 'Add New Service' ), | |
'new_item_name' => __( 'New Service Name' ), | |
'menu_name' => __( 'Services Provided' ), | |
); | |
register_taxonomy('service',array('tdiresources'), array( | |
'hierarchical' => true, | |
'labels' => $labels, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'query_var' => true, | |
'rewrite' => array( 'slug' => 'services' ), | |
)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Template Name: TDI Webinars | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; // Exit if accessed directly. | |
} | |
get_header(); ?> | |
<div id="primary" <?php generate_do_element_classes( 'content' ); ?>> | |
<main id="main" <?php generate_do_element_classes( 'main' ); ?>> | |
<?php | |
/** | |
* generate_before_main_content hook. | |
* | |
* @since 0.1 | |
*/ | |
do_action( 'generate_before_main_content' ); | |
while ( have_posts() ) : the_post(); | |
get_template_part( 'content', 'single' ); | |
// If comments are open or we have at least one comment, load up the comment template. | |
if ( comments_open() || '0' != get_comments_number() ) : | |
/** | |
* generate_before_comments_container hook. | |
* | |
* @since 2.1 | |
*/ | |
do_action( 'generate_before_comments_container' ); | |
?> | |
<div class="comments-area"> | |
<?php comments_template(); ?> | |
</div> | |
<?php | |
endif; | |
endwhile; | |
/** | |
* generate_after_main_content hook. | |
* | |
* @since 0.1 | |
*/ | |
do_action( 'generate_after_main_content' ); | |
?> | |
</main><!-- #main --> | |
</div><!-- #primary --> | |
<?php | |
/** | |
* generate_after_primary_content_area hook. | |
* | |
* @since 2.0 | |
*/ | |
do_action( 'generate_after_primary_content_area' ); | |
generate_construct_sidebars(); | |
get_footer(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment