Showing posts with label wordpress widget. Show all posts
Showing posts with label wordpress widget. Show all posts

Saturday, March 15, 2014

How to Create Custom Texonomies in Wordpress ?

For Creating Custom Texonomies in Wordpress Have Function
register_taxonomy () Function

Example Code : Below PHP Code Will Create genre texonomy in Wordpress


<?php
add_action( 'init', 'create_book_tax' );

function create_book_tax() {
 register_taxonomy(
  'genre',
  'book',
  array(
   'label' => __( 'Genre' ),
   'rewrite' => array( 'slug' => 'genre' ),
   'hierarchical' => true,
  )
 );
}

Friday, January 31, 2014

Wordpress - How to Create Multiple instance of Widget ?

How to Create Multiple instance of Widget ?


You need to implement your Widget using the Widgets API, so that WordPress knows how to make multiple instances of the Widget.

Your Widget declaration should take the following format:


class My_Widget extends WP_Widget {
    function My_Widget() {
        // widget actual processes
    }

    function form($instance) {
        // outputs the options form on admin
    }

    function update($new_instance, $old_instance) {
        // processes widget options to be saved
    }

    function widget($args, $instance) {
        // outputs the content of the widget
    }

}
register_widget('My_Widget');

Wordpress - How to Create New Custom Widget ?

How to Create New Custom Widget ?

 

Standard Practice to Create Widget 

/***Widget for Welcome Box *********/
class Welcome extends WP_Widget {

    /**
     * Sets up the widgets name etc
     */
    public function __construct() {
        // widget actual processes
        parent::__construct(
            'welcome_user', // Base ID
            __('Welcome User', 'text_domain'), // Name
            array( 'description' => __( 'Shows Welcome Message if User is Logged In', 'text_domain' ), ) // Args
        );
    }

    /**
     * Outputs the content of the widget
     *
     * @param array $args
     * @param array $instance
     */
    public function widget( $args, $instance ) {
        // outputs the content of the widget
        if(is_user_logged_in())
        {
            $objCurrentUser = wp_get_current_user();
            $strNiceName = $objCurrentUser->data->user_nicename;
        ?>
            <div class="welcome_text">
                <?php echo __('Welcome '.$strNiceName); ?>, 
                <a href="<?php echo wp_logout_url(get_option('siteurl')); ?>"><?php echo __('Log Out'); ?></a>
            </div>
        <?php
        }
    }

    /**
     * Ouputs the options form on admin
     *
     * @param array $instance The widget options
     */
    public function form( $instance ) {
        // outputs the options form on admin
    }

    /**
     * Processing widget options on save
     *
     * @param array $new_instance The new options
     * @param array $old_instance The previous options
     */
    public function update( $new_instance, $old_instance ) {
        // processes widget options to be saved
    }
}
add_action('widgets_init', 'fnWelcome');
function fnWelcome(){
    register_widget( 'Welcome' );
}
/********** END **********/

Another Way to Create Widget 

register_sidebar_widget(<Widget Title>, <your Custom function name>);

 

Copyright @ 2013 PHP WORDPRESS MAGENTO .

Designed by Kcon Technosoft