= 0 ) { $sticky = array_slice( $sticky, 0, $num_stickies ); } $args = array ( 'ignore_sticky_posts' => 1, 'order_by' => 'date', 'order' => 'DESC', 'post__in' => $sticky, 'posts_per_page' => $num_stickies, ); return new \WP_Query( $args ); } /** * Retrives the value of a setting previously saved to the database * typically through the use of the metabox mb_ctl components or * through the use of custom fields. * @param string $slug The unique key of the value to be retrieved * @param mixed $default If no value is found in the database, return this value instead * @return string The desired value */ static function get_opt( $slug, $default = null ) { // Get the global post and cascade. global $post; return self::get_opt_explicit( $post, $slug, $default ); } /** * Retrives the value of a setting previously saved to the database * typically through the use of the metabox mb_ctl components or * through the use of custom fields. * @param object/int $post The post or post ID with the option to be retrieved * @param string $slug The unique key of the value to be retrieved * @param mixed $default If no value is found in the database, return this value instead * @return string The desired value */ static function get_opt_explicit( $post, $slug, $default = null ) { // Ensure that we are on a post/page that has postmeta if ( empty( $post ) ) return $default; // A post object or the post ID could be passed - test it. $post_id = $post; if ( is_object( $post ) ) $post_id = $post->ID; // Retrieve the value from the database. $value = get_post_meta( $post_id, $slug, true ); // If no value was found and a default was provided, use the default. if ( ( $value == '' ) && ( $default != null ) ) { $value = $default; } // Return the ultimate value. return $value; } /** * Retrives all postmeta associated with the current post. * @param object A ski\db object to use as the connection - if not supplied, $wpdb will be used * @return array An array of key/value pairs */ static function get_opts( $slug, $db = null ) { // Get the global post and cascade. global $post; return self::get_opts_explicit( $post, $db ); } /** * Retrives all postmeta associated with the given post. * @param object/int $post The desired post or post ID * @param object A ski\db object to use as the connection - if not supplied, $wpdb will be used * @return array An array of key/value pairs */ static function get_opts_explicit( $post, $db = null ) { global $wpdb; // Ensure that we are on a post/page that has postmeta. if ( empty( $post ) ) return $default; // A post object or the post ID could be passed - test it. $post_id = $post; if ( is_object( $post ) ) $post_id = $post->ID; // Two ways to call the same query - ski\db is faster than $wpdb. $data = array(); $sql = sprintf( 'SELECT meta_key, meta_value FROM wp_postmeta WHERE post_id = %d;', $post_id ); if ( $db ) { $recs = $db->run_query( $sql ); while( $rec = $recs->next( true ) ) { $data[$rec->meta_key] = $rec->meta_value; } } else { $recs = $wpdb->get_results( $sql ); foreach ( $recs as $rec ) { $data[$rec->meta_key] = $rec->meta_value; }; } // And a single blob to return. return $data; } /** * Evidently, 'get_template_part' does not return an indicator that the * template actually loaded. So, this function tests if the file exists * so it has something to return to the client and loads the template if * the desired template is found. * @param string $slug The slug name for the generic template. * @param string $name The name of the specialised template. * @return boolean Whether or not the template was found/loaded */ static function get_template_part( $slug, $name = null ) { // Put together a list of templates to look through, just like // the original function - one with the name and one without. $templates = array(); $name = (string)$name; if ( !empty( $name ) ) $templates[] = $slug.'-'.$name.'.php'; $templates[] = $slug.'.php'; // See if the template really exists. $found = locate_template( $templates, false ); // Try loading the template no matter what - use the regular WP // function because it sets up a hook call too. get_template_part( $slug, $name ); // And return the info (the reason for this function) to the client. return $found; } /* PRIVATE */ /** * Only use this class as a utility.. */ private function __construct() { // Intentionally blank.. } } ?>