PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/wp-content/themes/phc/loop-attachment.php

https://bitbucket.org/dkrzos/phc
PHP | 105 lines | 80 code | 14 blank | 11 comment | 12 complexity | b117a96afb54a40801d45bede29c2849 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * The loop that displays an attachment.
  4. *
  5. * @package WordPress
  6. * @subpackage Starkers
  7. * @since Starkers HTML5 3.2
  8. */
  9. ?>
  10. <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
  11. <?php if ( ! empty( $post->post_parent ) ) : ?>
  12. <p><a href="<?php echo get_permalink( $post->post_parent ); ?>" title="<?php esc_attr( printf( __( 'Return to %s', 'starkers' ), get_the_title( $post->post_parent ) ) ); ?>" rel="gallery"><?php /* translators: %s - title of parent post */ printf( __( '&larr; %s', 'starkers' ), get_the_title( $post->post_parent ) ); ?></a></p>
  13. <?php endif; ?>
  14. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  15. <header>
  16. <h2><?php the_title(); ?></h2>
  17. <?php
  18. printf( __( 'By %2$s', 'starkers' ),
  19. 'meta-prep meta-prep-author',
  20. sprintf( '<a href="%1$s" title="%2$s">%3$s</a>',
  21. get_author_posts_url( get_the_author_meta( 'ID' ) ),
  22. sprintf( esc_attr__( 'View all posts by %s', 'starkers' ), get_the_author() ),
  23. get_the_author()
  24. )
  25. );
  26. ?>
  27. |
  28. <?php
  29. printf( __( 'Published %2$s', 'starkers' ),
  30. 'meta-prep meta-prep-entry-date',
  31. sprintf( '<abbr title="%1$s">%2$s</abbr>',
  32. esc_attr( get_the_time() ),
  33. get_the_date()
  34. )
  35. );
  36. if ( wp_attachment_is_image() ) {
  37. echo ' | ';
  38. $metadata = wp_get_attachment_metadata();
  39. printf( __( 'Full size is %s pixels', 'starkers' ),
  40. sprintf( '<a href="%1$s" title="%2$s">%3$s &times; %4$s</a>',
  41. wp_get_attachment_url(),
  42. esc_attr( __( 'Link to full-size image', 'starkers' ) ),
  43. $metadata['width'],
  44. $metadata['height']
  45. )
  46. );
  47. }
  48. ?>
  49. <?php edit_post_link( __( 'Edit', 'starkers' ), '', '' ); ?>
  50. </header>
  51. <?php if ( wp_attachment_is_image() ) :
  52. $attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) );
  53. foreach ( $attachments as $k => $attachment ) {
  54. if ( $attachment->ID == $post->ID )
  55. break;
  56. }
  57. $k++;
  58. // If there is more than 1 image attachment in a gallery
  59. if ( count( $attachments ) > 1 ) {
  60. if ( isset( $attachments[ $k ] ) )
  61. // get the URL of the next image attachment
  62. $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
  63. else
  64. // or get the URL of the first image attachment
  65. $next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
  66. } else {
  67. // or, if there's only 1 image attachment, get the URL of the image
  68. $next_attachment_url = wp_get_attachment_url();
  69. }
  70. ?>
  71. <p><a href="<?php echo $next_attachment_url; ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php
  72. $attachment_width = apply_filters( 'starkers_attachment_width', 900 );
  73. $attachment_height = apply_filters( 'starkers_attachment_height', 900 );
  74. echo wp_get_attachment_image( $post->ID, array( $attachment_width, $attachment_height ) ); ?></a></p>
  75. <nav>
  76. <?php previous_image_link( false ); ?>
  77. <?php next_image_link( false ); ?>
  78. </nav>
  79. <?php else : ?>
  80. <a href="<?php echo wp_get_attachment_url(); ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php echo basename( get_permalink() ); ?></a>
  81. <?php endif; ?>
  82. <?php if ( !empty( $post->post_excerpt ) ) the_excerpt(); ?>
  83. <?php the_content( __( 'Continue reading &rarr;', 'starkers' ) ); ?>
  84. <?php wp_link_pages( array( 'before' => '<nav>' . __( 'Pages:', 'starkers' ), 'after' => '</nav>' ) ); ?>
  85. <footer>
  86. <?php starkers_posted_in(); ?>
  87. <?php edit_post_link( __( 'Edit', 'starkers' ), ' ', '' ); ?>
  88. </footer>
  89. </article>
  90. <?php comments_template(); ?>
  91. <?php endwhile; // end of the loop. ?>