Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Portfolio {
- var $meta_fields = array('p-website','p-thumb','p-main');
- function Portfolio()
- {
- // Register custom post types
- register_post_type('portfolio', array(
- 'label' => __('Portfolio'),
- 'singular_label' => __('Portfolio'),
- 'public' => true,
- 'show_ui' => true, // UI in admin panel
- 'capability_type' => 'post',
- 'hierarchical' => false,
- 'rewrite' => array("slug" => "portfolio"), // Permalinks
- 'query_var' => "portfolio", // This goes to the WP_Query schema
- 'supports' => array('title', 'editor' /*,'custom-fields'*/) // Let's use custom fields for debugging purposes only
- ));
- // Register custom taxonomy
- register_taxonomy("type", array("portfolio"), array("hierarchical" => false, "label" => "Types", "singular_label" => "Type", "rewrite" => true));
- // Admin interface init
- add_action("admin_init", array(&$this, "admin_init"));
- // Insert post hook
- add_action("wp_insert_post", array(&$this, "wp_insert_post"), 10, 2);
- }
- // When a post is inserted or updated
- function wp_insert_post($post_id, $post = null)
- {
- if ($post->post_type == "portfolio")
- {
- // Loop through the POST data
- foreach ($this->meta_fields as $key)
- {
- $value = @$_POST[$key];
- if (empty($value))
- {
- delete_post_meta($post_id, $key);
- continue;
- }
- // If value is a string it should be unique
- if (!is_array($value))
- {
- // Update meta
- if (!update_post_meta($post_id, $key, $value))
- {
- // Or add the meta data
- add_post_meta($post_id, $key, $value);
- }
- }
- else
- {
- // If passed along is an array, we should remove all previous data
- delete_post_meta($post_id, $key);
- // Loop through the array adding new values to the post meta as different entries with the same name
- foreach ($value as $entry)
- add_post_meta($post_id, $key, $entry);
- }
- }
- }
- }
- function admin_init()
- {
- // Custom meta boxes for the edit podcast screen
- add_meta_box('p-website','Options',array(&$this,'meta_options'),'portfolio','side','low');
- }
- // Admin post meta contents
- function meta_options(){
- global $post;
- $custom = get_post_custom($post->ID);
- $length = $custom["p-website"][0];
- $thumb = $custom["p-thumb"][0];
- $main = $custom["p-main"][0];
- ?>
- <label>Website:</label><br /><p><input name="p-website" value="<?php echo $website; ?>" /></p><br />
- <?php
- function get_attachments($postID,$type,$theone){
- $args = array(
- 'post_type' => 'attachment',
- 'numberposts' => null,
- 'post_status' => null,
- 'post_parent' => $postID
- );
- $attachments = get_posts($args);
- if($attachments){
- foreach($attachments as $attachment){
- $image = wp_get_attachment_image_src($attachment->ID,'full');
- if($image == $theone){$select = ' checked="yes"';}else{$select = '';};
- echo '<p><input type="radio" name="p-'.$type.'" value="'.$image[0].'"'.$select.' /> <img src="'.$image[0].'" height="60" width="60" alt="" /></p>';
- }
- }
- else{
- echo '<p><em>Please upload images</em></p><br />';
- }
- }
- echo '<label>Thumnail</label><br />';
- get_attachments($post->ID,'thumb',$thumb);
- echo '<br /><label>Main</label><br />';
- get_attachments($post->ID,'main',$main);
- }
- }
- // Initiate the plugin
- add_action("init", "PortfolioInit");
- function PortfolioInit() { global $p30; $p30 = new Portfolio(); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement