posts - show image gallery in archives or category page

admin2025-01-07  3

i want to show image gallery in archives.php or category.php. The featured image and text content is showing but not image gallery. Below is the code inside category.php. I have tested to show one post from category 'blog'.

$args = array(
        'post_type' => 'post',
        'post_status' => 'any',
        'cat'=>3,
             'meta_query'=>
       array('relation'=>'AND',
         array(
        'key'=>'intro_post','value'=>'intro','type'=>'CHAR','compare'=>'LIKE'
        )
       )
   );
   $arr_posts = new WP_Query( $args );?>
    <?php  if (  $arr_posts->have_posts() ) : ?>
             <?php  while ( $arr_posts->have_posts() ) : $arr_posts->the_post(); ?>
                  <div class="entry-content">
                        <?php if (has_post_thumbnail()): ?>
                        <figure>
                        <?php the_post_thumbnail('full');?>
                        </figure>
                       <?php endif; ?>
        <?php the_content(); ?>

        </div><!-- .entry-content -->
                 <?php  endwhile; ?>
          <?php else : ?>
               <?php get_template_part( 'template-parts/content', 'none' ); ?>
          <?php endif; 
           wp_reset_query();

i want to show image gallery in archives.php or category.php. The featured image and text content is showing but not image gallery. Below is the code inside category.php. I have tested to show one post from category 'blog'.

$args = array(
        'post_type' => 'post',
        'post_status' => 'any',
        'cat'=>3,
             'meta_query'=>
       array('relation'=>'AND',
         array(
        'key'=>'intro_post','value'=>'intro','type'=>'CHAR','compare'=>'LIKE'
        )
       )
   );
   $arr_posts = new WP_Query( $args );?>
    <?php  if (  $arr_posts->have_posts() ) : ?>
             <?php  while ( $arr_posts->have_posts() ) : $arr_posts->the_post(); ?>
                  <div class="entry-content">
                        <?php if (has_post_thumbnail()): ?>
                        <figure>
                        <?php the_post_thumbnail('full');?>
                        </figure>
                       <?php endif; ?>
        <?php the_content(); ?>

        </div><!-- .entry-content -->
                 <?php  endwhile; ?>
          <?php else : ?>
               <?php get_template_part( 'template-parts/content', 'none' ); ?>
          <?php endif; 
           wp_reset_query();
Share Improve this question asked May 8, 2018 at 16:50 PhyoPhyo 12 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

If posts have post_format is gallery, you can get all gallaries by used: get_post_gallery_images(get_the_ID()); See more: https://pippinsplugins.com/retrieving-image-urls-of-galleries/

I fixed it. I set query 'post_type' to 'attachment' and 'post' in pre_get_posts hook. So now image galleries are showing in archive or category. 

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736252895a82.html

最新回复(0)