mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * WordPress Post Template Functions.
mp-wp_genesis 4 *
mp-wp_genesis 5 * Gets content for the current post in the loop.
mp-wp_genesis 6 *
mp-wp_genesis 7 * @package WordPress
mp-wp_genesis 8 * @subpackage Template
mp-wp_genesis 9 */
mp-wp_genesis 10
mp-wp_genesis 11 /**
mp-wp_genesis 12 * Display the ID of the current item in the WordPress Loop.
mp-wp_genesis 13 *
mp-wp_genesis 14 * @since 0.71
mp-wp_genesis 15 * @uses $id
mp-wp_genesis 16 */
mp-wp_genesis 17 function the_ID() {
mp-wp_genesis 18 global $id;
mp-wp_genesis 19 echo $id;
mp-wp_genesis 20 }
mp-wp_genesis 21
mp-wp_genesis 22 /**
mp-wp_genesis 23 * Retrieve the ID of the current item in the WordPress Loop.
mp-wp_genesis 24 *
mp-wp_genesis 25 * @since 2.1.0
mp-wp_genesis 26 * @uses $id
mp-wp_genesis 27 *
mp-wp_genesis 28 * @return unknown
mp-wp_genesis 29 */
mp-wp_genesis 30 function get_the_ID() {
mp-wp_genesis 31 global $id;
mp-wp_genesis 32 return $id;
mp-wp_genesis 33 }
mp-wp_genesis 34
mp-wp_genesis 35 /**
mp-wp_genesis 36 * Display or retrieve the current post title with optional content.
mp-wp_genesis 37 *
mp-wp_genesis 38 * @since 0.71
mp-wp_genesis 39 *
mp-wp_genesis 40 * @param string $before Optional. Content to prepend to the title.
mp-wp_genesis 41 * @param string $after Optional. Content to append to the title.
mp-wp_genesis 42 * @param bool $echo Optional, default to true.Whether to display or return.
mp-wp_genesis 43 * @return null|string Null on no title. String if $echo parameter is false.
mp-wp_genesis 44 */
mp-wp_genesis 45 function the_title($before = '', $after = '', $echo = true) {
mp-wp_genesis 46 $title = get_the_title();
mp-wp_genesis 47
mp-wp_genesis 48 if ( strlen($title) == 0 )
mp-wp_genesis 49 return;
mp-wp_genesis 50
mp-wp_genesis 51 $title = $before . $title . $after;
mp-wp_genesis 52
mp-wp_genesis 53 if ( $echo )
mp-wp_genesis 54 echo $title;
mp-wp_genesis 55 else
mp-wp_genesis 56 return $title;
mp-wp_genesis 57 }
mp-wp_genesis 58
mp-wp_genesis 59 /**
mp-wp_genesis 60 * Sanitize the current title when retrieving or displaying.
mp-wp_genesis 61 *
mp-wp_genesis 62 * Works like {@link the_title()}, except the parameters can be in a string or
mp-wp_genesis 63 * an array. See the function for what can be override in the $args parameter.
mp-wp_genesis 64 *
mp-wp_genesis 65 * The title before it is displayed will have the tags stripped and {@link
mp-wp_genesis 66 * attribute_escape()} before it is passed to the user or displayed. The default
mp-wp_genesis 67 * as with {@link the_title()}, is to display the title.
mp-wp_genesis 68 *
mp-wp_genesis 69 * @since 2.3.0
mp-wp_genesis 70 *
mp-wp_genesis 71 * @param string|array $args Optional. Override the defaults.
mp-wp_genesis 72 * @return string|null Null on failure or display. String when echo is false.
mp-wp_genesis 73 */
mp-wp_genesis 74 function the_title_attribute( $args = '' ) {
mp-wp_genesis 75 $title = get_the_title();
mp-wp_genesis 76
mp-wp_genesis 77 if ( strlen($title) == 0 )
mp-wp_genesis 78 return;
mp-wp_genesis 79
mp-wp_genesis 80 $defaults = array('before' => '', 'after' => '', 'echo' => true);
mp-wp_genesis 81 $r = wp_parse_args($args, $defaults);
mp-wp_genesis 82 extract( $r, EXTR_SKIP );
mp-wp_genesis 83
mp-wp_genesis 84
mp-wp_genesis 85 $title = $before . $title . $after;
mp-wp_genesis 86 $title = attribute_escape(strip_tags($title));
mp-wp_genesis 87
mp-wp_genesis 88 if ( $echo )
mp-wp_genesis 89 echo $title;
mp-wp_genesis 90 else
mp-wp_genesis 91 return $title;
mp-wp_genesis 92 }
mp-wp_genesis 93
mp-wp_genesis 94 /**
mp-wp_genesis 95 * Retrieve post title.
mp-wp_genesis 96 *
mp-wp_genesis 97 * If the post is protected and the visitor is not an admin, then "Protected"
mp-wp_genesis 98 * will be displayed before the post title. If the post is private, then
mp-wp_genesis 99 * "Private" will be located before the post title.
mp-wp_genesis 100 *
mp-wp_genesis 101 * @since 0.71
mp-wp_genesis 102 *
mp-wp_genesis 103 * @param int $id Optional. Post ID.
mp-wp_genesis 104 * @return string
mp-wp_genesis 105 */
mp-wp_genesis 106 function get_the_title( $id = 0 ) {
mp-wp_genesis 107 $post = &get_post($id);
mp-wp_genesis 108
mp-wp_genesis 109 $title = $post->post_title;
mp-wp_genesis 110
mp-wp_genesis 111 if ( !is_admin() ) {
mp-wp_genesis 112 if ( !empty($post->post_password) )
mp-wp_genesis 113 $title = sprintf(__('Protected: %s'), $title);
mp-wp_genesis 114 else if ( isset($post->post_status) && 'private' == $post->post_status )
mp-wp_genesis 115 $title = sprintf(__('Private: %s'), $title);
mp-wp_genesis 116 }
mp-wp_genesis 117 return apply_filters( 'the_title', $title );
mp-wp_genesis 118 }
mp-wp_genesis 119
mp-wp_genesis 120 /**
mp-wp_genesis 121 * Display the Post Global Unique Identifier (guid).
mp-wp_genesis 122 *
mp-wp_genesis 123 * The guid will appear to be a link, but should not be used as an link to the
mp-wp_genesis 124 * post. The reason you should not use it as a link, is because of moving the
mp-wp_genesis 125 * blog across domains.
mp-wp_genesis 126 *
mp-wp_genesis 127 * @since 1.5.0
mp-wp_genesis 128 *
mp-wp_genesis 129 * @param int $id Optional. Post ID.
mp-wp_genesis 130 */
mp-wp_genesis 131 function the_guid( $id = 0 ) {
mp-wp_genesis 132 echo get_the_guid($id);
mp-wp_genesis 133 }
mp-wp_genesis 134
mp-wp_genesis 135 /**
mp-wp_genesis 136 * Retrieve the Post Global Unique Identifier (guid).
mp-wp_genesis 137 *
mp-wp_genesis 138 * The guid will appear to be a link, but should not be used as an link to the
mp-wp_genesis 139 * post. The reason you should not use it as a link, is because of moving the
mp-wp_genesis 140 * blog across domains.
mp-wp_genesis 141 *
mp-wp_genesis 142 * @since 1.5.0
mp-wp_genesis 143 *
mp-wp_genesis 144 * @param int $id Optional. Post ID.
mp-wp_genesis 145 * @return string
mp-wp_genesis 146 */
mp-wp_genesis 147 function get_the_guid( $id = 0 ) {
mp-wp_genesis 148 $post = &get_post($id);
mp-wp_genesis 149
mp-wp_genesis 150 return apply_filters('get_the_guid', $post->guid);
mp-wp_genesis 151 }
mp-wp_genesis 152
mp-wp_genesis 153 /**
mp-wp_genesis 154 * Display the post content.
mp-wp_genesis 155 *
mp-wp_genesis 156 * @since 0.71
mp-wp_genesis 157 *
mp-wp_genesis 158 * @param string $more_link_text Optional. Content for when there is more text.
mp-wp_genesis 159 * @param string $stripteaser Optional. Teaser content before the more text.
mp-wp_genesis 160 * @param string $more_file Optional. Not used.
mp-wp_genesis 161 */
mp-wp_genesis 162 function the_content($more_link_text = null, $stripteaser = 0, $more_file = '') {
mp-wp_genesis 163 $content = get_the_content($more_link_text, $stripteaser, $more_file);
mp-wp_genesis 164 $content = apply_filters('the_content', $content);
mp-wp_genesis 165 $content = str_replace(']]>', ']]>', $content);
mp-wp_genesis 166 echo $content;
mp-wp_genesis 167 }
mp-wp_genesis 168
mp-wp_genesis 169 /**
mp-wp_genesis 170 * Retrieve the post content.
mp-wp_genesis 171 *
mp-wp_genesis 172 * @since 0.71
mp-wp_genesis 173 *
mp-wp_genesis 174 * @param string $more_link_text Optional. Content for when there is more text.
mp-wp_genesis 175 * @param string $stripteaser Optional. Teaser content before the more text.
mp-wp_genesis 176 * @param string $more_file Optional. Not used.
mp-wp_genesis 177 * @return string
mp-wp_genesis 178 */
mp-wp_genesis 179 function get_the_content($more_link_text = null, $stripteaser = 0, $more_file = '') {
mp-wp_genesis 180 global $id, $post, $more, $page, $pages, $multipage, $preview, $pagenow;
mp-wp_genesis 181
mp-wp_genesis 182 if ( null === $more_link_text )
mp-wp_genesis 183 $more_link_text = __( '(more...)' );
mp-wp_genesis 184
mp-wp_genesis 185 $output = '';
mp-wp_genesis 186
mp-wp_genesis 187 // If post password required and it doesn't match the cookie.
mp-wp_genesis 188 if ( post_password_required($post) ) {
mp-wp_genesis 189 $output = get_the_password_form();
mp-wp_genesis 190 return $output;
mp-wp_genesis 191 }
mp-wp_genesis 192
mp-wp_genesis 193 if ( $more_file != '' )
mp-wp_genesis 194 $file = $more_file;
mp-wp_genesis 195 else
mp-wp_genesis 196 $file = $pagenow; //$_SERVER['PHP_SELF'];
mp-wp_genesis 197
mp-wp_genesis 198 if ( $page > count($pages) ) // if the requested page doesn't exist
mp-wp_genesis 199 $page = count($pages); // give them the highest numbered page that DOES exist
mp-wp_genesis 200
mp-wp_genesis 201 $content = $pages[$page-1];
mp-wp_genesis 202 if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
mp-wp_genesis 203 $content = explode($matches[0], $content, 2);
mp-wp_genesis 204 if ( !empty($matches[1]) && !empty($more_link_text) )
mp-wp_genesis 205 $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1])));
mp-wp_genesis 206 } else {
mp-wp_genesis 207 $content = array($content);
mp-wp_genesis 208 }
mp-wp_genesis 209 if ( (false !== strpos($post->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) )
mp-wp_genesis 210 $stripteaser = 1;
mp-wp_genesis 211 $teaser = $content[0];
mp-wp_genesis 212 if ( ($more) && ($stripteaser) )
mp-wp_genesis 213 $teaser = '';
mp-wp_genesis 214 $output .= $teaser;
mp-wp_genesis 215 if ( count($content) > 1 ) {
mp-wp_genesis 216 if ( $more ) {
mp-wp_genesis 217 $output .= '<span id="more-'.$id.'"></span>'.$content[1];
mp-wp_genesis 218 } else {
mp-wp_genesis 219 $output = balanceTags($output);
mp-wp_genesis 220 if ( ! empty($more_link_text) )
mp-wp_genesis 221 $output .= ' <a href="'. get_permalink() . "#more-$id\" class=\"more-link\">$more_link_text</a>";
mp-wp_genesis 222 }
mp-wp_genesis 223
mp-wp_genesis 224 }
mp-wp_genesis 225 if ( $preview ) // preview fix for javascript bug with foreign languages
mp-wp_genesis 226 $output = preg_replace('/\%u([0-9A-F]{4,4})/e', "'&#'.base_convert('\\1',16,10).';'", $output);
mp-wp_genesis 227
mp-wp_genesis 228 return $output;
mp-wp_genesis 229 }
mp-wp_genesis 230
mp-wp_genesis 231 /**
mp-wp_genesis 232 * Display the post excerpt.
mp-wp_genesis 233 *
mp-wp_genesis 234 * @since 0.71
mp-wp_genesis 235 * @uses apply_filters() Calls 'the_excerpt' hook on post excerpt.
mp-wp_genesis 236 */
mp-wp_genesis 237 function the_excerpt() {
mp-wp_genesis 238 echo apply_filters('the_excerpt', get_the_excerpt());
mp-wp_genesis 239 }
mp-wp_genesis 240
mp-wp_genesis 241 /**
mp-wp_genesis 242 * Retrieve the post excerpt.
mp-wp_genesis 243 *
mp-wp_genesis 244 * @since 0.71
mp-wp_genesis 245 *
mp-wp_genesis 246 * @param mixed $deprecated Not used.
mp-wp_genesis 247 * @return string
mp-wp_genesis 248 */
mp-wp_genesis 249 function get_the_excerpt($deprecated = '') {
mp-wp_genesis 250 global $post;
mp-wp_genesis 251 $output = '';
mp-wp_genesis 252 $output = $post->post_excerpt;
mp-wp_genesis 253 if ( post_password_required($post) ) {
mp-wp_genesis 254 $output = __('There is no excerpt because this is a protected post.');
mp-wp_genesis 255 return $output;
mp-wp_genesis 256 }
mp-wp_genesis 257
mp-wp_genesis 258 return apply_filters('get_the_excerpt', $output);
mp-wp_genesis 259 }
mp-wp_genesis 260
mp-wp_genesis 261 /**
mp-wp_genesis 262 * Whether post has excerpt.
mp-wp_genesis 263 *
mp-wp_genesis 264 * @since 2.3.0
mp-wp_genesis 265 *
mp-wp_genesis 266 * @param int $id Optional. Post ID.
mp-wp_genesis 267 * @return bool
mp-wp_genesis 268 */
mp-wp_genesis 269 function has_excerpt( $id = 0 ) {
mp-wp_genesis 270 $post = &get_post( $id );
mp-wp_genesis 271 return ( !empty( $post->post_excerpt ) );
mp-wp_genesis 272 }
mp-wp_genesis 273
mp-wp_genesis 274 /**
mp-wp_genesis 275 * Display the classes for the post div.
mp-wp_genesis 276 *
mp-wp_genesis 277 * @since 2.7.0
mp-wp_genesis 278 *
mp-wp_genesis 279 * @param string|array $class One or more classes to add to the class list.
mp-wp_genesis 280 * @param int $post_id An optional post ID.
mp-wp_genesis 281 */
mp-wp_genesis 282 function post_class( $class = '', $post_id = null ) {
mp-wp_genesis 283 // Separates classes with a single space, collates classes for post DIV
mp-wp_genesis 284 echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
mp-wp_genesis 285 }
mp-wp_genesis 286
mp-wp_genesis 287 /**
mp-wp_genesis 288 * Retrieve the classes for the post div as an array.
mp-wp_genesis 289 *
mp-wp_genesis 290 * The class names are add are many. If the post is a sticky, then the 'sticky'
mp-wp_genesis 291 * class name. The class 'hentry' is always added to each post. For each
mp-wp_genesis 292 * category, the class will be added with 'category-' with category slug is
mp-wp_genesis 293 * added. The tags are the same way as the categories with 'tag-' before the tag
mp-wp_genesis 294 * slug. All classes are passed through the filter, 'post_class' with the list
mp-wp_genesis 295 * of classes, followed by $class parameter value, with the post ID as the last
mp-wp_genesis 296 * parameter.
mp-wp_genesis 297 *
mp-wp_genesis 298 * @since 2.7.0
mp-wp_genesis 299 *
mp-wp_genesis 300 * @param string|array $class One or more classes to add to the class list.
mp-wp_genesis 301 * @param int $post_id An optional post ID.
mp-wp_genesis 302 * @return array Array of classes.
mp-wp_genesis 303 */
mp-wp_genesis 304 function get_post_class( $class = '', $post_id = null ) {
mp-wp_genesis 305 $post = get_post($post_id);
mp-wp_genesis 306
mp-wp_genesis 307 $classes = array();
mp-wp_genesis 308
mp-wp_genesis 309 $classes[] = $post->post_type;
mp-wp_genesis 310
mp-wp_genesis 311 // sticky for Sticky Posts
mp-wp_genesis 312 if ( is_sticky($post->ID) && is_home())
mp-wp_genesis 313 $classes[] = 'sticky';
mp-wp_genesis 314
mp-wp_genesis 315 // hentry for hAtom compliace
mp-wp_genesis 316 $classes[] = 'hentry';
mp-wp_genesis 317
mp-wp_genesis 318 // Categories
mp-wp_genesis 319 foreach ( (array) get_the_category($post->ID) as $cat ) {
mp-wp_genesis 320 if ( empty($cat->slug ) )
mp-wp_genesis 321 continue;
mp-wp_genesis 322 $classes[] = 'category-' . $cat->slug;
mp-wp_genesis 323 }
mp-wp_genesis 324
mp-wp_genesis 325 // Tags
mp-wp_genesis 326 foreach ( (array) get_the_tags($post->ID) as $tag ) {
mp-wp_genesis 327 if ( empty($tag->slug ) )
mp-wp_genesis 328 continue;
mp-wp_genesis 329 $classes[] = 'tag-' . $tag->slug;
mp-wp_genesis 330 }
mp-wp_genesis 331
mp-wp_genesis 332 if ( !empty($class) ) {
mp-wp_genesis 333 if ( !is_array( $class ) )
mp-wp_genesis 334 $class = preg_split('#\s+#', $class);
mp-wp_genesis 335 $classes = array_merge($classes, $class);
mp-wp_genesis 336 }
mp-wp_genesis 337
mp-wp_genesis 338 return apply_filters('post_class', $classes, $class, $post_id);
mp-wp_genesis 339 }
mp-wp_genesis 340
mp-wp_genesis 341 /**
mp-wp_genesis 342 * Whether post requires password and correct password has been provided.
mp-wp_genesis 343 *
mp-wp_genesis 344 * @since 2.7.0
mp-wp_genesis 345 *
mp-wp_genesis 346 * @param int|object $post An optional post. Global $post used if not provided.
mp-wp_genesis 347 * @return bool false if a password is not required or the correct password cookie is present, true otherwise.
mp-wp_genesis 348 */
mp-wp_genesis 349 function post_password_required( $post = null ) {
mp-wp_genesis 350 $post = get_post($post);
mp-wp_genesis 351
mp-wp_genesis 352 if ( empty($post->post_password) )
mp-wp_genesis 353 return false;
mp-wp_genesis 354
mp-wp_genesis 355 if ( !isset($_COOKIE['wp-postpass_' . COOKIEHASH]) )
mp-wp_genesis 356 return true;
mp-wp_genesis 357
mp-wp_genesis 358 if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password )
mp-wp_genesis 359 return true;
mp-wp_genesis 360
mp-wp_genesis 361 return false;
mp-wp_genesis 362 }
mp-wp_genesis 363
mp-wp_genesis 364 /**
mp-wp_genesis 365 * Display "sticky" CSS class, if a post is sticky.
mp-wp_genesis 366 *
mp-wp_genesis 367 * @since 2.7.0
mp-wp_genesis 368 *
mp-wp_genesis 369 * @param int $post_id An optional post ID.
mp-wp_genesis 370 */
mp-wp_genesis 371 function sticky_class( $post_id = null ) {
mp-wp_genesis 372 if ( !is_sticky($post_id) )
mp-wp_genesis 373 return;
mp-wp_genesis 374
mp-wp_genesis 375 echo " sticky";
mp-wp_genesis 376 }
mp-wp_genesis 377
mp-wp_genesis 378 /**
mp-wp_genesis 379 * Page Template Functions for usage in Themes
mp-wp_genesis 380 *
mp-wp_genesis 381 * @package WordPress
mp-wp_genesis 382 * @subpackage Template
mp-wp_genesis 383 */
mp-wp_genesis 384
mp-wp_genesis 385 /**
mp-wp_genesis 386 * The formatted output of a list of pages.
mp-wp_genesis 387 *
mp-wp_genesis 388 * Displays page links for paginated posts (i.e. includes the <!--nextpage-->.
mp-wp_genesis 389 * Quicktag one or more times). This tag must be within The Loop.
mp-wp_genesis 390 *
mp-wp_genesis 391 * The defaults for overwriting are:
mp-wp_genesis 392 * 'next_or_number' - Default is 'number' (string). Indicates whether page
mp-wp_genesis 393 * numbers should be used. Valid values are number and next.
mp-wp_genesis 394 * 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page.
mp-wp_genesis 395 * of the bookmark.
mp-wp_genesis 396 * 'previouspagelink' - Default is 'Previous Page' (string). Text for link to
mp-wp_genesis 397 * previous page, if available.
mp-wp_genesis 398 * 'pagelink' - Default is '%' (String).Format string for page numbers. The % in
mp-wp_genesis 399 * the parameter string will be replaced with the page number, so Page %
mp-wp_genesis 400 * generates "Page 1", "Page 2", etc. Defaults to %, just the page number.
mp-wp_genesis 401 * 'before' - Default is '<p> Pages:' (string). The html or text to prepend to
mp-wp_genesis 402 * each bookmarks.
mp-wp_genesis 403 * 'after' - Default is '</p>' (string). The html or text to append to each
mp-wp_genesis 404 * bookmarks.
mp-wp_genesis 405 * 'more_file' - Default is '' (string) Page the links should point to. Defaults
mp-wp_genesis 406 * to the current page.
mp-wp_genesis 407 * 'link_before' - Default is '' (string). The html or text to prepend to each
mp-wp_genesis 408 * Pages link inside the <a> tag.
mp-wp_genesis 409 * 'link_after' - Default is '' (string). The html or text to append to each
mp-wp_genesis 410 * Pages link inside the <a> tag.
mp-wp_genesis 411 *
mp-wp_genesis 412 * @since 1.2.0
mp-wp_genesis 413 * @access private
mp-wp_genesis 414 *
mp-wp_genesis 415 * @param string|array $args Optional. Overwrite the defaults.
mp-wp_genesis 416 * @return string Formatted output in HTML.
mp-wp_genesis 417 */
mp-wp_genesis 418 function wp_link_pages($args = '') {
mp-wp_genesis 419 $defaults = array(
mp-wp_genesis 420 'before' => '<p>' . __('Pages:'), 'after' => '</p>',
mp-wp_genesis 421 'link_before' => '', 'link_after' => '',
mp-wp_genesis 422 'next_or_number' => 'number', 'nextpagelink' => __('Next page'),
mp-wp_genesis 423 'previouspagelink' => __('Previous page'), 'pagelink' => '%',
mp-wp_genesis 424 'more_file' => '', 'echo' => 1
mp-wp_genesis 425 );
mp-wp_genesis 426
mp-wp_genesis 427 $r = wp_parse_args( $args, $defaults );
mp-wp_genesis 428 extract( $r, EXTR_SKIP );
mp-wp_genesis 429
mp-wp_genesis 430 global $post, $page, $numpages, $multipage, $more, $pagenow;
mp-wp_genesis 431 if ( $more_file != '' )
mp-wp_genesis 432 $file = $more_file;
mp-wp_genesis 433 else
mp-wp_genesis 434 $file = $pagenow;
mp-wp_genesis 435
mp-wp_genesis 436 $output = '';
mp-wp_genesis 437 if ( $multipage ) {
mp-wp_genesis 438 if ( 'number' == $next_or_number ) {
mp-wp_genesis 439 $output .= $before;
mp-wp_genesis 440 for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
mp-wp_genesis 441 $j = str_replace('%',"$i",$pagelink);
mp-wp_genesis 442 $output .= ' ';
mp-wp_genesis 443 if ( ($i != $page) || ((!$more) && ($page==1)) ) {
mp-wp_genesis 444 if ( 1 == $i ) {
mp-wp_genesis 445 $output .= '<a href="' . get_permalink() . '">';
mp-wp_genesis 446 } else {
mp-wp_genesis 447 if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
mp-wp_genesis 448 $output .= '<a href="' . get_permalink() . '&page=' . $i . '">';
mp-wp_genesis 449 else
mp-wp_genesis 450 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">';
mp-wp_genesis 451 }
mp-wp_genesis 452
mp-wp_genesis 453 }
mp-wp_genesis 454 $output .= $link_before;
mp-wp_genesis 455 $output .= $j;
mp-wp_genesis 456 $output .= $link_after;
mp-wp_genesis 457 if ( ($i != $page) || ((!$more) && ($page==1)) )
mp-wp_genesis 458 $output .= '</a>';
mp-wp_genesis 459 }
mp-wp_genesis 460 $output .= $after;
mp-wp_genesis 461 } else {
mp-wp_genesis 462 if ( $more ) {
mp-wp_genesis 463 $output .= $before;
mp-wp_genesis 464 $i = $page - 1;
mp-wp_genesis 465 if ( $i && $more ) {
mp-wp_genesis 466 if ( 1 == $i ) {
mp-wp_genesis 467 $output .= '<a href="' . get_permalink() . '">' . $link_before. $previouspagelink . $link_after . '</a>';
mp-wp_genesis 468 } else {
mp-wp_genesis 469 if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
mp-wp_genesis 470 $output .= '<a href="' . get_permalink() . '&page=' . $i . '">' . $link_before. $previouspagelink . $link_after . '</a>';
mp-wp_genesis 471 else
mp-wp_genesis 472 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">' . $link_before. $previouspagelink . $link_after . '</a>';
mp-wp_genesis 473 }
mp-wp_genesis 474 }
mp-wp_genesis 475 $i = $page + 1;
mp-wp_genesis 476 if ( $i <= $numpages && $more ) {
mp-wp_genesis 477 if ( 1 == $i ) {
mp-wp_genesis 478 $output .= '<a href="' . get_permalink() . '">' . $link_before. $nextpagelink . $link_after . '</a>';
mp-wp_genesis 479 } else {
mp-wp_genesis 480 if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
mp-wp_genesis 481 $output .= '<a href="' . get_permalink() . '&page=' . $i . '">' . $link_before. $nextpagelink . $link_after . '</a>';
mp-wp_genesis 482 else
mp-wp_genesis 483 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">' . $link_before. $nextpagelink . $link_after . '</a>';
mp-wp_genesis 484 }
mp-wp_genesis 485 }
mp-wp_genesis 486 $output .= $after;
mp-wp_genesis 487 }
mp-wp_genesis 488 }
mp-wp_genesis 489 }
mp-wp_genesis 490
mp-wp_genesis 491 if ( $echo )
mp-wp_genesis 492 echo $output;
mp-wp_genesis 493
mp-wp_genesis 494 return $output;
mp-wp_genesis 495 }
mp-wp_genesis 496
mp-wp_genesis 497
mp-wp_genesis 498 //
mp-wp_genesis 499 // Post-meta: Custom per-post fields.
mp-wp_genesis 500 //
mp-wp_genesis 501
mp-wp_genesis 502 /**
mp-wp_genesis 503 * Retrieve post custom meta data field.
mp-wp_genesis 504 *
mp-wp_genesis 505 * @since 1.5.0
mp-wp_genesis 506 *
mp-wp_genesis 507 * @param string $key Meta data key name.
mp-wp_genesis 508 * @return string|array Array of values or single value, if only one element exists.
mp-wp_genesis 509 */
mp-wp_genesis 510 function post_custom( $key = '' ) {
mp-wp_genesis 511 $custom = get_post_custom();
mp-wp_genesis 512
mp-wp_genesis 513 if ( 1 == count($custom[$key]) )
mp-wp_genesis 514 return $custom[$key][0];
mp-wp_genesis 515 else
mp-wp_genesis 516 return $custom[$key];
mp-wp_genesis 517 }
mp-wp_genesis 518
mp-wp_genesis 519 /**
mp-wp_genesis 520 * Display list of post custom fields.
mp-wp_genesis 521 *
mp-wp_genesis 522 * @internal This will probably change at some point...
mp-wp_genesis 523 * @since 1.2.0
mp-wp_genesis 524 * @uses apply_filters() Calls 'the_meta_key' on list item HTML content, with key and value as separate parameters.
mp-wp_genesis 525 */
mp-wp_genesis 526 function the_meta() {
mp-wp_genesis 527 if ( $keys = get_post_custom_keys() ) {
mp-wp_genesis 528 echo "<ul class='post-meta'>\n";
mp-wp_genesis 529 foreach ( (array) $keys as $key ) {
mp-wp_genesis 530 $keyt = trim($key);
mp-wp_genesis 531 if ( '_' == $keyt{0} )
mp-wp_genesis 532 continue;
mp-wp_genesis 533 $values = array_map('trim', get_post_custom_values($key));
mp-wp_genesis 534 $value = implode($values,', ');
mp-wp_genesis 535 echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);
mp-wp_genesis 536 }
mp-wp_genesis 537 echo "</ul>\n";
mp-wp_genesis 538 }
mp-wp_genesis 539 }
mp-wp_genesis 540
mp-wp_genesis 541 //
mp-wp_genesis 542 // Pages
mp-wp_genesis 543 //
mp-wp_genesis 544
mp-wp_genesis 545 /**
mp-wp_genesis 546 * Retrieve or display list of pages as a dropdown (select list).
mp-wp_genesis 547 *
mp-wp_genesis 548 * @since 2.1.0
mp-wp_genesis 549 *
mp-wp_genesis 550 * @param array|string $args Optional. Override default arguments.
mp-wp_genesis 551 * @return string HTML content, if not displaying.
mp-wp_genesis 552 */
mp-wp_genesis 553 function wp_dropdown_pages($args = '') {
mp-wp_genesis 554 $defaults = array(
mp-wp_genesis 555 'depth' => 0, 'child_of' => 0,
mp-wp_genesis 556 'selected' => 0, 'echo' => 1,
mp-wp_genesis 557 'name' => 'page_id', 'show_option_none' => '', 'show_option_no_change' => '',
mp-wp_genesis 558 'option_none_value' => ''
mp-wp_genesis 559 );
mp-wp_genesis 560
mp-wp_genesis 561 $r = wp_parse_args( $args, $defaults );
mp-wp_genesis 562 extract( $r, EXTR_SKIP );
mp-wp_genesis 563
mp-wp_genesis 564 $pages = get_pages($r);
mp-wp_genesis 565 $output = '';
mp-wp_genesis 566
mp-wp_genesis 567 if ( ! empty($pages) ) {
mp-wp_genesis 568 $output = "<select name=\"$name\" id=\"$name\">\n";
mp-wp_genesis 569 if ( $show_option_no_change )
mp-wp_genesis 570 $output .= "\t<option value=\"-1\">$show_option_no_change</option>";
mp-wp_genesis 571 if ( $show_option_none )
mp-wp_genesis 572 $output .= "\t<option value=\"$option_none_value\">$show_option_none</option>\n";
mp-wp_genesis 573 $output .= walk_page_dropdown_tree($pages, $depth, $r);
mp-wp_genesis 574 $output .= "</select>\n";
mp-wp_genesis 575 }
mp-wp_genesis 576
mp-wp_genesis 577 $output = apply_filters('wp_dropdown_pages', $output);
mp-wp_genesis 578
mp-wp_genesis 579 if ( $echo )
mp-wp_genesis 580 echo $output;
mp-wp_genesis 581
mp-wp_genesis 582 return $output;
mp-wp_genesis 583 }
mp-wp_genesis 584
mp-wp_genesis 585 /**
mp-wp_genesis 586 * Retrieve or display list of pages in list (li) format.
mp-wp_genesis 587 *
mp-wp_genesis 588 * @since 1.5.0
mp-wp_genesis 589 *
mp-wp_genesis 590 * @param array|string $args Optional. Override default arguments.
mp-wp_genesis 591 * @return string HTML content, if not displaying.
mp-wp_genesis 592 */
mp-wp_genesis 593 function wp_list_pages($args = '') {
mp-wp_genesis 594 $defaults = array(
mp-wp_genesis 595 'depth' => 0, 'show_date' => '',
mp-wp_genesis 596 'date_format' => get_option('date_format'),
mp-wp_genesis 597 'child_of' => 0, 'exclude' => '',
mp-wp_genesis 598 'title_li' => __('Pages'), 'echo' => 1,
mp-wp_genesis 599 'authors' => '', 'sort_column' => 'menu_order, post_title',
mp-wp_genesis 600 'link_before' => '', 'link_after' => ''
mp-wp_genesis 601 );
mp-wp_genesis 602
mp-wp_genesis 603 $r = wp_parse_args( $args, $defaults );
mp-wp_genesis 604 extract( $r, EXTR_SKIP );
mp-wp_genesis 605
mp-wp_genesis 606 $output = '';
mp-wp_genesis 607 $current_page = 0;
mp-wp_genesis 608
mp-wp_genesis 609 // sanitize, mostly to keep spaces out
mp-wp_genesis 610 $r['exclude'] = preg_replace('[^0-9,]', '', $r['exclude']);
mp-wp_genesis 611
mp-wp_genesis 612 // Allow plugins to filter an array of excluded pages
mp-wp_genesis 613 $r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', explode(',', $r['exclude'])));
mp-wp_genesis 614
mp-wp_genesis 615 // Query pages.
mp-wp_genesis 616 $r['hierarchical'] = 0;
mp-wp_genesis 617 $pages = get_pages($r);
mp-wp_genesis 618
mp-wp_genesis 619 if ( !empty($pages) ) {
mp-wp_genesis 620 if ( $r['title_li'] )
mp-wp_genesis 621 $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
mp-wp_genesis 622
mp-wp_genesis 623 global $wp_query;
mp-wp_genesis 624 if ( is_page() || $wp_query->is_posts_page )
mp-wp_genesis 625 $current_page = $wp_query->get_queried_object_id();
mp-wp_genesis 626 $output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
mp-wp_genesis 627
mp-wp_genesis 628 if ( $r['title_li'] )
mp-wp_genesis 629 $output .= '</ul></li>';
mp-wp_genesis 630 }
mp-wp_genesis 631
mp-wp_genesis 632 $output = apply_filters('wp_list_pages', $output);
mp-wp_genesis 633
mp-wp_genesis 634 if ( $r['echo'] )
mp-wp_genesis 635 echo $output;
mp-wp_genesis 636 else
mp-wp_genesis 637 return $output;
mp-wp_genesis 638 }
mp-wp_genesis 639
mp-wp_genesis 640 /**
mp-wp_genesis 641 * Display or retrieve list of pages with optional home link.
mp-wp_genesis 642 *
mp-wp_genesis 643 * The arguments are listed below and part of the arguments are for {@link
mp-wp_genesis 644 * wp_list_pages()} function. Check that function for more info on those
mp-wp_genesis 645 * arguments.
mp-wp_genesis 646 *
mp-wp_genesis 647 * <ul>
mp-wp_genesis 648 * <li><strong>sort_column</strong> - How to sort the list of pages. Defaults
mp-wp_genesis 649 * to page title. Use column for posts table.</li>
mp-wp_genesis 650 * <li><strong>menu_class</strong> - Class to use for the div ID which contains
mp-wp_genesis 651 * the page list. Defaults to 'menu'.</li>
mp-wp_genesis 652 * <li><strong>echo</strong> - Whether to echo list or return it. Defaults to
mp-wp_genesis 653 * echo.</li>
mp-wp_genesis 654 * <li><strong>link_before</strong> - Text before show_home argument text.</li>
mp-wp_genesis 655 * <li><strong>link_after</strong> - Text after show_home argument text.</li>
mp-wp_genesis 656 * <li><strong>show_home</strong> - If you set this argument, then it will
mp-wp_genesis 657 * display the link to the home page. The show_home argument really just needs
mp-wp_genesis 658 * to be set to the value of the text of the link.</li>
mp-wp_genesis 659 * </ul>
mp-wp_genesis 660 *
mp-wp_genesis 661 * @since 2.7.0
mp-wp_genesis 662 *
mp-wp_genesis 663 * @param array|string $args
mp-wp_genesis 664 */
mp-wp_genesis 665 function wp_page_menu( $args = array() ) {
mp-wp_genesis 666 $defaults = array('sort_column' => 'post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => '');
mp-wp_genesis 667 $args = wp_parse_args( $args, $defaults );
mp-wp_genesis 668 $args = apply_filters( 'wp_page_menu_args', $args );
mp-wp_genesis 669
mp-wp_genesis 670 $menu = '';
mp-wp_genesis 671
mp-wp_genesis 672 $list_args = $args;
mp-wp_genesis 673
mp-wp_genesis 674 // Show Home in the menu
mp-wp_genesis 675 if ( isset($args['show_home']) && ! empty($args['show_home']) ) {
mp-wp_genesis 676 if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] )
mp-wp_genesis 677 $text = __('Home');
mp-wp_genesis 678 else
mp-wp_genesis 679 $text = $args['show_home'];
mp-wp_genesis 680 $class = '';
mp-wp_genesis 681 if ( is_front_page() && !is_paged() )
mp-wp_genesis 682 $class = 'class="current_page_item"';
mp-wp_genesis 683 $menu .= '<li ' . $class . '><a href="' . get_option('home') . '">' . $link_before . $text . $link_after . '</a></li>';
mp-wp_genesis 684 // If the front page is a page, add it to the exclude list
mp-wp_genesis 685 if (get_option('show_on_front') == 'page') {
mp-wp_genesis 686 if ( !empty( $list_args['exclude'] ) ) {
mp-wp_genesis 687 $list_args['exclude'] .= ',';
mp-wp_genesis 688 } else {
mp-wp_genesis 689 $list_args['exclude'] = '';
mp-wp_genesis 690 }
mp-wp_genesis 691 $list_args['exclude'] .= get_option('page_on_front');
mp-wp_genesis 692 }
mp-wp_genesis 693 }
mp-wp_genesis 694
mp-wp_genesis 695 $list_args['echo'] = false;
mp-wp_genesis 696 $list_args['title_li'] = '';
mp-wp_genesis 697 $menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) );
mp-wp_genesis 698
mp-wp_genesis 699 if ( $menu )
mp-wp_genesis 700 $menu = '<ul>' . $menu . '</ul>';
mp-wp_genesis 701
mp-wp_genesis 702 $menu = '<div class="' . $args['menu_class'] . '">' . $menu . "</div>\n";
mp-wp_genesis 703 $menu = apply_filters( 'wp_page_menu', $menu, $args );
mp-wp_genesis 704 if ( $args['echo'] )
mp-wp_genesis 705 echo $menu;
mp-wp_genesis 706 else
mp-wp_genesis 707 return $menu;
mp-wp_genesis 708 }
mp-wp_genesis 709
mp-wp_genesis 710 //
mp-wp_genesis 711 // Page helpers
mp-wp_genesis 712 //
mp-wp_genesis 713
mp-wp_genesis 714 /**
mp-wp_genesis 715 * Retrieve HTML list content for page list.
mp-wp_genesis 716 *
mp-wp_genesis 717 * @uses Walker_Page to create HTML list content.
mp-wp_genesis 718 * @since 2.1.0
mp-wp_genesis 719 * @see Walker_Page::walk() for parameters and return description.
mp-wp_genesis 720 */
mp-wp_genesis 721 function walk_page_tree($pages, $depth, $current_page, $r) {
mp-wp_genesis 722 $walker = new Walker_Page;
mp-wp_genesis 723 $args = array($pages, $depth, $r, $current_page);
mp-wp_genesis 724 return call_user_func_array(array(&$walker, 'walk'), $args);
mp-wp_genesis 725 }
mp-wp_genesis 726
mp-wp_genesis 727 /**
mp-wp_genesis 728 * Retrieve HTML dropdown (select) content for page list.
mp-wp_genesis 729 *
mp-wp_genesis 730 * @uses Walker_PageDropdown to create HTML dropdown content.
mp-wp_genesis 731 * @since 2.1.0
mp-wp_genesis 732 * @see Walker_PageDropdown::walk() for parameters and return description.
mp-wp_genesis 733 */
mp-wp_genesis 734 function walk_page_dropdown_tree() {
mp-wp_genesis 735 $walker = new Walker_PageDropdown;
mp-wp_genesis 736 $args = func_get_args();
mp-wp_genesis 737 return call_user_func_array(array(&$walker, 'walk'), $args);
mp-wp_genesis 738 }
mp-wp_genesis 739
mp-wp_genesis 740 //
mp-wp_genesis 741 // Attachments
mp-wp_genesis 742 //
mp-wp_genesis 743
mp-wp_genesis 744 /**
mp-wp_genesis 745 * Display an attachment page link using an image or icon.
mp-wp_genesis 746 *
mp-wp_genesis 747 * @since 2.0.0
mp-wp_genesis 748 *
mp-wp_genesis 749 * @param int $id Optional. Post ID.
mp-wp_genesis 750 * @param bool $fullsize Optional, default is false. Whether to use full size.
mp-wp_genesis 751 * @param bool $deprecated Deprecated. Not used.
mp-wp_genesis 752 * @param bool $permalink Optional, default is false. Whether to include permalink.
mp-wp_genesis 753 */
mp-wp_genesis 754 function the_attachment_link($id = 0, $fullsize = false, $deprecated = false, $permalink = false) {
mp-wp_genesis 755 if ( $fullsize )
mp-wp_genesis 756 echo wp_get_attachment_link($id, 'full', $permalink);
mp-wp_genesis 757 else
mp-wp_genesis 758 echo wp_get_attachment_link($id, 'thumbnail', $permalink);
mp-wp_genesis 759 }
mp-wp_genesis 760
mp-wp_genesis 761 /**
mp-wp_genesis 762 * Retrieve an attachment page link using an image or icon, if possible.
mp-wp_genesis 763 *
mp-wp_genesis 764 * @since 2.5.0
mp-wp_genesis 765 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
mp-wp_genesis 766 *
mp-wp_genesis 767 * @param int $id Optional. Post ID.
mp-wp_genesis 768 * @param string $size Optional. Image size.
mp-wp_genesis 769 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
mp-wp_genesis 770 * @param bool $icon Optional, default is false. Whether to include icon.
mp-wp_genesis 771 * @return string HTML content.
mp-wp_genesis 772 */
mp-wp_genesis 773 function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false) {
mp-wp_genesis 774 $id = intval($id);
mp-wp_genesis 775 $_post = & get_post( $id );
mp-wp_genesis 776
mp-wp_genesis 777 if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) )
mp-wp_genesis 778 return __('Missing Attachment');
mp-wp_genesis 779
mp-wp_genesis 780 if ( $permalink )
mp-wp_genesis 781 $url = get_attachment_link($_post->ID);
mp-wp_genesis 782
mp-wp_genesis 783 $post_title = attribute_escape($_post->post_title);
mp-wp_genesis 784
mp-wp_genesis 785 $link_text = wp_get_attachment_image($id, $size, $icon);
mp-wp_genesis 786 if ( !$link_text )
mp-wp_genesis 787 $link_text = $_post->post_title;
mp-wp_genesis 788
mp-wp_genesis 789 return apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon );
mp-wp_genesis 790 }
mp-wp_genesis 791
mp-wp_genesis 792 /**
mp-wp_genesis 793 * Retrieve HTML content of attachment image with link.
mp-wp_genesis 794 *
mp-wp_genesis 795 * @since 2.0.0
mp-wp_genesis 796 * @deprecated Use {@link wp_get_attachment_link()}
mp-wp_genesis 797 * @see wp_get_attachment_link() Use instead.
mp-wp_genesis 798 *
mp-wp_genesis 799 * @param int $id Optional. Post ID.
mp-wp_genesis 800 * @param bool $fullsize Optional, default is false. Whether to use full size image.
mp-wp_genesis 801 * @param array $max_dims Optional. Max image dimensions.
mp-wp_genesis 802 * @param bool $permalink Optional, default is false. Whether to include permalink to image.
mp-wp_genesis 803 * @return string
mp-wp_genesis 804 */
mp-wp_genesis 805 function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false, $permalink = false) {
mp-wp_genesis 806 $id = (int) $id;
mp-wp_genesis 807 $_post = & get_post($id);
mp-wp_genesis 808
mp-wp_genesis 809 if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) )
mp-wp_genesis 810 return __('Missing Attachment');
mp-wp_genesis 811
mp-wp_genesis 812 if ( $permalink )
mp-wp_genesis 813 $url = get_attachment_link($_post->ID);
mp-wp_genesis 814
mp-wp_genesis 815 $post_title = attribute_escape($_post->post_title);
mp-wp_genesis 816
mp-wp_genesis 817 $innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims);
mp-wp_genesis 818 return "<a href='$url' title='$post_title'>$innerHTML</a>";
mp-wp_genesis 819 }
mp-wp_genesis 820
mp-wp_genesis 821 /**
mp-wp_genesis 822 * Retrieve icon URL and Path.
mp-wp_genesis 823 *
mp-wp_genesis 824 * @since 2.1.0
mp-wp_genesis 825 * @deprecated Use {@link wp_get_attachment_image_src()}
mp-wp_genesis 826 * @see wp_get_attachment_image_src() Use instead.
mp-wp_genesis 827 *
mp-wp_genesis 828 * @param int $id Optional. Post ID.
mp-wp_genesis 829 * @param bool $fullsize Optional, default to false. Whether to have full image.
mp-wp_genesis 830 * @return array Icon URL and full path to file, respectively.
mp-wp_genesis 831 */
mp-wp_genesis 832 function get_attachment_icon_src( $id = 0, $fullsize = false ) {
mp-wp_genesis 833 $id = (int) $id;
mp-wp_genesis 834 if ( !$post = & get_post($id) )
mp-wp_genesis 835 return false;
mp-wp_genesis 836
mp-wp_genesis 837 $file = get_attached_file( $post->ID );
mp-wp_genesis 838
mp-wp_genesis 839 if ( !$fullsize && $src = wp_get_attachment_thumb_url( $post->ID ) ) {
mp-wp_genesis 840 // We have a thumbnail desired, specified and existing
mp-wp_genesis 841
mp-wp_genesis 842 $src_file = basename($src);
mp-wp_genesis 843 $class = 'attachmentthumb';
mp-wp_genesis 844 } elseif ( wp_attachment_is_image( $post->ID ) ) {
mp-wp_genesis 845 // We have an image without a thumbnail
mp-wp_genesis 846
mp-wp_genesis 847 $src = wp_get_attachment_url( $post->ID );
mp-wp_genesis 848 $src_file = & $file;
mp-wp_genesis 849 $class = 'attachmentimage';
mp-wp_genesis 850 } elseif ( $src = wp_mime_type_icon( $post->ID ) ) {
mp-wp_genesis 851 // No thumb, no image. We'll look for a mime-related icon instead.
mp-wp_genesis 852
mp-wp_genesis 853 $icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' );
mp-wp_genesis 854 $src_file = $icon_dir . '/' . basename($src);
mp-wp_genesis 855 }
mp-wp_genesis 856
mp-wp_genesis 857 if ( !isset($src) || !$src )
mp-wp_genesis 858 return false;
mp-wp_genesis 859
mp-wp_genesis 860 return array($src, $src_file);
mp-wp_genesis 861 }
mp-wp_genesis 862
mp-wp_genesis 863 /**
mp-wp_genesis 864 * Retrieve HTML content of icon attachment image element.
mp-wp_genesis 865 *
mp-wp_genesis 866 * @since 2.0.0
mp-wp_genesis 867 * @deprecated Use {@link wp_get_attachment_image()}
mp-wp_genesis 868 * @see wp_get_attachment_image() Use instead of.
mp-wp_genesis 869 *
mp-wp_genesis 870 * @param int $id Optional. Post ID.
mp-wp_genesis 871 * @param bool $fullsize Optional, default to false. Whether to have full size image.
mp-wp_genesis 872 * @param array $max_dims Optional. Dimensions of image.
mp-wp_genesis 873 * @return string HTML content.
mp-wp_genesis 874 */
mp-wp_genesis 875 function get_attachment_icon( $id = 0, $fullsize = false, $max_dims = false ) {
mp-wp_genesis 876 $id = (int) $id;
mp-wp_genesis 877 if ( !$post = & get_post($id) )
mp-wp_genesis 878 return false;
mp-wp_genesis 879
mp-wp_genesis 880 if ( !$src = get_attachment_icon_src( $post->ID, $fullsize ) )
mp-wp_genesis 881 return false;
mp-wp_genesis 882
mp-wp_genesis 883 list($src, $src_file) = $src;
mp-wp_genesis 884
mp-wp_genesis 885 // Do we need to constrain the image?
mp-wp_genesis 886 if ( ($max_dims = apply_filters('attachment_max_dims', $max_dims)) && file_exists($src_file) ) {
mp-wp_genesis 887
mp-wp_genesis 888 $imagesize = getimagesize($src_file);
mp-wp_genesis 889
mp-wp_genesis 890 if (($imagesize[0] > $max_dims[0]) || $imagesize[1] > $max_dims[1] ) {
mp-wp_genesis 891 $actual_aspect = $imagesize[0] / $imagesize[1];
mp-wp_genesis 892 $desired_aspect = $max_dims[0] / $max_dims[1];
mp-wp_genesis 893
mp-wp_genesis 894 if ( $actual_aspect >= $desired_aspect ) {
mp-wp_genesis 895 $height = $actual_aspect * $max_dims[0];
mp-wp_genesis 896 $constraint = "width='{$max_dims[0]}' ";
mp-wp_genesis 897 $post->iconsize = array($max_dims[0], $height);
mp-wp_genesis 898 } else {
mp-wp_genesis 899 $width = $max_dims[1] / $actual_aspect;
mp-wp_genesis 900 $constraint = "height='{$max_dims[1]}' ";
mp-wp_genesis 901 $post->iconsize = array($width, $max_dims[1]);
mp-wp_genesis 902 }
mp-wp_genesis 903 } else {
mp-wp_genesis 904 $post->iconsize = array($imagesize[0], $imagesize[1]);
mp-wp_genesis 905 $constraint = '';
mp-wp_genesis 906 }
mp-wp_genesis 907 } else {
mp-wp_genesis 908 $constraint = '';
mp-wp_genesis 909 }
mp-wp_genesis 910
mp-wp_genesis 911 $post_title = attribute_escape($post->post_title);
mp-wp_genesis 912
mp-wp_genesis 913 $icon = "<img src='$src' title='$post_title' alt='$post_title' $constraint/>";
mp-wp_genesis 914
mp-wp_genesis 915 return apply_filters( 'attachment_icon', $icon, $post->ID );
mp-wp_genesis 916 }
mp-wp_genesis 917
mp-wp_genesis 918 /**
mp-wp_genesis 919 * Retrieve HTML content of image element.
mp-wp_genesis 920 *
mp-wp_genesis 921 * @since 2.0.0
mp-wp_genesis 922 * @deprecated Use {@link wp_get_attachment_image()}
mp-wp_genesis 923 * @see wp_get_attachment_image() Use instead.
mp-wp_genesis 924 *
mp-wp_genesis 925 * @param int $id Optional. Post ID.
mp-wp_genesis 926 * @param bool $fullsize Optional, default to false. Whether to have full size image.
mp-wp_genesis 927 * @param array $max_dims Optional. Dimensions of image.
mp-wp_genesis 928 * @return string
mp-wp_genesis 929 */
mp-wp_genesis 930 function get_attachment_innerHTML($id = 0, $fullsize = false, $max_dims = false) {
mp-wp_genesis 931 $id = (int) $id;
mp-wp_genesis 932 if ( !$post = & get_post($id) )
mp-wp_genesis 933 return false;
mp-wp_genesis 934
mp-wp_genesis 935 if ( $innerHTML = get_attachment_icon($post->ID, $fullsize, $max_dims))
mp-wp_genesis 936 return $innerHTML;
mp-wp_genesis 937
mp-wp_genesis 938
mp-wp_genesis 939 $innerHTML = attribute_escape($post->post_title);
mp-wp_genesis 940
mp-wp_genesis 941 return apply_filters('attachment_innerHTML', $innerHTML, $post->ID);
mp-wp_genesis 942 }
mp-wp_genesis 943
mp-wp_genesis 944 /**
mp-wp_genesis 945 * Wrap attachment in <<p>> element before content.
mp-wp_genesis 946 *
mp-wp_genesis 947 * @since 2.0.0
mp-wp_genesis 948 * @uses apply_filters() Calls 'prepend_attachment' hook on HTML content.
mp-wp_genesis 949 *
mp-wp_genesis 950 * @param string $content
mp-wp_genesis 951 * @return string
mp-wp_genesis 952 */
mp-wp_genesis 953 function prepend_attachment($content) {
mp-wp_genesis 954 global $post;
mp-wp_genesis 955
mp-wp_genesis 956 if ( empty($post->post_type) || $post->post_type != 'attachment' )
mp-wp_genesis 957 return $content;
mp-wp_genesis 958
mp-wp_genesis 959 $p = '<p class="attachment">';
mp-wp_genesis 960 // show the medium sized image representation of the attachment if available, and link to the raw file
mp-wp_genesis 961 $p .= wp_get_attachment_link(0, 'medium', false);
mp-wp_genesis 962 $p .= '</p>';
mp-wp_genesis 963 $p = apply_filters('prepend_attachment', $p);
mp-wp_genesis 964
mp-wp_genesis 965 return "$p\n$content";
mp-wp_genesis 966 }
mp-wp_genesis 967
mp-wp_genesis 968 //
mp-wp_genesis 969 // Misc
mp-wp_genesis 970 //
mp-wp_genesis 971
mp-wp_genesis 972 /**
mp-wp_genesis 973 * Retrieve protected post password form content.
mp-wp_genesis 974 *
mp-wp_genesis 975 * @since 1.0.0
mp-wp_genesis 976 * @uses apply_filters() Calls 'the_password_form' filter on output.
mp-wp_genesis 977 *
mp-wp_genesis 978 * @return string HTML content for password form for password protected post.
mp-wp_genesis 979 */
mp-wp_genesis 980 function get_the_password_form() {
mp-wp_genesis 981 global $post;
mp-wp_genesis 982 $label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
mp-wp_genesis 983 $output = '<form action="' . get_option('siteurl') . '/wp-pass.php" method="post">
mp-wp_genesis 984 <p>' . __("This post is password protected. To view it please enter your password below:") . '</p>
mp-wp_genesis 985 <p><label for="' . $label . '">' . __("Password:") . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . __("Submit") . '" /></p>
mp-wp_genesis 986 </form>
mp-wp_genesis 987 ';
mp-wp_genesis 988 return apply_filters('the_password_form', $output);
mp-wp_genesis 989 }
mp-wp_genesis 990
mp-wp_genesis 991 /**
mp-wp_genesis 992 * Whether currently in a page template.
mp-wp_genesis 993 *
mp-wp_genesis 994 * This template tag allows you to determine whether or not you are in a page
mp-wp_genesis 995 * template. You can optional provide a template name and then the check will be
mp-wp_genesis 996 * specific to that template.
mp-wp_genesis 997 *
mp-wp_genesis 998 * @since 2.5.0
mp-wp_genesis 999 * @uses $wp_query
mp-wp_genesis 1000 *
mp-wp_genesis 1001 * @param string $template The specific template name if specific matching is required.
mp-wp_genesis 1002 * @return bool False on failure, true if success.
mp-wp_genesis 1003 */
mp-wp_genesis 1004 function is_page_template($template = '') {
mp-wp_genesis 1005 if (!is_page()) {
mp-wp_genesis 1006 return false;
mp-wp_genesis 1007 }
mp-wp_genesis 1008
mp-wp_genesis 1009 global $wp_query;
mp-wp_genesis 1010
mp-wp_genesis 1011 $page = $wp_query->get_queried_object();
mp-wp_genesis 1012 $custom_fields = get_post_custom_values('_wp_page_template',$page->ID);
mp-wp_genesis 1013 $page_template = $custom_fields[0];
mp-wp_genesis 1014
mp-wp_genesis 1015 // We have no argument passed so just see if a page_template has been specified
mp-wp_genesis 1016 if ( empty( $template ) ) {
mp-wp_genesis 1017 if (!empty( $page_template ) ) {
mp-wp_genesis 1018 return true;
mp-wp_genesis 1019 }
mp-wp_genesis 1020 } elseif ( $template == $page_template) {
mp-wp_genesis 1021 return true;
mp-wp_genesis 1022 }
mp-wp_genesis 1023
mp-wp_genesis 1024 return false;
mp-wp_genesis 1025 }
mp-wp_genesis 1026
mp-wp_genesis 1027 /**
mp-wp_genesis 1028 * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
mp-wp_genesis 1029 *
mp-wp_genesis 1030 * @package WordPress
mp-wp_genesis 1031 * @subpackage Post_Revisions
mp-wp_genesis 1032 * @since 2.6.0
mp-wp_genesis 1033 *
mp-wp_genesis 1034 * @uses date_i18n()
mp-wp_genesis 1035 *
mp-wp_genesis 1036 * @param int|object $revision Revision ID or revision object.
mp-wp_genesis 1037 * @param bool $link Optional, default is true. Link to revisions's page?
mp-wp_genesis 1038 * @return string i18n formatted datetimestamp or localized 'Current Revision'.
mp-wp_genesis 1039 */
mp-wp_genesis 1040 function wp_post_revision_title( $revision, $link = true ) {
mp-wp_genesis 1041 if ( !$revision = get_post( $revision ) )
mp-wp_genesis 1042 return $revision;
mp-wp_genesis 1043
mp-wp_genesis 1044 if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
mp-wp_genesis 1045 return false;
mp-wp_genesis 1046
mp-wp_genesis 1047 $datef = _c( 'j F, Y @ G:i|revision date format');
mp-wp_genesis 1048 $autosavef = __( '%s [Autosave]' );
mp-wp_genesis 1049 $currentf = __( '%s [Current Revision]' );
mp-wp_genesis 1050
mp-wp_genesis 1051 $date = date_i18n( $datef, strtotime( $revision->post_modified_gmt . ' +0000' ) );
mp-wp_genesis 1052 if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
mp-wp_genesis 1053 $date = "<a href='$link'>$date</a>";
mp-wp_genesis 1054
mp-wp_genesis 1055 if ( !wp_is_post_revision( $revision ) )
mp-wp_genesis 1056 $date = sprintf( $currentf, $date );
mp-wp_genesis 1057 elseif ( wp_is_post_autosave( $revision ) )
mp-wp_genesis 1058 $date = sprintf( $autosavef, $date );
mp-wp_genesis 1059
mp-wp_genesis 1060 return $date;
mp-wp_genesis 1061 }
mp-wp_genesis 1062
mp-wp_genesis 1063 /**
mp-wp_genesis 1064 * Display list of a post's revisions.
mp-wp_genesis 1065 *
mp-wp_genesis 1066 * Can output either a UL with edit links or a TABLE with diff interface, and
mp-wp_genesis 1067 * restore action links.
mp-wp_genesis 1068 *
mp-wp_genesis 1069 * Second argument controls parameters:
mp-wp_genesis 1070 * (bool) parent : include the parent (the "Current Revision") in the list.
mp-wp_genesis 1071 * (string) format : 'list' or 'form-table'. 'list' outputs UL, 'form-table'
mp-wp_genesis 1072 * outputs TABLE with UI.
mp-wp_genesis 1073 * (int) right : what revision is currently being viewed - used in
mp-wp_genesis 1074 * form-table format.
mp-wp_genesis 1075 * (int) left : what revision is currently being diffed against right -
mp-wp_genesis 1076 * used in form-table format.
mp-wp_genesis 1077 *
mp-wp_genesis 1078 * @package WordPress
mp-wp_genesis 1079 * @subpackage Post_Revisions
mp-wp_genesis 1080 * @since 2.6.0
mp-wp_genesis 1081 *
mp-wp_genesis 1082 * @uses wp_get_post_revisions()
mp-wp_genesis 1083 * @uses wp_post_revision_title()
mp-wp_genesis 1084 * @uses get_edit_post_link()
mp-wp_genesis 1085 * @uses get_author_name()
mp-wp_genesis 1086 *
mp-wp_genesis 1087 * @todo split into two functions (list, form-table) ?
mp-wp_genesis 1088 *
mp-wp_genesis 1089 * @param int|object $post_id Post ID or post object.
mp-wp_genesis 1090 * @param string|array $args See description {@link wp_parse_args()}.
mp-wp_genesis 1091 * @return null
mp-wp_genesis 1092 */
mp-wp_genesis 1093 function wp_list_post_revisions( $post_id = 0, $args = null ) {
mp-wp_genesis 1094 if ( !$post = get_post( $post_id ) )
mp-wp_genesis 1095 return;
mp-wp_genesis 1096
mp-wp_genesis 1097 $defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list', 'type' => 'all' );
mp-wp_genesis 1098 extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
mp-wp_genesis 1099
mp-wp_genesis 1100 switch ( $type ) {
mp-wp_genesis 1101 case 'autosave' :
mp-wp_genesis 1102 if ( !$autosave = wp_get_post_autosave( $post->ID ) )
mp-wp_genesis 1103 return;
mp-wp_genesis 1104 $revisions = array( $autosave );
mp-wp_genesis 1105 break;
mp-wp_genesis 1106 case 'revision' : // just revisions - remove autosave later
mp-wp_genesis 1107 case 'all' :
mp-wp_genesis 1108 default :
mp-wp_genesis 1109 if ( !$revisions = wp_get_post_revisions( $post->ID ) )
mp-wp_genesis 1110 return;
mp-wp_genesis 1111 break;
mp-wp_genesis 1112 }
mp-wp_genesis 1113
mp-wp_genesis 1114 $titlef = _c( '%1$s by %2$s|post revision 1:datetime, 2:name' );
mp-wp_genesis 1115
mp-wp_genesis 1116 if ( $parent )
mp-wp_genesis 1117 array_unshift( $revisions, $post );
mp-wp_genesis 1118
mp-wp_genesis 1119 $rows = '';
mp-wp_genesis 1120 $class = false;
mp-wp_genesis 1121 $can_edit_post = current_user_can( 'edit_post', $post->ID );
mp-wp_genesis 1122 foreach ( $revisions as $revision ) {
mp-wp_genesis 1123 if ( !current_user_can( 'read_post', $revision->ID ) )
mp-wp_genesis 1124 continue;
mp-wp_genesis 1125 if ( 'revision' === $type && wp_is_post_autosave( $revision ) )
mp-wp_genesis 1126 continue;
mp-wp_genesis 1127
mp-wp_genesis 1128 $date = wp_post_revision_title( $revision );
mp-wp_genesis 1129 $name = get_author_name( $revision->post_author );
mp-wp_genesis 1130
mp-wp_genesis 1131 if ( 'form-table' == $format ) {
mp-wp_genesis 1132 if ( $left )
mp-wp_genesis 1133 $left_checked = $left == $revision->ID ? ' checked="checked"' : '';
mp-wp_genesis 1134 else
mp-wp_genesis 1135 $left_checked = $right_checked ? ' checked="checked"' : ''; // [sic] (the next one)
mp-wp_genesis 1136 $right_checked = $right == $revision->ID ? ' checked="checked"' : '';
mp-wp_genesis 1137
mp-wp_genesis 1138 $class = $class ? '' : " class='alternate'";
mp-wp_genesis 1139
mp-wp_genesis 1140 if ( $post->ID != $revision->ID && $can_edit_post )
mp-wp_genesis 1141 $actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'diff' => false, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';
mp-wp_genesis 1142 else
mp-wp_genesis 1143 $actions = '';
mp-wp_genesis 1144
mp-wp_genesis 1145 $rows .= "<tr$class>\n";
mp-wp_genesis 1146 $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked /><input type='radio' name='right' value='$revision->ID'$right_checked /></th>\n";
mp-wp_genesis 1147 $rows .= "\t<td>$date</td>\n";
mp-wp_genesis 1148 $rows .= "\t<td>$name</td>\n";
mp-wp_genesis 1149 $rows .= "\t<td class='action-links'>$actions</td>\n";
mp-wp_genesis 1150 $rows .= "</tr>\n";
mp-wp_genesis 1151 } else {
mp-wp_genesis 1152 $title = sprintf( $titlef, $date, $name );
mp-wp_genesis 1153 $rows .= "\t<li>$title</li>\n";
mp-wp_genesis 1154 }
mp-wp_genesis 1155 }
mp-wp_genesis 1156
mp-wp_genesis 1157 if ( 'form-table' == $format ) : ?>
mp-wp_genesis 1158
mp-wp_genesis 1159 <form action="revision.php" method="get">
mp-wp_genesis 1160
mp-wp_genesis 1161 <div class="tablenav">
mp-wp_genesis 1162 <div class="alignleft">
mp-wp_genesis 1163 <input type="submit" class="button-secondary" value="<?php _e( 'Compare Revisions' ); ?>" />
mp-wp_genesis 1164 <input type="hidden" name="action" value="diff" />
mp-wp_genesis 1165 </div>
mp-wp_genesis 1166 </div>
mp-wp_genesis 1167
mp-wp_genesis 1168 <br class="clear" />
mp-wp_genesis 1169
mp-wp_genesis 1170 <table class="widefat post-revisions" cellspacing="0">
mp-wp_genesis 1171 <col />
mp-wp_genesis 1172 <col style="width: 33%" />
mp-wp_genesis 1173 <col style="width: 33%" />
mp-wp_genesis 1174 <col style="width: 33%" />
mp-wp_genesis 1175 <thead>
mp-wp_genesis 1176 <tr>
mp-wp_genesis 1177 <th scope="col"></th>
mp-wp_genesis 1178 <th scope="col"><?php _e( 'Date Created' ); ?></th>
mp-wp_genesis 1179 <th scope="col"><?php _e( 'Author' ); ?></th>
mp-wp_genesis 1180 <th scope="col" class="action-links"><?php _e( 'Actions' ); ?></th>
mp-wp_genesis 1181 </tr>
mp-wp_genesis 1182 </thead>
mp-wp_genesis 1183 <tbody>
mp-wp_genesis 1184
mp-wp_genesis 1185 <?php echo $rows; ?>
mp-wp_genesis 1186
mp-wp_genesis 1187 </tbody>
mp-wp_genesis 1188 </table>
mp-wp_genesis 1189
mp-wp_genesis 1190 </form>
mp-wp_genesis 1191
mp-wp_genesis 1192 <?php
mp-wp_genesis 1193 else :
mp-wp_genesis 1194 echo "<ul class='post-revisions'>\n";
mp-wp_genesis 1195 echo $rows;
mp-wp_genesis 1196 echo "</ul>";
mp-wp_genesis 1197 endif;
mp-wp_genesis 1198
mp-wp_genesis 1199 }