Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Add adventure custom post type #33

Merged
merged 10 commits into from
Apr 12, 2018
37 changes: 37 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Theme functions file.
*
* @package WPAMPTheme
*/

// Include required classes.
require_once get_template_directory() . '/includes/class-amp-travel-cpt.php';


if ( ! function_exists( 'travel_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function travel_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on WPAMPTheme, use a find and replace
* to change 'travel' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'travel', get_template_directory() . '/languages' );

add_theme_support( 'amp', array() );

// init custom post type.
new AMP_Travel_CTP();
}
endif;

// Hook into theme after setup.
add_action( 'after_setup_theme', 'travel_setup' );
129 changes: 129 additions & 0 deletions includes/class-amp-travel-cpt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php
/**
* Class for Travel Custom Post Type.
*
* @package WPAMPTheme
*/

/**
* Class AMP_Travel_CTP
*
* @package WPAMPTheme
*/
class AMP_Travel_CTP {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a typo, should probably be _CPT instead of _CTP.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops yes, will fix


/**
* The post type slug.
*
* @var string
*/
const POST_TYPE_SLUG = 'adventure';

/**
* AMP_Travel_CTP constructor.
*/
public function __construct() {
add_action( 'init', array( $this, 'setup' ) );
}

/**
* Setup the Custom post type support.
*/
public function setup() {
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );

// Image Sizes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a phpdoc comment to describe the filter.

$image_sizes = apply_filters( 'amp_travel_image_sizes', array(
'1600x900',
'1400x787',
'1200x675',
'1040x585',
'768x432',
'727x409',
'600x338',
'500x281',
'375x211',
'335x188',
'320x180',
'280x158',
'240x135',
'160x90',
'122x67',
Copy link
Contributor

@kienstra kienstra Apr 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all of these image sizes needed?

You know more about the specifics than I do. But it seems excessive to create 15 image sizes for every image uploaded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kienstra - no idea. but it's a good point. I took these from the ampconf theme as a starting point. I'll reduce it down to what I think should be needed for the current blocks, etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something that we should revisit. But I'm going to merge this PR to unblock other PRs.

) );

// Custom image sizes.
foreach ( $image_sizes as $size ) {
$dimensions = explode( 'x', $size );
add_image_size( 'travel-' . $size, $dimensions[0], $dimensions[1], true );
}

// Register the post type.
$this->register_post_type();
}

/**
* Register 'adventure' post type.
*/
private function register_post_type() {
$labels = array(
'name' => _x( 'Adventures', 'Post type general name', 'travel' ),
'singular_name' => _x( 'Adventure', 'Post type singular name', 'travel' ),
'menu_name' => _x( 'Adventures', 'Admin Menu text', 'travel' ),
'name_admin_bar' => _x( 'Adventure', 'Add New on Toolbar', 'travel' ),
'add_new' => __( 'Add New', 'travel' ),
'add_new_item' => __( 'Add New Adventure', 'travel' ),
'new_item' => __( 'New Adventure', 'travel' ),
'edit_item' => __( 'Edit Adventure', 'travel' ),
'view_item' => __( 'View Adventure', 'travel' ),
'all_items' => __( 'All Adventures', 'travel' ),
'search_items' => __( 'Search Adventures', 'travel' ),
'parent_item_colon' => __( 'Parent Adventures:', 'travel' ),
'not_found' => __( 'No adventures found.', 'travel' ),
'not_found_in_trash' => __( 'No adventures found in Trash.', 'travel' ),
'featured_image' => _x( 'Adventure Cover Image', 'Overrides the “Featured Image” phrase for this post type.', 'travel' ),
'set_featured_image' => _x( 'Set cover image', 'Overrides the “Set featured image” phrase for this post type.', 'travel' ),
'remove_featured_image' => _x( 'Remove cover image', 'Overrides the “Remove featured image” phrase for this post type.', 'travel' ),
'use_featured_image' => _x( 'Use as cover image', 'Overrides the “Use as featured image” phrase for this post type.', 'travel' ),
'archives' => _x( 'Adventure archives', 'The post type archive label used in nav menus. Default “Post Archives”.', 'travel' ),
'insert_into_item' => _x( 'Insert into adventure', 'Overrides the “Insert into post”/”Insert into page” phrase (used when inserting media into a post).', 'travel' ),
'uploaded_to_this_item' => _x( 'Uploaded to this adventure', 'Overrides the “Uploaded to this post”/”Uploaded to this page” phrase (used when viewing media attached to a post).', 'travel' ),
'filter_items_list' => _x( 'Filter adventures list', 'Screen reader text for the filter links heading on the post type listing screen. Default “Filter posts list”/”Filter pages list”.', 'travel' ),
'items_list_navigation' => _x( 'Adventures list navigation', 'Screen reader text for the pagination heading on the post type listing screen. Default “Posts list navigation”/”Pages list navigation”.', 'travel' ),
'items_list' => _x( 'Adventures list', 'Screen reader text for the items list heading on the post type listing screen. Default “Posts list”/”Pages list”.', 'travel' ),
);

$args = array(
'labels' => $labels,
'description' => __( 'Adventure Custom Post Type for travel theme.', 'travel' ),
'public' => true,
'exclude_from_search' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing show_in_rest which is required for Gutenberg.

'menu_position' => 20,
'menu_icon' => 'dashicons-location-alt',
'capability_type' => 'post',
'hierarchical' => false,
'supports' => array(
'title',
'editor',
'thumbnail',
),
'has_archive' => true,
'rewrite' => array(
'slug' => self::POST_TYPE_SLUG,
),
'query_var' => true,
'can_export' => true,
);

register_post_type( self::POST_TYPE_SLUG, $args );
}
}
10 changes: 10 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
/**
* Placeholder for index.php file.
*
* @package WPAMPTheme
*/

?>

<html></html>
17 changes: 17 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*!
Theme Name: Travel
Theme URI: https://wordpress.org/themes/amp-travel
Author: XWP
Author URI: https://xwp.co
Description: WordPress theme built using AMP to make your site lightning fast.
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: LICENSE
Text Domain: travel
Tags: custom-background, custom-logo, custom-menu, featured-images, threaded-comments, translation-ready

This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you've learned with others.

This stylesheet is intentionally left blank.
*/