Snippets
Created by
Benjamin J. DeLong
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 105 106 | <?php
/*
Author: bozdoz
Author URI: https://twitter.com/bozdoz/
Plugin Name: Rachael Simonds Media Posts
Description: A plugin for creating Photography, Print, Drawing, and Other media types for Rachael Simonds.
Version: 0.1.0
License: GPL2
*/
add_action( 'init', 'add_all_custom_posts' );
function add_all_custom_posts() {
$allmedia = array(
array(
'title' => 'Photography',
'name' => 'photo'
),
array(
'title' => 'Print',
'name' => 'print'
),
array(
'title' => 'Drawing',
'name' => 'drawing'
),
array(
'title' => 'Other Media',
'name' => 'other'
),
array(
'title' => 'Photography',
'name' => 'photo'
),
);
function getArgs ($arr) {
extract($arr);
$labels = array(
'name' => _x( "$title", 'post type general name' ),
'singular_name' => _x( "$name", 'post type singular name' ),
'add_new' => _x( "Add New", "$name" ),
'add_new_item' => __( "Add New $name" ),
'edit_item' => __( "Edit $name" ),
'new_item' => __( "New $name" ),
'all_items' => __( "All $title" ),
'view_item' => __( "View $name" ),
'search_items' => __( "Search $title" ),
'not_found' => __( "No $title found" ),
'not_found_in_trash' => __( "No $title found in the Trash" ),
'parent_item_colon' => '',
'menu_name' => "$title"
);
$args = array(
'labels' => $labels,
'description' => "Holds our $title and $name specific data",
'public' => true,
'menu_position' => 5,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
'has_archive' => true,
);
return $args;
}
foreach ($allmedia as $arr) {
register_post_type($arr['name'], getArgs($arr) );
}
}
/* shortcode for displaying all custom media posts */
add_shortcode('rachael-simonds-media', 'displayMedia');
function displayMedia () {
$args = array(
'posts_per_page' => 40,
'orderby' => 'id',
'order' => 'DESC',
'post_type' => 'team',
'post_status' => 'publish');
$teams = get_posts( $args );
$html = '<div class="team-list">';
foreach ( $teams as $team ) {
$thumb_url = get_the_post_thumbnail_url($team->ID, array(400,400));
$permalink = get_permalink($team->ID);
$position = get_post_meta($team->ID, 'team_position', true);
$html .= "<a class=\"img-holder\"
href=\"$permalink\"
title=\"$team->post_title\">
<span class=\"img img-block\"
style=\"background-image:url( $thumb_url );\">
<span class=\"img-screen\">
<span class=\"center-vertical\">
<span class=\"img-title\">$team->post_title</span>
<span class=\"img-subtitle\">$position</span>
</span>
</span>
</span>
</a>";
}
$html .= '</div>';
wp_reset_postdata();
return $html;
}
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.