widgets for artister og program, custom post for artist

This commit is contained in:
Sjur Hernes committed 2011-07-03 11:45:50 +02:00
1 parent 5b27f5079e
commit 8889dfadfc
7 files changed
+229 -5

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
wp-config.php
*~
+3
View File
@@ -0,0 +1,3 @@
[submodule "wp-content/plugins/neuf-events"]
path = wp-content/plugins/neuf-events
url = git@github.com:neuf/neuf-events.git
+3 -3
View File
@@ -16,13 +16,13 @@
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'oyvinbak');
define('DB_NAME', 'studio11');
/** MySQL database username */
define('DB_USER', 'oyv_wordpress');
define('DB_USER', 'studio11');
/** MySQL database password */
define('DB_PASSWORD', 'LGwW35HRPcjXNcmd');
define('DB_PASSWORD', 'studio11');
/** MySQL hostname */
define('DB_HOST', 'localhost');
@@ -0,0 +1,170 @@
<?php
/*
Plugin Name: studio-artist
Plugin URI: http://www.studentersamfundet.no
Description: Plugin to manage artists for studio11
Version 0.1
Author: Sjur Hernes
Author URI: grey.sjux.net
License: GPL v2 or later
*/
?>
<?php
if (!class_exists("StudioArtist")) {
class StudioArtist{
function StudioArtist(){
/**
Create the fields the post type should have
*/
function studio_artist_post_type() {
register_post_type(
'artist',
array(
'labels' => array(
'name' => __( 'Artister' ),
'singular_name' => __( 'Artist' ),
'add_new' => __( 'Legg til ny artist' ),
'add_new_item' => __( 'Legg til ny artist' ),
'edit_item' => __( 'Rediger artist' ),
'new_item' => __( 'Legg til ny artist' ),
'view_item' => __( 'Vis artist' ),
'search_items' => __( 'Søk etter artist' ),
'not_found' => __( 'ingen artister funnet' ),
'not_found_in_trash' => __( 'ingen artister funnet i søppel' )
),
'public' => true,
'publicly_queryable' => true,
'query_var' => 'artist',
'capability_type' => 'post',
'supports' => array(
'title',
'editor',
'thumbnail',
),
'register_meta_box_cb' => 'add_studart_metaboxes',
)
);
}
/*******************************************************************************
********************************************************************************
** Add meta-boxes ***********************************************************
********************************************************************************
*******************************************************************************/
function add_studart_metaboxes() {
add_meta_box(
'studio_artist_pop',
__('Artiststørrelse'),
'studio_artist_custom_box',
'artist',
'side',
'high'
);
}
/*******************************************************************************
********************************************************************************
** Eventtype metabox ********************************************************
********************************************************************************
*******************************************************************************/
function studio_artist_custom_box(){
global $post;
$artist_pop = get_post_meta($post->ID, 'studio_artist_pop' , true);
$artist_link = get_post_meta($post->ID, 'studio_artist_link', true);
echo "Størrelse:";
echo '<select name="studio_artist_pop">';
echo $artist_pop;
$types = array( array('name'=>'Singstar/Guitarhero', 'size' => 12),
array('name'=>'Liten Artist', 'size' => 15),
array('name'=>'Mellomstor Artist', 'size' => 18),
array('name'=>'Stor', 'size' => 21),
array('name'=>'Enorm', 'size' => 24),
);
foreach($types as $type){
echo '<option value="' . $type['size'] . '"';
if($type['size'] == $artist_pop)
echo ' selected="selected"';
echo '>' . $type['name'] . '</option>';
}
echo '</select>';
echo '<br />Artisturl:<br /><input type="text" name="studio_artist_link" value="'.$artist_link.'" />';
}
/**
* When the post is saved, saves our custom data
*/
function studio_artist_save_info( $post_id ) {
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id;
if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id;
// Get posted data
$studart['studio_artist_pop'] = $_POST['studio_artist_pop' ];
$studart['studio_artist_link'] = $_POST['studio_artist_link'];
foreach($studart as $key=>$value)
if ( !update_post_meta($post_id, $key, $value))
add_post_meta($post_id, $key, $value, true);
return $post_id;
}
/** View of the custom page */
function studio_artist_list() {
global $post, $wp_locale;
$artister = new WP_Query( array('post_type' => 'artist','posts_per_page' => -1,'order' => 'ASC' ) );
$html = '';
if ( $artister->have_posts() ) {
$html .= '<ul class="artist-table">';
while ( $artister->have_posts() ) {
$artister->the_post();
$size = get_post_meta($post->ID, 'studio_artist_pop', true);
$html .= ' <li class="title" style="padding-right:10px; font-size:'.$size.'px"><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
}
$html .= '</ul><!-- .artist-table -->';
}
return $html;
}
}
}
}
if (class_exists("StudioArtist")) {
$studio_artist_object = new StudioArtist();
}
if ( isset($studio_artist_object)){
add_action( 'init', 'studio_artist_post_type', 0);
add_action( 'save_post', 'studio_artist_save_info');
add_shortcode( 'studio-artist-list', 'studio_artist_list' );
}
?>
+48
View File
@@ -15,3 +15,51 @@ function studio11_widgets_init() {
}
/** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
add_action( 'widgets_init', 'studio11_widgets_init' );
class Program_Widget extends WP_Widget {
function Program_Widget() { parent::WP_Widget(false, 'Program'); }
function form($instance) {}
function update($new_instance, $old_instance) { return $new_instance; }
function widget($args, $instance) {
global $post, $wp_locale;
$args['title'] = 'Program';
$events = new WP_Query( array('post_type' => 'event','posts_per_page' => -1,'meta_key' => 'neuf_events_starttime','orderby' => 'meta_value','order' => 'ASC') );
echo $args['before_widget'] . $args['before_title'] . $args['title'] . $args['after_title'];
if ( $events->have_posts() ) {
echo '<ul id="event-widget">';
while ( $events->have_posts() ) {
$events->the_post();
echo '<li>' . date("d/m", get_post_meta($post->ID, 'neuf_events_starttime', true)) . ' | <a href="' . get_permalink() . '">' . get_the_title() . '</a>';
} echo '</ul>';
wp_reset_query();
} echo $args['after_widget'];
}
}
class Artist_Widget extends WP_Widget {
function Artist_Widget() { parent::WP_Widget(false, 'Artister'); }
function form($instance) {}
function update($new_instance, $old_instance) { return $new_instance; }
function widget($args, $instance) {
global $post, $wp_locale;
$args['title'] = 'Artister';
$studart = new WP_Query( array('post_type' => 'artist', 'posts_per_page' => -1,'meta_key' => 'studio_artist_pop','orderby' => 'meta_value', 'order' => 'ASC'));
echo $args['before_widget'] . $args['before_title'] . $args['title'] . $args['after_title'];
if ( $studart->have_posts() ) {
while ( $studart->have_posts() ) {
$studart->the_post();
echo get_post_meta($post->ID, 'studio_artist_pop', true);
$link = get_post_meta($post->ID, 'studio_artist_link', true) ? get_post_meta($post->ID, 'studio_artist_link', true) : get_permalink();
echo '<p style="font-size:'.get_post_meta($post->ID, 'studio_artist_pop', true).'px"><a href="' . $link . '">' . get_the_title() . '</a></p>';
}
} echo $args['after_widget'];
}
}
register_widget('Program_Widget');
register_widget('Artist_Widget');
+2 -2
View File
@@ -21,8 +21,8 @@
*/
if ( ! dynamic_sidebar( 'left-primary-widget-area' ) ) : ?>
<?php dynamic_sidebar( 'secondary-widget-area' ); ?>
<?php endif; // end primary widget area ?>
<?php dynamic_sidebar( 'left-primary-widget-area' ); ?>
<?php endif; // end primary widget area ?>
</ul>
</div><!-- #primary .widget-area -->
@@ -506,3 +506,4 @@ function twentyten_posted_in() {
);
}
endif;