D
D
drawnofmymind2020-05-20 08:56:03
WordPress
drawnofmymind, 2020-05-20 08:56:03

How to limit the output of images for a single post?

Hello, here is the code:

$images1 =& get_children( array (
    'post_parent' => $post->ID,
    'post_type' => 'attachment',
    'order' => 'ASC',
    'post_mime_type' => 'image'
  ));
  if ( empty($images1) ) {
    // no attachments here
  } else { ?>
  <div class="portfolio__wrap">
    <div class="portfolio__photo">
      <div class="row">
        <div class="carousel photo__carousel col col-xs-12 col-sm-10 col-sm-of-1 col-md-12 col-md-of-0">
          <?php foreach ( $images1 as $attachment_id => $attachment ) { ?>
          <div class="item">
            <a href="<?php echo wp_get_attachment_image_url($attachment_id, "full");?>"  
               class="fancybox-photos link__scale video__link" data-fancybox-group="photos" data-fancybox-title="<?php the_title(); ?>">
              <span class="bg__icon arrow"><span class="icon__plus"></span></span>
              <?php echo wp_get_attachment_image( $attachment_id, "medium"); ?></a>
          </div>
          <?php } ?>
        </div>
      </div>
    </div>
  </div>

The essence of the code is such that when media files are loaded, you can link to a specific page and display them.
I uploaded 50 photos, but I need 13 of them for the first SLIDER, and 37 for the second.
Question: how can I separate the pictures attached to one page, but to a different slider (using this code)?
PS I'll forgive the petition, for raising the question, perhaps I'm not explaining correctly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2020-05-20
@drawnofmymind

$images_first = array_splice( $images, 0, 13); 

// массив $images_first  будет содержать первые 13 элементов масcива $images
// в массиве $images теперь будут содержаться только элементы которые изначально были после 13-го

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question