Issue on Getting Images URL of the WordPress Post Gallery -
i trying url of attached galley post on custom page layout called gallery page. tried use code codex @ this page (get post gallery images). not getting thing on page!
can please let me know doing wrong?
<?php /** * template name: gallery page * */ if ( have_posts() ) { while ( have_posts() ) { the_post(); function pw_show_gallery_image_urls( $content ) { global $post; // on singular items if( ! is_singular() ) return $content; // make sure post has gallery in if( ! has_shortcode( $post->post_content, 'gallery' ) ) return $content; // retrieve first gallery in post $gallery = get_post_gallery_images( $post ); $image_list = '<ul>'; // loop through each image in each gallery foreach( $gallery $image_url ) { $image_list .= '<li>' . '<img src="' . $image_url . '">' . '</li>'; } $image_list .= '</ul>'; // append our image list content of our post $content .= $image_list; return $content; } add_filter( 'the_content', 'pw_show_gallery_image_urls' ); } // end while } // end if ?>
you need put function pw_show_gallery_image_urls() outside posts loop. , better place in functions.php file of theme.
try way :
<?php /** * template name: gallery page * */ if ( have_posts() ) { while ( have_posts() ) { the_post(); the_content(); } // end while } // end if function pw_show_gallery_image_urls( $content ) { global $post; // on singular items if( ! is_singular() ) return $content; // make sure post has gallery in if( ! has_shortcode( $post->post_content, 'gallery' ) ) return $content; // retrieve first gallery in post $gallery = get_post_gallery_images( $post ); $image_list = '<ul>'; // loop through each image in each gallery foreach( $gallery $image_url ) { $image_list .= '<li>' . '<img src="' . $image_url . '">' . '</li>'; } $image_list .= '</ul>'; // append our image list content of our post $content .= $image_list; return $content; } add_filter( 'the_content', 'pw_show_gallery_image_urls' ); ?> not tested, hope work now.
Comments
Post a Comment