Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. <?php
  2. /**
  3. * Template Name: Gallery Page
  4. *
  5. */
  6.  
  7. if ( have_posts() ) {
  8. while ( have_posts() ) {
  9. the_post();
  10. function pw_show_gallery_image_urls( $content ) {
  11.  
  12. global $post;
  13.  
  14. // Only do this on singular items
  15. if( ! is_singular() )
  16. return $content;
  17.  
  18. // Make sure the post has a gallery in it
  19. if( ! has_shortcode( $post->post_content, 'gallery' ) )
  20. return $content;
  21.  
  22. // Retrieve the first gallery in the post
  23. $gallery = get_post_gallery_images( $post );
  24.  
  25. $image_list = '<ul>';
  26.  
  27. // Loop through each image in each gallery
  28. foreach( $gallery as $image_url ) {
  29.  
  30. $image_list .= '<li>' . '<img src="' . $image_url . '">' . '</li>';
  31.  
  32. }
  33.  
  34. $image_list .= '</ul>';
  35.  
  36. // Append our image list to the content of our post
  37. $content .= $image_list;
  38.  
  39. return $content;
  40.  
  41. }
  42. add_filter( 'the_content', 'pw_show_gallery_image_urls' );
  43. } // end while
  44. } // end if
  45. ?>
  46.  
  47. function pw_show_gallery_image_urls( $content ) {
  48.  
  49. global $post;
  50.  
  51. // Only do this on singular items
  52. if( ! is_singular() )
  53. return $content;
  54.  
  55. // Make sure the post has a gallery in it
  56. if( ! has_shortcode( $post->post_content, 'gallery' ) )
  57. return $content;
  58.  
  59. // Retrieve the first gallery in the post
  60. $gallery = get_post_gallery_images( $post );
  61.  
  62. $image_list = '<ul>';
  63.  
  64. // Loop through each image in each gallery
  65. foreach( $gallery as $image_url ) {
  66. $image_list .= '<li>' . '<img src="' . $image_url . '">' . '</li>';
  67. }
  68.  
  69. $image_list .= '</ul>';
  70.  
  71. // Append our image list to the content of our post
  72. $content .= $image_list;
  73.  
  74. return $content;
  75. }
  76. add_filter( 'the_content', 'pw_show_gallery_image_urls' );
  77.  
  78. if ( have_posts() ) {
  79. while ( have_posts() ) {
  80. the_post();
  81.  
  82. } // end while
  83. } // end if
  84.  
  85. if ( have_posts() ) {
  86. while ( have_posts() ) {
  87. the_post();
  88. the_content(); // minimum
  89. } // end while
  90. } // end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement