Categories
Wordpress

Easy way to add embed code to your site

If you want to embed from popular video sites, rather than copying and pasting embed codes, use oembed and the built int wordpress oembed functions.

http://codex.wordpress.org/Function_Reference/wp_oembed_get

Call it from your template and it will create the embed code for you. The only drawback is that it may be slower.

Categories
Wordpress

Great wordpress video for beginners

Here is a little WP video to get beginners familiar with WP admin panel.

Categories
Wordpress

Converting single wordpress blog to network ( aka MU )

What should be simple took quite a while. There is really only way to do this, and that is from scratch.

1) Create an XML export

2) Rename your install and put it somewhere else

3) Drop the database, create a new one

4) Install WordPress

5) Follow the instructions for network install

6) Import your XML.

7) copy the upload directory from the old instance

Categories
Wordpress

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();

Categories
Wordpress

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’);

Categories
Wordpress

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);

}