> Reading), // then calls to $post, get_the_ID(), etc will return the ID of the first // post that page is displaying - as such, jimmy around to the page ID. $post_id = $post->ID; if ( is_home() ) { $post_id = get_option( 'page_for_posts' ); } // //DAN-HACK: End return self::get_opt_explicit( $post_id, $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; } /** * Transforms a page/post slug into a full URL. * * Note: If you have a hierarchical page, you must include the full path (e.g. 'parent-page/sub-page'). * @link http://codex.wordpress.org/Function_Reference/get_page_by_path * * @param string $slug The slug of the page/post desired * @return string The desired URL, or nothing if not found */ public static function get_permalink_by_slug( $slug ) { $page = get_page_by_path( $slug ); if ( !empty( $page ) ) { return get_permalink( $page->ID ); } return ''; } /** * Retrieves a list of the sticky posts in descending date order. This list * of posts can then be used in the a WP loop. * * @link http://justintadlock.com/archives/2009/03/28/get-the-latest-sticky-posts-in-wordpress * @param integer $num_stickies Can limit the number of stickies to retrieve * @return object A WP Query */ public static function get_stickies( $num_stickies = -1 ) { $sticky = get_option( 'sticky_posts' ); rsort( $sticky ); if ( $num_stickies >= 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 ); } /* PRIVATE */ /** * Only use this class as a utility.. */ private function __construct() { // Intentionally blank.. } } ?>