WYSIWYG Editor for your custom box

If you have a custom text box in the edit post page, and you want to have the built-in editor, it’s quite easy to do.
<?php
the_editor($content,’id’);

deprecated

use

wp_editor($content,’id’ . $post->ID);
?>

To get ajax data, you can call global tinyMCE object
tinyMCE.get(node_id).getContent();

Creating a custom widget

Here is the basic code to use to create a widget.

class myWidget extends WP_Widget {
function myWidget() {
// widget actual processes
parent::WP_Widget(false, $name = ‘myWidget’);
}

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
?>
<li> …
</li>
<?
}

}
register_widget(‘myWidget’);

Custom Boxes in Posts

You can create a custom box in post/page/custom-post-type by adding a couple of actions and telling it to trigger for the post-type.

1. add_action( ‘add_meta_boxes’, ‘people_add_custom_box’ ); // this hooks into the ‘add_meta_boxes’ action, and calls the function people_add_custom_box

2.     function people_add_custom_box() {
add_meta_box(
‘people-quote’,
__( ‘Quote’, ‘quote_textdomain’ ),
‘people_inner_custom_box’,
‘people’
);
Each add_meta_box creates a separate box, in this case it calls function people_inner_custom_box() to generate its HTML

3. function people_inner_custom_box($post). Use this to generate the form fields. You can use a nonce to prevent accidental posting

$collection_link = get_post_meta($post->ID,’collection_link’,true);
$template = get_post_meta($post->ID,’template’,true);
$video = get_post_meta($post->ID,’video’,true);
?>

function designer_page_template($post) {
$collection_link = get_post_meta($post->ID,’collection_link’,true);
$template = get_post_meta($post->ID,’template’,true);
$video = get_post_meta($post->ID,’video’,true);
?>
Page Type: <select name=”template”>
<option value=”landing” <?php echo ($template==”landing”) ? ‘selected=”selected”‘:”;?>>Designer Landing Page</option>
<option value=”history” <?php echo ($template==”history”) ? ‘selected=”selected”‘:”;?>>History Page</option>
<option value=”inspiration” <?php echo ($template==”inspiration”) ? ‘selected=”selected”‘:”;?>>Inspiration Page</option>
<option value=”video” <?php echo ($template==”video”) ? ‘selected=”selected”‘:”;?>>Video Page</option>
</select><br />
Collection Link: <input type=”text” name=”collection_link” id=”collection_link” value=”<?php echo $collection_link;?>” style=”width:400px”/><br />
Video embed code:<br />
<textarea style=”width:500px;height:100px;” name=”video”><?php echo stripslashes($video);?></textarea>
<?
}

4. add_action( ‘save_post’, ‘people_save_postdata’ ); // hooks into save_post and calls function people_save_postdata(). You can then use update_post_meta() to store the data.

5.function people_save_postdata($post_id) {
if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE )
return;
$address = $_POST[‘address’];
if ($address) update_post_meta($post_id,’address’,$address);

}

A new and better clearfix

I love clearfix. It works great, but now there is a new sheriff in town.

This is micro clearfix. For those of you not familiar with clearfix, when you have child elements that are all floated, the parent element has no “shape” to hold its height. Clearfix takes care of that.

http://nicolasgallagher.com/micro-clearfix-hack/

 

/* For modern browsers */
.cf:before,
.cf:after {
    content:"";
    display:table;
}

.cf:after {
    clear:both;
}

/* For IE 6/7 (trigger hasLayout) */
.cf {
    zoom:1;
}