This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function __construct() { | |
$widget_options = array( | |
'classname' => 'example_widget', | |
'description' => 'This is an Example Widget', | |
); | |
parent::__construct( 'example_widget', 'Example Widget', $widget_options ); | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class jpen_Example_Widget extends WP_Widget { | |
/** | |
* To create the example widget all four methods will be | |
* nested inside this single instance of the WP_Widget class. | |
**/ | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* First Loop | |
* Returns posts with a custom post order value | |
*/ | |
// First, determine if on the first page of posts | |
// If on first page, run query to display posts with custom sort first | |
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array( | |
'post_type' => 'post', | |
'cat' => '94', | |
'meta_key' => '_custom_post_order', | |
'orderby' => 'meta_value', | |
'order' => 'ASC' | |
); | |
$query = new WP_query ( $args ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Sort posts on the blog posts page according to the custom sort order */ | |
function jpen_custom_post_order_sort( $query ){ | |
if ( $query->is_main_query() && is_home() ){ | |
$query->set( 'orderby', 'meta_value' ); | |
$query->set( 'meta_key', '_custom_post_order' ); | |
$query->set( 'order' , 'ASC' ); | |
} | |
} | |
add_action( 'pre_get_posts' , 'jpen_custom_post_order_sort' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Display custom post order in the post list */ | |
function jpen_custom_post_order_value( $column, $post_id ){ | |
if ($column == 'pos' ){ | |
echo '<p>' . get_post_meta( $post_id, '_custom_post_order', true) . '</p>'; | |
} | |
} | |
add_action( 'manage_posts_custom_column' , 'jpen_custom_post_order_value' , 10 , 2 ); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Add custom post order column to post list */ | |
function jpen_add_custom_post_order_column( $columns ){ | |
return array_merge ( $columns, | |
array( 'pos' => 'Position', )); | |
} | |
add_filter('manage_posts_columns' , 'jpen_add_custom_post_order_column'); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Save the input to post_meta_data */ | |
function jpen_save_custom_post_order( $post_id ){ | |
if ( !isset( $_POST['jpen_custom_post_order_nonce'] ) || !wp_verify_nonce( $_POST['jpen_custom_post_order_nonce'], basename( __FILE__ ) ) ){ | |
return; | |
} | |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){ | |
return; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Add a field to the metabox */ | |
function jpen_custom_post_order( $post ) { | |
wp_nonce_field( basename( __FILE__ ), 'jpen_custom_post_order_nonce' ); | |
$current_pos = get_post_meta( $post->ID, '_custom_post_order', true); ?> | |
<p>Enter the position at which you would like the post to appear. For exampe, post "1" will appear first, post "2" second, and so forth.</p> | |
<p><input type="number" name="pos" value="<?php echo $current_pos; ?>" /></p> | |
<?php | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Create custom meta data box to the post edit screen */ | |
function jpen_custom_post_sort( $post ){ | |
add_meta_box( | |
'custom_post_sort_box', | |
'Position in List of Posts', | |
'jpen_custom_post_order', | |
'post' , | |
'side' |