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

/attachment.php

https://github.com/scottsweb/null
PHP | 172 lines | 105 code | 52 blank | 15 comment | 23 complexity | 20bbad4075b95bf4607456472a369830 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. This is the default view for an attached library item.
  4. This template will be irrelevant if you never use the "Link to Page" option when inserting a library item.
  5. Other views include: image.php, video.php, audio.php, application.php - all are optional.
  6. By default we will redirect this page to the file.
  7. **/
  8. /** by default simply redirect to the file - the library item view is oftern overkill **/
  9. the_post();
  10. wp_redirect(wp_get_attachment_url($post->ID));
  11. exit;
  12. ?>
  13. <?php get_header() ?>
  14. <?php tha_content_before(); ?>
  15. <div id="content" role="main">
  16. <?php tha_content_top(); ?>
  17. <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  18. <?php if (!empty($post->post_parent)) : // page title ?>
  19. <h2 class="page-title"><a href="<?php echo get_permalink( $post->post_parent ); ?>" title="<?php esc_attr(printf(__('Return to %s', 'null'), get_the_title($post->post_parent))); ?>" rev="attachment" rel="gallery">&laquo; <?php echo get_the_title($post->post_parent); ?></a></h2>
  20. <?php endif; ?>
  21. <?php tha_entry_before(); ?>
  22. <article <?php post_class() ?> role="article">
  23. <?php tha_entry_top(); ?>
  24. <header>
  25. <h3 class="entry-title"><?php the_title(); ?></h3>
  26. </header>
  27. <div class="entry-content">
  28. <div class="entry-attachment">
  29. <?php if ( wp_attachment_is_image() ) :
  30. $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' ) ) );
  31. foreach ( $attachments as $k => $attachment ) {
  32. if ( $attachment->ID == $post->ID )
  33. break;
  34. }
  35. $k++;
  36. // If there is more than 1 image attachment in a gallery
  37. if ( count( $attachments ) > 1 ) {
  38. if ( isset( $attachments[ $k ] ) )
  39. // get the URL of the next image attachment
  40. $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
  41. else
  42. // or get the URL of the first image attachment
  43. $next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
  44. } else {
  45. // or, if there's only 1 image attachment, get the URL of the image
  46. $next_attachment_url = wp_get_attachment_url();
  47. }
  48. ?>
  49. <p class="attachment">
  50. <a href="<?php echo $next_attachment_url; ?>" title="<?php the_title_attribute(); ?>" rel="attachment">
  51. <?php echo wp_get_attachment_image( $post->ID, 'large' ); ?>
  52. </a>
  53. </p>
  54. <?php if ($wp_query->max_num_pages > 1) : // only paginate when necessary ?>
  55. <nav class="attachment-pagination">
  56. <div class="previous"><?php previous_image_link(false, __('&laquo; Previous Image', 'null')) ?></div>
  57. <div class="next"><?php next_image_link(false, __('Next Image &raquo;', 'null')) ?></div>
  58. </nav>
  59. <?php endif; ?>
  60. <?php else : ?>
  61. <p class="attachment">
  62. <a href="<?php echo wp_get_attachment_url(); ?>" title="<?php the_title_attribute(); ?>" rel="attachment"><?php echo basename( get_permalink() ); ?></a>
  63. </p>
  64. <?php endif; ?>
  65. </div><!-- .entry-attachment -->
  66. <div class="entry-caption"><?php if (!empty($post->post_excerpt)) the_excerpt(); // caption from gallery settings ?></div>
  67. </div><!-- .entry-content -->
  68. <footer>
  69. <p class="entry-meta entry-description">
  70. <?php
  71. printf(__('This entry was posted by %1$s on %2$s and is filed under %3$s. ', 'null'),
  72. get_the_author(),
  73. '<time datetime="'.get_the_time('Y-m-d').'">'.null_get_time('l, F jS, Y @ g:ia').'</time>',
  74. get_the_category_list(', ')
  75. );
  76. printf(__('You can follow any responses to this entry through the %1$sRSS 2.0%2$s feed. ', 'null'),
  77. '<a href="'.get_post_comments_feed_link().'">',
  78. '</a>'
  79. );
  80. if ( comments_open() && pings_open() ) {
  81. // Both Comments and Pings are open
  82. printf(
  83. __('You can <a href="#respond">leave a response</a>, or <a href="%1$s" rel="trackback">trackback</a> from your own site.', 'null'),
  84. get_trackback_url()
  85. );
  86. } else if ( !comments_open() && pings_open() ) {
  87. // Only Pings are Open
  88. printf(
  89. __('Responses are currently closed, but you can leave a <a href="%1$s" rel="trackback">trackback</a> from your own site.', 'null'),
  90. get_trackback_url()
  91. );
  92. } else if ( comments_open() && !pings_open() ) {
  93. // Comments are open, Pings are not
  94. _e('You can skip to the end and leave a response. Pinging is currently not allowed.', 'null');
  95. } else if ( !comments_open() && !pings_open() ) {
  96. // Neither Comments, nor Pings are open
  97. _e('Both comments and pings are currently closed.', 'null');
  98. }
  99. ?>
  100. </p>
  101. </footer>
  102. <?php comments_template(); ?>
  103. <?php tha_entry_bottom(); ?>
  104. </article>
  105. <?php tha_entry_after(); ?>
  106. <?php endwhile; else: ?>
  107. <?php tha_entry_before(); ?>
  108. <article role="article">
  109. <?php tha_entry_top(); ?>
  110. <h3><?php _e('No Posts Found', 'null'); ?></h3>
  111. <p class="notice"><?php _e('Sorry, no attachments were found that matched your criteria.', 'null'); ?></p>
  112. <?php tha_entry_bottom(); ?>
  113. </article>
  114. <?php tha_entry_after(); ?>
  115. <?php endif; ?>
  116. <?php tha_content_bottom(); ?>
  117. </div><!-- #content -->
  118. <?php tha_content_after(); ?>
  119. <?php get_sidebar() ?>
  120. <?php get_footer() ?>