Bootstrap Templates Bundle

Monday, August 26, 2013

Adding Custom Meta Boxes in Wordpress

Add below code into wordpress functions.php file

add_action( 'add_meta_boxes', 'custom_header_img' );
function custom_header_img() {
$post_types = get_post_types();
foreach ( $post_types as $post_type ) {
if ($post_type == 'ad_post_type') {$post_type = 'page';}
add_meta_box( 'custom_header_img_url', 'Custom Header Image URL', 'custom_header_img_add', $post_type, 'normal', 'high' );
    }
}


function custom_header_img_add( $post )
{
$values = get_post_custom( $post->ID );
$chi_url = isset( $values['custom_header_img'] ) ? esc_attr( $values['custom_header_img'][0] ) : '';
wp_nonce_field( 'custom_header_img_add_nonce', 'meta_box_nonce_chi' );
?>

<span style="font-size:11px; color:#999; line-height:1.3;">Header Image will only work if "Custom Header Element" chosen.<br/>
Enter image full URL (include http://)</span>
<p><input type="text" name="custom_header_img" id="custom_header_img" value="<?php echo $chi_url; ?>" style="width:100%;" /> </p>

<?php
}


add_action( 'save_post', 'chi_meta_box_save' );
function chi_meta_box_save( $post_id )
{
// Bail if we're doing an auto save
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;

// if our nonce isn't there, or we can't verify it, bail
if( !isset( $_POST['meta_box_nonce_chi'] ) || !wp_verify_nonce( $_POST['meta_box_nonce_chi'], 'custom_header_img_add_nonce' ) ) return;

// if our current user can't edit this post, bail
if( !current_user_can( 'edit_post' ) ) return;

// now we can actually save the data
$allowed = array(
'a' => array( // on allow a tags
'href' => array() // and those anchords can only have href attribute
)
);


if( isset( $_POST['custom_header_img'] ) )
update_post_meta( $post_id, 'custom_header_img', esc_attr( $_POST['custom_header_img'] ) );
}

After adding this above code, check .//wp-admin/post-new.php, You can see a custom meta box by Custom Header Image URL named.

To show this on front end, add this code where you want to show
<?php echo get_post_meta($post->ID, 'custom_header_img', true); ?>
or
If you want add style then   <div style="color: red;float:left;"> <?php echo get_post_meta($post->ID, 'custom_header_img', true); ?></div>
or
<img class="custom_header_img" src="<?php echo get_post_meta($post->ID, 'custom_header_img', true); ?>">


You can add more custom meta boxes by only changing the red color portions. Suppose I want to add a custom field for word, So , I only change the all red color  custom_header_img  by custom_header_word

such as:
/*********************************************** CUSTOM meta Box for  word ***************************************************/

add_action( 'add_meta_boxes', 'custom_header_word' );
function custom_header_word() {
$post_types = get_post_types();
foreach ( $post_types as $post_type ) {
if ($post_type == 'ad_post_type') {$post_type = 'page';}
add_meta_box( 'custom_header_word_url', 'Custom Header Image Word', 'custom_header_word_add', $post_type, 'normal', 'high' );
    }
}


function custom_header_word_add( $post )
{
$values = get_post_custom( $post->ID );
$chi_url = isset( $values['custom_header_word'] ) ? esc_attr( $values['custom_header_word'][0] ) : '';
wp_nonce_field( 'custom_header_word_add_nonce', 'meta_box_nonce_chi' );
?>

<span style="font-size:11px; color:#999; line-height:1.3;">Header Image will only work if "Custom Header Element" chosen.<br/>
Enter image full URL (include http://)</span>
<p><input type="text" name="custom_header_word" id="custom_header_word" value="<?php echo $chi_url; ?>" style="width:100%;" /> </p>

<?php
}


add_action( 'save_post', 'chi_meta_boxword_save' );
function chi_meta_boxword_save( $post_id )
{
// Bail if we're doing an auto save
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;

// if our nonce isn't there, or we can't verify it, bail
if( !isset( $_POST['meta_box_nonce_chi'] ) || !wp_verify_nonce( $_POST['meta_box_nonce_chi'], 'custom_header_word_add_nonce' ) ) return;

// if our current user can't edit this post, bail
if( !current_user_can( 'edit_post' ) ) return;

// now we can actually save the data
$allowed = array(
'a' => array( // on allow a tags
'href' => array() // and those anchords can only have href attribute
)
);


if( isset( $_POST['custom_header_word'] ) )
update_post_meta( $post_id, 'custom_header_word', esc_attr( $_POST['custom_header_word'] ) );
}


Adding Custom editor buttons in wordpress

Add these below code into functions.php file:

/* Custom editor buttons */
function enable_more_buttons($buttons) {
  $buttons[] = 'hr';
  $buttons[] = 'sub';
  $buttons[] = 'sup';
  $buttons[] = 'fontselect';
  $buttons[] = 'fontsizeselect';

  return $buttons;
}
add_filter("mce_buttons_3", "enable_more_buttons");

How to add a ID column into wordpress Posts and pages

Add these below code to functions.php file  and after adding visit
../wp-admin/edit.php?post_type=page
and ../wp-admin/edit.php



/* Add Post ID column */
add_filter('manage_posts_columns', 'posts_columns_id', 5);
function posts_columns_id($defaults){
    $defaults['wps_post_id'] = 'ID';
    return $defaults;
}
add_action('manage_posts_custom_column', 'posts_custom_id_columns', 5, 2);
function posts_custom_id_columns($column_name, $id){
        if($column_name === 'wps_post_id'){
                echo $id;
    }
}
add_action('admin_head', 'id_column_style');
function id_column_style() {
    echo '<style type="text/css">.column-wps_post_id{width:5%;}</style>';
}


/* Add Page ID column */
add_filter('manage_pages_columns', 'pages_columns_id', 5);
function pages_columns_id($defaults){
    $defaults['wps_page_id'] = 'ID';
    return $defaults;
}
add_action('manage_pages_custom_column', 'pages_custom_id_columns', 5, 2);
function pages_custom_id_columns($column_name, $id){
        if($column_name === 'wps_page_id'){
                echo $id;
    }
}
add_action('admin_head', 'id_column_style');
function ids_column_style() {
    echo '<style type="text/css">.column-wps_page_id{width:5%;}</style>';
}

Thursday, August 1, 2013

How to Install the Facebook Like Box on Your Drupal Website also enable php code as input text format

Get facebook likebox code from facebook.com
suppose

<iframe scrolling="no" frameborder="0" allowtransparency="true" src="http://platform.twitter.com/widgets/follow_button.1340179658.html#_=1344687471539&amp;id=twitter-widget-2&amp;lang=en&amp;screen_name=saranquardz&amp;show_count=true&amp;show_screen_name=true&amp;size=m" class="twitter-follow-button" style="width: 243px; height: 20px;" title="Twitter Follow Button"></iframe><iframe src="//www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fdevsaran.drupal&amp;width=240&amp;height=258&amp;colorscheme=light&amp;show_faces=true&amp;border_color&amp;stream=false&amp;header=false" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:240px; height:258px;" allowtransparency="true"></iframe>

Then create a block and add avove code also select php code as input tex format




Do you know how to enable php code for input text format?
see below:

Go to Administration > Modules.
Scroll down to the PHP filter module and check the Enabled box. Press the Save Configuration button.
When you will add ant content/block select php code as input method. That's all

Wokiee React eCommerce Template