Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Piha functions and definitions
- *
- * @package WordPress
- * @subpackage Piha
- */
- /*-----------------------------------------------------------------------------------*/
- /* Make theme available for translation
- /* Translations can be filed in the /languages/ directory
- /*-----------------------------------------------------------------------------------*/
- load_theme_textdomain( 'piha', TEMPLATEPATH . '/languages' );
- $locale = get_locale();
- $locale_file = TEMPLATEPATH . "/languages/$locale.php";
- if ( is_readable( $locale_file ) )
- require_once( $locale_file );
- /*-----------------------------------------------------------------------------------*/
- /* Set the content width based on the theme's design and stylesheet.
- /*-----------------------------------------------------------------------------------*/
- if ( ! isset( $content_width ) )
- $content_width = 680;
- /*-----------------------------------------------------------------------------------*/
- /* Tell WordPress to run piha() when the 'after_setup_theme' hook is run.
- /*-----------------------------------------------------------------------------------*/
- add_action( 'after_setup_theme', 'piha' );
- if ( ! function_exists( 'piha' ) ):
- /*-----------------------------------------------------------------------------------*/
- /* Create the Piha Theme Options Page
- /*-----------------------------------------------------------------------------------*/
- require_once ( get_template_directory() . '/includes/theme-options.php' );
- /*-----------------------------------------------------------------------------------*/
- /* Call JavaScript Scripts for Piha (Fitvids for Elasic Videos and Custom)
- /*-----------------------------------------------------------------------------------*/
- add_action('wp_enqueue_scripts','piha_scripts_function');
- function piha_scripts_function() {
- wp_enqueue_script( 'fitvids', get_template_directory_uri() . '/js/jquery.fitvids.js', false, '1.0');
- wp_enqueue_script( 'respond', get_template_directory_uri() . '/js/respond.min.js', false, '1.0.1');
- wp_enqueue_script( 'custom', get_template_directory_uri() . '/js/custom.js', false, '1.0.1');
- }
- /*-----------------------------------------------------------------------------------*/
- /* Sets up theme defaults and registers support for WordPress features.
- /*-----------------------------------------------------------------------------------*/
- function piha() {
- // This theme styles the visual editor with editor-style.css to match the theme style.
- add_editor_style();
- // This theme uses post thumbnails
- add_theme_support( 'post-thumbnails' );
- // Add default posts and comments RSS feed links to head
- add_theme_support( 'automatic-feed-links' );
- // This theme uses wp_nav_menu() in one location.
- register_nav_menus( array(
- 'primary' => __( 'Primary Navigation', 'piha' ),
- 'top' => __( 'Optional Top Navigation (no sub menus supported)', 'piha' ),
- 'footer' => __( 'Optional Footer Navigation (no sub menus supported)', 'piha' )
- ) );
- // Add support for Post Formats
- add_theme_support( 'post-formats', array( 'aside', 'status', 'link', 'quote', 'chat', 'image', 'gallery', 'video', 'audio' ) );
- // This theme allows users to set a custom background
- add_custom_background();
- // The default header text color
- define( 'HEADER_TEXTCOLOR', '222' );
- // By leaving empty, we allow for random image rotation.
- define( 'HEADER_IMAGE', '' );
- // The height and width of your custom header. You can hook into the theme's own filters to change these values.
- // Add a filter to piha_header_image_width and piha_header_image_height to change these values.
- define( 'HEADER_IMAGE_WIDTH', apply_filters( 'piha_header_image_width', 750 ) );
- define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'piha_header_image_height', 200 ) );
- // Don't support text inside the header image.
- define( 'NO_HEADER_TEXT', true );
- // Add a way for the custom header to be styled in the admin panel that controls
- // custom headers. See piha_admin_header_style(), below.
- add_custom_image_header( '', 'piha_admin_header_style' );
- // ... and thus ends the changeable header business.
- // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
- register_default_headers( array(
- 'numbers' => array(
- 'url' => '%s/images/headers/headerimage.jpg',
- 'thumbnail_url' => '%s/images/headers/headerimage-thumbnail.jpg',
- /* translators: header image description */
- 'description' => __( 'Numbers', 'piha' )
- ),
- 'mosaik' => array(
- 'url' => '%s/images/headers/headerimage02.jpg',
- 'thumbnail_url' => '%s/images/headers/headerimage02-thumbnail.jpg',
- /* translators: header image description */
- 'description' => __( 'Mosaik', 'piha' )
- )
- ) );
- }
- endif;
- if ( ! function_exists( 'piha_admin_header_style' ) ) :
- /*-----------------------------------------------------------------------------------*/
- /* Styles the header image displayed on the Appearance > Header admin panel.
- /* Referenced via add_custom_image_header() in piha_setup().
- /*-----------------------------------------------------------------------------------*/
- function piha_admin_header_style() {
- ?>
- <style type="text/css">
- /* Shows the same border as on front end */
- #heading {
- border-bottom: 1px solid #000;
- border-top: 4px solid #000;
- }
- /* If NO_HEADER_TEXT is false, you would style the text with these selectors:
- #headimg #name { }
- #headimg #desc { }
- */
- </style>
- <?php
- }
- endif;
- /*-----------------------------------------------------------------------------------*/
- /* Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
- /*-----------------------------------------------------------------------------------*/
- function piha_page_menu_args( $args ) {
- $args['show_home'] = true;
- return $args;
- }
- add_filter( 'wp_page_menu_args', 'piha_page_menu_args' );
- /*-----------------------------------------------------------------------------------*/
- /* Sets the post excerpt length to 40 characters.
- /*-----------------------------------------------------------------------------------*/
- function piha_excerpt_length( $length ) {
- return 40;
- }
- add_filter( 'excerpt_length', 'piha_excerpt_length' );
- /*-----------------------------------------------------------------------------------*/
- /* Returns a "Continue Reading" link for excerpts
- /*-----------------------------------------------------------------------------------*/
- function piha_continue_reading_link() {
- return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'piha' ) . '</a>';
- }
- /*-----------------------------------------------------------------------------------*/
- /* Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and piha_continue_reading_link().
- /*
- /* To override this in a child theme, remove the filter and add your own
- /* function tied to the excerpt_more filter hook.
- /*-----------------------------------------------------------------------------------*/
- function piha_auto_excerpt_more( $more ) {
- return ' …' . piha_continue_reading_link();
- }
- add_filter( 'excerpt_more', 'piha_auto_excerpt_more' );
- /*-----------------------------------------------------------------------------------*/
- /* Adds a pretty "Continue Reading" link to custom post excerpts.
- /*
- /* To override this link in a child theme, remove the filter and add your own
- /* function tied to the get_the_excerpt filter hook.
- /*-----------------------------------------------------------------------------------*/
- function piha_custom_excerpt_more( $output ) {
- if ( has_excerpt() && ! is_attachment() ) {
- $output .= piha_continue_reading_link();
- }
- return $output;
- }
- add_filter( 'get_the_excerpt', 'piha_custom_excerpt_more' );
- /*-----------------------------------------------------------------------------------*/
- /* Remove inline styles printed when the gallery shortcode is used.
- /*-----------------------------------------------------------------------------------*/
- function piha_remove_gallery_css( $css ) {
- return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
- }
- add_filter( 'gallery_style', 'piha_remove_gallery_css' );
- if ( ! function_exists( 'piha_comment' ) ) :
- /*-----------------------------------------------------------------------------------*/
- /* Comments template piha_comment
- /*-----------------------------------------------------------------------------------*/
- function piha_comment( $comment, $args, $depth ) {
- $GLOBALS['comment'] = $comment;
- switch ( $comment->comment_type ) :
- case '' :
- ?>
- <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
- <article id="comment-<?php comment_ID(); ?>" class="comment">
- <div class="comment-header">
- <?php echo get_avatar( $comment, 40 ); ?>
- <?php printf( __( '%s', 'piha' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
- <p><a class="comment-time" href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
- <?php
- /* translators: 1: date, 2: time */
- printf( __( '%1$s @ %2$s', 'piha' ),
- get_comment_date('d/m/Y'),
- get_comment_time() );
- ?></a></p>
- <p><?php edit_comment_link( __( 'Edit comment »', 'piha' ), ' ' );?></p>
- </div><!-- end .comment-header -->
- <div class="comment-content">
- <?php comment_text(); ?>
- <?php if ( $comment->comment_approved == '0' ) : ?>
- <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'piha' ); ?></p>
- <?php endif; ?>
- <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'piha' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
- </div><!-- end .comment-content -->
- </article><!-- end .comment -->
- <?php
- break;
- case 'pingback' :
- case 'trackback' :
- ?>
- <li class="post pingback">
- <p><?php _e( 'Pingback:', 'piha' ); ?> <?php comment_author_link(); ?></p>
- <p><?php edit_comment_link( __('Edit pingback »', 'piha'), ' ' ); ?></p>
- <?php
- break;
- endswitch;
- }
- endif;
- /*-----------------------------------------------------------------------------------*/
- /* Register widgetized area and update sidebar with default widgets
- /*-----------------------------------------------------------------------------------*/
- function piha_widgets_init() {
- register_sidebar( array (
- 'name' => __( 'Main Sidebar', 'piha' ),
- 'id' => 'sidebar-1',
- 'description' => __( 'Add your sidebar widgets here.', 'piha' ),
- 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
- 'after_widget' => "</aside>",
- 'before_title' => '<h3 class="widget-title">',
- 'after_title' => '</h3>',
- ) );
- }
- add_action( 'init', 'piha_widgets_init' );
- /*-----------------------------------------------------------------------------------*/
- /* Customized Piha search form
- /*-----------------------------------------------------------------------------------*/
- function piha_search_form( $form ) {
- $form = ' <form method="get" class="searchform" action="'.get_bloginfo('url').'">
- <input type="text" class="field s" name="s" placeholder="'. esc_attr__('Search', 'piha') .'" />
- <input type="submit" class="searchsubmit" name="submit" value="'. esc_attr__('Search', 'piha') .'" />
- </form>';
- return $form;
- }
- add_filter( 'get_search_form', 'piha_search_form' );
- /**
- * Removes the default CSS style from the WP image gallery
- */
- add_filter('gallery_style', function($a) {
- return "<div class='gallery'>";
- });
- /*-----------------------------------------------------------------------------------*/
- /* Piha Shortcodes
- /*-----------------------------------------------------------------------------------*/
- // Enable shortcodes in widget areas
- add_filter( 'widget_text', 'do_shortcode' );
- // Replace WP autop formatting
- if (!function_exists( "piha_remove_wpautop")) {
- function piha_remove_wpautop($content) {
- $content = do_shortcode( shortcode_unautop( $content ) );
- $content = preg_replace( '#^<\/p>|^<br \/>|<p>$#', '', $content);
- return $content;
- }
- }
- /*-----------------------------------------------------------------------------------*/
- /* Multi Columns Shortcodes
- /* Don't forget to add "_last" behind the shortcode if it is the last column.
- /*-----------------------------------------------------------------------------------*/
- // Two Columns
- function piha_shortcode_two_columns_one( $atts, $content = null ) {
- return '<div class="two-columns-one">' . piha_remove_wpautop($content) . '</div>';
- }
- add_shortcode( 'two_columns_one', 'piha_shortcode_two_columns_one' );
- function piha_shortcode_two_columns_one_last( $atts, $content = null ) {
- return '<div class="two-columns-one last">' . piha_remove_wpautop($content) . '</div>';
- }
- add_shortcode( 'two_columns_one_last', 'piha_shortcode_two_columns_one_last' );
- // Three Columns
- function piha_shortcode_three_columns_one($atts, $content = null) {
- return '<div class="three-columns-one">' . piha_remove_wpautop($content) . '</div>';
- }
- add_shortcode( 'three_columns_one', 'piha_shortcode_three_columns_one' );
- function piha_shortcode_three_columns_one_last($atts, $content = null) {
- return '<div class="three-columns-one last">' . piha_remove_wpautop($content) . '</div>';
- }
- add_shortcode( 'three_columns_one_last', 'piha_shortcode_three_columns_one_last' );
- function piha_shortcode_three_columns_two($atts, $content = null) {
- return '<div class="three-columns-two">' . piha_remove_wpautop($content) . '</div>';
- }
- add_shortcode( 'three_columns_two', 'piha_shortcode_three_columns' );
- function piha_shortcode_three_columns_two_last($atts, $content = null) {
- return '<div class="three-columns-two last">' . piha_remove_wpautop($content) . '</div>';
- }
- add_shortcode( 'three_columns_two_last', 'piha_shortcode_three_columns_two_last' );
- // Four Columns
- function piha_shortcode_four_columns_one($atts, $content = null) {
- return '<div class="four-columns-one">' . piha_remove_wpautop($content) . '</div>';
- }
- add_shortcode( 'four_columns_one', 'piha_shortcode_four_columns_one' );
- function piha_shortcode_four_columns_one_last($atts, $content = null) {
- return '<div class="four-columns-one last">' . piha_remove_wpautop($content) . '</div>';
- }
- add_shortcode( 'four_columns_one_last', 'piha_shortcode_four_columns_one_last' );
- function piha_shortcode_four_columns_two($atts, $content = null) {
- return '<div class="four-columns-two">' . piha_remove_wpautop($content) . '</div>';
- }
- add_shortcode( 'four_columns_two', 'piha_shortcode_four_columns_two' );
- function piha_shortcode_four_columns_two_last($atts, $content = null) {
- return '<div class="four-columns-two last">' . piha_remove_wpautop($content) . '</div>';
- }
- add_shortcode( 'four_columns_two_last', 'piha_shortcode_four_columns_two_last' );
- function piha_shortcode_four_columns_three($atts, $content = null) {
- return '<div class="four-columns-three">' . piha_remove_wpautop($content) . '</div>';
- }
- add_shortcode( 'four_columns_three', 'piha_shortcode_four_columns_three' );
- function piha_shortcode_four_columns_three_last($atts, $content = null) {
- return '<div class="four-columns-three last">' . piha_remove_wpautop($content) . '</div>';
- }
- add_shortcode( 'four_columns_three_last', 'piha_shortcode_four_columns_three_last' );
- // Divide Text Shortcode
- function piha_shortcode_divider($atts, $content = null) {
- return '<div class="divider"></div>';
- }
- add_shortcode( 'divider', 'piha_shortcode_divider' );
- /*-----------------------------------------------------------------------------------*/
- /* Text Highlight and Info Boxes Shortcodes
- /*-----------------------------------------------------------------------------------*/
- function piha_shortcode_white_box($atts, $content = null) {
- return '<div class="white-box">' . do_shortcode( piha_remove_wpautop($content) ) . '</div>';
- }
- add_shortcode( 'white_box', 'piha_shortcode_white_box' );
- function piha_shortcode_yellow_box($atts, $content = null) {
- return '<div class="yellow-box">' . do_shortcode( piha_remove_wpautop($content) ) . '</div>';
- }
- add_shortcode( 'yellow_box', 'piha_shortcode_yellow_box' );
- function piha_shortcode_red_box($atts, $content = null) {
- return '<div class="red-box">' . do_shortcode( piha_remove_wpautop($content) ) . '</div>';
- }
- add_shortcode( 'red_box', 'piha_shortcode_red_box' );
- function piha_shortcode_blue_box($atts, $content = null) {
- return '<div class="blue-box">' . do_shortcode( piha_remove_wpautop($content) ) . '</div>';
- }
- add_shortcode( 'blue_box', 'piha_shortcode_blue_box' );
- function piha_shortcode_green_box($atts, $content = null) {
- return '<div class="green-box">' . do_shortcode( piha_remove_wpautop($content) ) . '</div>';
- }
- add_shortcode( 'green_box', 'piha_shortcode_green_box' );
- function piha_shortcode_lightgrey_box($atts, $content = null) {
- return '<div class="lightgrey-box">' . do_shortcode( piha_remove_wpautop($content) ) . '</div>';
- }
- add_shortcode( 'lightgrey_box', 'piha_shortcode_lightgrey_box' );
- function piha_shortcode_grey_box($atts, $content = null) {
- return '<div class="grey-box">' . do_shortcode( piha_remove_wpautop($content) ) . '</div>';
- }
- add_shortcode( 'grey_box', 'piha_shortcode_grey_box' );
- function piha_shortcode_darkgrey_box($atts, $content = null) {
- return '<div class="darkgrey-box">' . do_shortcode( piha_remove_wpautop($content) ) . '</div>';
- }
- add_shortcode( 'darkgrey_box', 'piha_shortcode_darkgrey_box' );
- /*-----------------------------------------------------------------------------------*/
- /* General Buttons Shortcodes
- /*-----------------------------------------------------------------------------------*/
- function piha_button( $atts, $content = null ) {
- extract(shortcode_atts(array(
- 'link' => '#',
- 'target' => '',
- 'color' => '',
- 'size' => '',
- 'form' => '',
- 'style' => '',
- ), $atts));
- $color = ($color) ? ' '.$color. '-btn' : '';
- $size = ($size) ? ' '.$size. '-btn' : '';
- $form = ($form) ? ' '.$form. '-btn' : '';
- $target = ($target == 'blank') ? ' target="_blank"' : '';
- $out = '<a' .$target. ' class="standard-btn' .$color.$size.$form. '" href="' .$link. '"><span>' .do_shortcode($content). '</span></a>';
- return $out;
- }
- add_shortcode('button', 'piha_button');
- /*-----------------------------------------------------------------------------------*/
- /* PDF, Info and Add Buttons Shortcodes
- /*-----------------------------------------------------------------------------------*/
- function piha_icons_button( $atts, $content = null ) {
- extract(shortcode_atts(array(
- 'link' => '#',
- 'target' => '',
- 'color' => '',
- 'style' => '',
- 'form' => '',
- ), $atts));
- $color = ($color) ? ' '.$color. '-btn' : '';
- $style = ($style) ? ' '.$style. '-btn' : '';
- $form = ($form) ? ' '.$form. '-btn' : '';
- $target = ($target == 'blank') ? ' target="_blank"' : '';
- $out = '<a' .$target. ' class="icons-btn' .$color.$style.$form. '" href="' .$link. '"><span>' .do_shortcode($content). '</span></a>';
- return $out;
- }
- add_shortcode('icons_button', 'piha_icons_button');
- /*-----------------------------------------------------------------------------------*/
- /* Simple PDF, Info and Add Buttons Shortcodes
- /*-----------------------------------------------------------------------------------*/
- function piha_simple_icons_button( $atts, $content = null ) {
- extract(shortcode_atts(array(
- 'link' => '#',
- 'target' => '',
- 'style' => '',
- ), $atts));
- $style = ($style) ? ' '.$style. '-btn' : '';
- $target = ($target == 'blank') ? ' target="_blank"' : '';
- $out = '<a' .$target. ' class="simple-icons-btn' .$style. '" href="' .$link. '"><span>' .do_shortcode($content). '</span></a>';
- return $out;
- }
- add_shortcode('simple_icons_button', 'piha_simple_icons_button');
- /*-----------------------------------------------------------------------------------*/
- /* Link Post Format Button Shortcode
- /*-----------------------------------------------------------------------------------*/
- function piha_link_format( $atts, $content = null ) {
- extract(shortcode_atts(array(
- 'link' => '#',
- 'target' => '',
- 'style' => '',
- ), $atts));
- $target = ($target == 'blank') ? ' target="_blank"' : '';
- $out = '<a' .$target. ' class="link-format-btn' .$style. '" href="' .$link. '"><span>' .do_shortcode($content). '</span></a>';
- return $out;
- }
- add_shortcode('link_format', 'piha_link_format');
- /*-----------------------------------------------------------------------------------*/
- /* Deactives the default CSS styles for the Smart Archives Reloaded plugin
- /*-----------------------------------------------------------------------------------*/
- add_filter('smart_archives_load_default_styles', '__return_false');
- /*-----------------------------------------------------------------------------------*/
- /* Include a custom Flickr Widget
- /*-----------------------------------------------------------------------------------*/
- class Piha_Flickr extends WP_Widget {
- public function __construct() {
- $widget_ops = array('description' => 'Show preview images from a flickr account or group.' , 'piha');
- parent::__construct('piha_flickr', __('Flickr Widget', 'piha'), $widget_ops);
- }
- public function widget($args, $instance) {
- extract($args);
- $title = $instance['title'];
- $id = $instance['id'];
- $linktext = $instance['linktext'];
- $linkurl = $instance['linkurl'];
- $number = $instance['number'];
- $type = $instance['type'];
- $sorting = $instance['sorting'];
- echo $before_widget; ?>
- <?php if ($title != '') {
- echo '<h3 class="widget-title">' . $title . '</h3>';
- } ?>
- <div class="flickr_badge_wrapper"><script type="text/javascript" src="http://www.flickr.com/badge_code_v2.gne?count=<?php echo $number; ?>&display=<?php echo $sorting; ?>&&source=<?php echo $type; ?>&<?php echo $type; ?>=<?php echo $id; ?>&size=m"></script><div class="clear"></div>
- <?php if ($linktext == '') {
- echo '';
- } else {
- echo '<div class="flickr-bottom"><a href="'.$linkurl.'" class="flickr-home" target="_blank">'.$linktext.'</a></div>';
- }?>
- </div><!-- end .flickr_badge_wrapper -->
- <?php
- echo $after_widget;
- }
- public function update($new_instance, $old_instance) {
- return $new_instance;
- }
- public function form($instance) {
- $title = esc_attr($instance['title']);
- $id = esc_attr($instance['id']);
- $linktext = esc_attr($instance['linktext']);
- $linkurl = esc_attr($instance['linkurl']);
- $number = esc_attr($instance['number']);
- $type = esc_attr($instance['type']);
- $sorting = esc_attr($instance['sorting']);
- ?>
- <p>
- <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:','piha'); ?></label>
- <input type="text" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('id'); ?>"><?php _e('Flickr ID (<a href="http://www.idgettr.com" target="_blank">idGettr</a>):','piha'); ?></label>
- <input type="text" name="<?php echo $this->get_field_name('id'); ?>" value="<?php echo $id; ?>" class="widefat" id="<?php echo $this->get_field_id('id'); ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('linktext'); ?>"><?php _e('Flickr Profile Link Text:','piha'); ?></label>
- <input type="text" name="<?php echo $this->get_field_name('linktext'); ?>" value="<?php echo $linktext; ?>" class="widefat" id="<?php echo $this->get_field_id('linktext'); ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('linkurl'); ?>"><?php _e('Flickr Profile URL:','piha'); ?></label>
- <input type="text" name="<?php echo $this->get_field_name('linkurl'); ?>" value="<?php echo $linkurl; ?>" class="widefat" id="<?php echo $this->get_field_id('linkurl'); ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of photos:','piha'); ?></label>
- <select name="<?php echo $this->get_field_name('number'); ?>" class="widefat" id="<?php echo $this->get_field_id('number'); ?>">
- <?php for ($i = 1; $i <= 10; $i += 1) { ?>
- <option value="<?php echo $i; ?>" <?php if ($number == $i) { echo "selected='selected'";} ?>><?php echo $i; ?></option>
- <?php } ?>
- </select>
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('type'); ?>"><?php _e('Choose user or group:','piha'); ?></label>
- <select name="<?php echo $this->get_field_name('type'); ?>" class="widefat" id="<?php echo $this->get_field_id('type'); ?>">
- <option value="user" <?php if ($type == "user") { echo "selected='selected'";} ?>><?php _e('User', 'piha'); ?></option>
- <option value="group" <?php if ($type == "group") { echo "selected='selected'";} ?>><?php _e('Group', 'piha'); ?></option>
- </select>
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('sorting'); ?>"><?php _e('Show latest or random pictures:','piha'); ?></label>
- <select name="<?php echo $this->get_field_name('sorting'); ?>" class="widefat" id="<?php echo $this->get_field_id('sorting'); ?>">
- <option value="latest" <?php if ($sorting == "latest") { echo "selected='selected'";} ?>><?php _e('Latest', 'piha'); ?></option>
- <option value="random" <?php if ($sorting == "random") { echo "selected='selected'";} ?>><?php _e('Random', 'piha'); ?></option>
- </select>
- </p>
- <?php
- }
- }
- // Register the widget using the class name
- add_action('widgets_init', function(){
- register_widget('Piha_Flickr');
- });
- /*-----------------------------------------------------------------------------------*/
- /* Include a custom Video Widget
- /*-----------------------------------------------------------------------------------*/
- class Piha_Video extends WP_Widget {
- public function __construct() {
- $widget_ops = array('description' => 'Show a custom featured video.', 'piha');
- parent::__construct('piha_video', __('Video Widget', 'piha'), $widget_ops);
- }
- public function widget($args, $instance) {
- extract($args);
- $title = $instance['title'];
- $embedcode = $instance['embedcode'];
- echo $before_widget; ?>
- <?php if ($title != '') {
- echo '<h3 class="widget-title">' . $title . '</h3>';
- } ?>
- <div class="video_widget">
- <div class="featured-video"><?php echo $embedcode; ?></div>
- </div><!-- end .video_widget -->
- <?php
- echo $after_widget;
- }
- public function update($new_instance, $old_instance) {
- return $new_instance;
- }
- public function form($instance) {
- $title = esc_attr($instance['title']);
- $embedcode = esc_attr($instance['embedcode']);
- ?>
- <p>
- <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'piha'); ?></label>
- <input type="text" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('embedcode'); ?>"><?php _e('Video embed code:', 'piha'); ?></label>
- <textarea name="<?php echo $this->get_field_name('embedcode'); ?>" class="widefat" rows="6" id="<?php echo $this->get_field_id('embedcode'); ?>"><?php echo ($embedcode); ?></textarea>
- </p>
- <?php
- }
- }
- // Register the widget using the class name
- add_action('widgets_init', function () {
- register_widget('Piha_Video');
- });
- /*-----------------------------------------------------------------------------------*/
- /* Including a custom Social Media Widget
- /*-----------------------------------------------------------------------------------*/
- class Piha_SocialLinks extends WP_Widget {
- public function __construct() {
- $widget_ops = array('description' => 'Link to your social profiles.');
- parent::__construct('piha_sociallinks', __('Social Links Widget', 'piha'), $widget_ops);
- }
- public function widget($args, $instance) {
- $title = !empty($instance['title']) ? $instance['title'] : '';
- $target = !empty($instance['target']) ? 'target="_blank"' : '';
- echo $args['before_widget'];
- if (!empty($title)) {
- echo $args['before_title'] . $title . $args['after_title'];
- }
- ?>
- <ul class="sociallinks">
- <?php
- $social_links = array(
- 'twitter' => 'Twitter',
- 'facebook' => 'Facebook',
- // Add more social links as needed
- );
- foreach ($social_links as $key => $label) {
- $url = !empty($instance[$key]) ? esc_url($instance[$key]) : '';
- if (!empty($url)) {
- echo '<li><a href="' . $url . '" class="' . $key . '" title="' . $label . '" ' . $target . '>' . $label . '</a></li>';
- }
- }
- ?>
- </ul><!-- end .sociallinks -->
- <?php
- echo $args['after_widget'];
- }
- public function update($new_instance, $old_instance) {
- $instance = $old_instance;
- $instance['title'] = sanitize_text_field($new_instance['title']);
- $instance['target'] = isset($new_instance['target']) ? true : false;
- // Update other fields as needed
- return $instance;
- }
- public function form($instance) {
- $title = !empty($instance['title']) ? esc_attr($instance['title']) : '';
- $target = !empty($instance['target']) ? 'checked="checked"' : '';
- ?>
- <p>
- <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
- <input type="text" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" />
- </p>
- <p>
- <input class="checkbox" type="checkbox" <?php echo $target; ?> id="<?php echo $this->get_field_id('target'); ?>" name="<?php echo $this->get_field_name('target'); ?>" />
- <label for="<?php echo $this->get_field_id('target'); ?>"><?php _e('Open all links in a new browser tab'); ?></label>
- </p>
- <?php
- }
- }
- function register_piha_sociallinks_widget() {
- register_widget('Piha_SocialLinks');
- }
- add_action('widgets_init', 'register_piha_sociallinks_widget');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement