I'm using wordpress codestar options framework to build a wordpress theme, for that i need to do following list of things:
add featured image support to the theme
add a custom post type called "institutions", add metabox options for that post type with the following list: text type, the title is features; select type, the title is regions with two options; gallery type, the title is gallery, repeater type, the title is bulletpoints; text type, the title is montly price; text type, the title is address; text type, the title is type;
please write style.css sample theme declaration comment
please generate the code for me, thanks.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
// Add featured image support to the theme
function add_featured_image_support() {
add_post_type_support( 'institution', 'post-thumbnails', 'title', 'editor' );
}
add_action( 'after_setup_theme', 'add_featured_image_support' );
// Custom post type "institutions"
function create_institution_post_type() {
$args = array(
'public' => true,
'label' => 'Institutions',
'supports' => array( 'title', 'editor', 'thumbnail' ),
'has_archive' => true,
'menu_icon' => 'dashicons-admin-journal',
'rewrite' => array( 'slug' => 'institutions' ),
);
register_post_type( 'institution', $args );
}
add_action( 'init', 'create_institution_post_type' );
// Metabox for "Institutions" post type
function add_institution_metaboxes() {
add_meta_box( 'institution_details', 'Institution Details', 'institution_metabox_callback', 'institution', 'normal', 'high' );
}
add_action( 'add_meta_boxes', 'add_institution_metaboxes' );
function institution_metabox_callback( $post ) {
wp_nonce_field( 'save_institution_details_data', 'institution_details_meta_box_nonce_field' );
$type = get_post_meta( $post->ID, '_institution_type', true );
$title = get_post_meta( $post->ID, '_institution_title', true );
$regions = get_post_meta( $post->ID, '_institution_regions', true );
$gallery = get_post_meta( $post->ID, '_institution_gallery', true );
$bulletpoints = get_post_meta( $post->ID, '_institution_bulletpoints', true );
$price = get_post_meta( $post->ID, '_institution_price', true );
$address = get_post_meta( $post->ID, '_institution_address', true );
$institution_type = get_post_meta( $post->ID, '_institution_type', true );
// Text input for "Type"
echo '<label for="institution_type">Type:</label>';
echo '<input type="text" id="institution_type" name="institution_type" value="' . esc_attr( $type ) . '" />';
// Select field for "Regions"
echo '<label for="institution_regions">Regions:</label>';
echo '<select id="institution_regions" name="institution_regions">';
echo '<option value="option1" ' . selected( $regions[0], 'option1', false ) . '>Option 1</option>';
echo '<option value="option2" ' . selected( $regions[1], 'option2', false ) . '>Option 2</option>';
echo '</select>';
// Gallery repeater for "Gallery"
echo '<label for="institution_gallery">Gallery:</label>';
echo '<ul>';
foreach ( $gallery as $index => $image_url ) {
echo '<li>';
echo '<input type="hidden" name="institution_gallery_' . $index . '" value="' . esc_attr( $image_url ) . '" />';
echo '<img src="' . esc_url( $image_url ) . '" alt="" />';
echo '</li>';
}
echo '</ul>';
// Text input for "Bulletpoints"
echo '<label for="institution_bulletpoints">Bulletpoints:</label>';
echo '<input type="text" id="institution_bulletpoints" name="institution_bulletpoints" value="' . esc_attr( $bulletpoints ) . '" />';
// Text input for "Price"
echo '<label for="institution_price">Price:</label>';
echo '<input type="text" id="institution_price" name="institution_price" value="' . esc_attr( $price ) . '" />';
// Text input for "Address"
echo '<label for="institution_address">Address:</label>';
echo '<input type="text" id="institution_address" name="institution_address" value="' . esc_attr( $address ) . '" />';
// Text input for "Type"
echo '<label for="institution_type">Type:</label>';
echo '<input type="text" id="institution_type" name="institution_type" value="' . esc_attr( $institution_type ) . '" />';
}
// Save metabox data
function save_institution_details_data( $post_id ) {
// Check if the nonce is set and valid
if ( ! isset( $_POST['institution_details_meta_box_nonce_field'] ) || ! wp_verify_nonce( $_POST['institution_details_meta_box_nonce_field'], 'save_institution_details_data' ) ) {
return false;
}
// Check if the current user has permission to edit the post
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return false;
}
// Update post meta data
update_post_meta( $post_id, '_institution_type', $_POST['institution_type'] );
update_post_meta( $post_id, '_institution_regions', $_POST['institution_regions'] );
update_post_meta( $post_id, '_institution_gallery', $_POST['institution_gallery'] );
update_post_meta( $post_id, '_institution_bulletpoints', $_POST['institution_bulletpoints'] );
update_post_meta( $post_id, '_institution_price', $_POST['institution_price'] );
update_post_meta( $post_id, '_institution_address', $_POST['institution_address'] );
update_post_meta( $post_id, '_institution_type', $_POST['institution_type'] );
// Save post data
if ( ! wp_update_post( array( 'ID' => $post_id, 'post_title' => $_POST['post_title'], 'post_content' => $_POST['post_content'] ) ) ) {
return false;
}
return true;
}
add_action( 'save_post', 'save_institution_details_data' );
css
/*
Theme Name: My Custom Theme
Theme URI: https://example.com/my-custom-theme/
Author: Your Name
Author URI: https://example.com
Description: A custom WordPress theme with featured image support and a custom post type "Institutions".
Version: 1.0
License: GNU General Public License v2 or later
License URI: https://www.creativecommons.org/licenses/by-sa/2.0/
Tags: custom-theme, featured-image, institutions
Text Domain: my-custom-theme
*/