Support

Account

Forum Replies Created

  • This seems to work, thoughts?

    <?php if(get_field('media')): ?>
                    <div class="info news">
                      <ul>
                        <?php $rows = get_field('media'); ?>
                        <?php
                            $articleArray = array();
                            foreach( $rows as $key => $row ) {
                                $rows[$key] = $row['id'];
                                $articleArray[$key]['date'] = $row['date'];
                                $articleArray[$key]['file'] = $row['file'];
                                $articleArray[$key]['title'] = $row['title'];
                            }
                        ?>
                        <?php $rowCount = count($rows); ?>
                        <?php for ($i = ($rowCount - 1); $i >= 0; $i--) { ?>
                        <li>
                            <em><?php echo $articleArray[$i]['date']; ?></em>
                            <strong><a href="<?php echo $articleArray[$i]['file']; ?>" rel="bookmark"><?php echo $articleArray[$i]['title']; ?></a></strong>
                        </li>
                        <?php } ?>
                    </ul>
            </div>
            <?php endif; ?>
  • Yes, correct. OK, well, I am using this instance in two places, but one place doesn’t have a huge list so I think for that one I will just show all and not paginate to simplify this problem a bit more. If I change the above to

    <?php  if(get_field('media')) { ?>
    <div class="info news">
      <ul>
         <?php  $counter = 0; ?>
        <?php  while ( have_rows('media') ) : the_row(); ?>
        <?php
          $data[$counter]['date'] = get_sub_field('date');
          $data[$counter]['file'] = get_sub_field('file');
          $data[$counter]['title'] = get_sub_field('title');
          $counter++;
        ?>
        <?php  endwhile; ?>
    
        <?php  for($i = 0; $i < count($data); $i++) { ?>
          <li>
            <em><?php  echo $data[$i]['date'] ?></em>
            <strong><a href="<?php  echo $data[$i]['file'] ?>" rel="bookmark"><?php  echo $data[$i]['title'] ?></a></strong>
          </li>
        <?php  } ?>
      </ul>
    
    </div>
    

    That works fine, however I would like to reverse the sort so the most current date is at the top of the list and not the bottom. Do you know how I might change this to do that? Thanks for your help.

  • Yea, me neither. So, what happens is if you go to /news/newsletter/2012 it just resolves back to /news/newsletter and only shows the current year. Not quite sure how to troubleshoot this, all I know is it seems that after WP 5.5 people started complaining online about this pagination issue, yet I am coming at this issue a few years late so am not finding a whole lot to go on here.

  • For each year:

    Array
    (
    [0] => 2010
    [1] => 2011
    [2] => 2012
    [3] => 2015
    [4] => 2016
    [5] => 2017
    [6] => 2018
    [7] => 2019
    [8] => 2020
    [9] => 2021
    )

  • The last part (which appears to have been truncated on previous post. It is too late to edit it now)

    <?php for ($i = 0; $i < count($uniqueYears); $i++) { ?>
                    <a href="/news/newsletter/<?php  echo str_replace(' ', '', $uniqueYears[$i]); ?>/"><?php echo $uniqueYears[$i]; ?></a>
                  <?php  } ?>

    Is pagination via year (2021 2020 2019, etc.) that link to the respective year page. Just trying to paginate by year.

    Sorry for the redundant post and edit, I noticed another truncated line in previous post as well, just going to re paste the full block below.

    <?php  if(get_field('newsletter')) { ?>
    <div>
      <h3>Newsletter</h3>
      <ul>
        <?php $urlSplits = explode('/', $_SERVER['REQUEST_URI']); ?>
        <?php $counter = 0; ?>
        <?php
          while ( have_rows('external-links') ) : the_row();
            $tempDate = explode(',', get_sub_field('date'));
            $mediaYears[] = $tempDate['1'];
            $data[$counter]['year'] = $tempDate['1'];
            $data[$counter]['date'] = get_sub_field('date');
            $data[$counter]['link'] = get_sub_field('link');
            $data[$counter]['title'] = get_sub_field('title');
            $counter++;
          endwhile;
        ?>
        <?php
          $keys = 0;
          $mediaYears = array_unique($mediaYears);
          foreach ($mediaYears as $value) {
            if ($value != '') {
              $uniqueYears[$keys] = $value;
              $keys++;
            }
          }
          rsort($uniqueYears);
          $data = array_reverse($data, true);
          if ($urlSplits[3] != '') {
            $currentYear = str_replace(' ', '', $urlSplits[3]);
          } else {
            $currentYear = str_replace(' ', '', $uniqueYears[0]);
          }
        ?>
        <?php  for($i = count($data); $i >= 0; $i--) { ?>
          <?php  if ($currentYear == $data[$i]['year']) { ?>
          <li>
            <em><?php  echo $data[$i]['date'] ?></em>
            <strong><a href="<?php echo $data[$i]['link'] ?>" rel="bookmark"><?php  echo $data[$i]['title'] ?></a></strong>
          </li>
          <?php  } ?>
        <?php  } ?>
      </ul>
    <!-- PAGINATION LINKS -->
      <?php for ($i = 0; $i < count($uniqueYears); $i++) { ?>
        <a href="/news/newsletter/<?php  echo str_replace(' ', '', $uniqueYears[$i]); ?>/"><?php echo $uniqueYears[$i]; ?></a>
      <?php  } ?>
    </div>
    <?php  } ?>
    <?php  } ?>
  • Ok, I changed it to this, didn’t break anything, but the pagination is still an issue, what am I missing here? This was working on WP 5.4 but 5.5 and beyond it is not.

    <?php  if(get_field('newsletter')) { ?>
    <div>
      <h3>Newsletter</h3>
      <ul>
        <?php $urlSplits = explode('/', $_SERVER['REQUEST_URI']); ?>
        <?php $counter = 0; ?>
        <?php
          while ( have_rows('external-links') ) : the_row();
            $tempDate = explode(',', get_sub_field('date'));
            $mediaYears[] = $tempDate['1'];
            $data[$counter]['year'] = $tempDate['1'];
            $data[$counter]['date'] = get_sub_field('date');
            $data[$counter]['link'] = get_sub_field('link');
            $data[$counter]['title'] = get_sub_field('title');
            $counter++;
          endwhile;
        ?>
        <?php
          $keys = 0;
          $mediaYears = array_unique($mediaYears);
          foreach ($mediaYears as $value) {
            if ($value != '') {
              $uniqueYears[$keys] = $value;
              $keys++;
            }
          }
          rsort($uniqueYears);
          $data = array_reverse($data, true);
          if ($urlSplits[3] != '') {
            $currentYear = str_replace(' ', '', $urlSplits[3]);
          } else {
            $currentYear = str_replace(' ', '', $uniqueYears[0]);
          }
        ?>
        <?php for($i = count($data); $i >= 0; $i--) { ?>
          <?php if ($currentYear == $data[$i]['year']) {?>
          <li>
            <em><?php echo $data[$i]['date'] ?></em>
            <strong><a>" rel="bookmark"><?php  echo $data[$i]['title'] ?></a></strong>
          </li>
          <?php } ?>
        <?php } ?>
      </ul>
      <?php for ($i = 0; $i < count($uniqueYears); $i++) { ?>
        <a>"><?php  echo $uniqueYears[$i]; ?></a>
      <?php } ?>
    </div>
    <?php  } ?>
    <?php  } ?>
  • Ok, I simplified this and got the random part to work but now it is pulling two identical random items vs. 2 different random items. How can I fix this?

    function getLatestBooks() {
        if(get_field('books', 34)) {
            $rows = get_field('books', 34);
            $row_count = count($rows);
            $i = rand(0, $row_count - 1);
    
            echo $rows[$i]['sub_field_name'];
    
            $paperCounter = 0;
    
            while(has_sub_field('books', 34) && $paperCounter < 2) {
                $latestBooks .= '<p>'.$rows[$i]['cover'].'</p>';
                $latestBooks .= '<p>'.$rows[$i]['title'].'</p>';
    
                $paperCounter++;
            }
    
            $latestBooks .= '</ul>';
        }
        return $latestBooks;
    }
  • Yea, as it turned out, this concept is a lot more involved than you might think at first glance. I ended up moving on from this for the time being and will circle back another time.

  • Took out $paperCounter for now to try and get 1 random one pulled and have it functioning with the exception of the get_image_with_alt line. Any clue how I could pull 2 randoms, and adjust the line get_image_with_alt to be random? Feel like I am getting close but need a bit of help.

    function getLatestPhotos() {
        if(get_field('photos', 34)) {
            $rows = get_field('photos', 34);
            $row_count = count($rows);
            $i = rand(0, $row_count - 1);
    
            echo $rows[$i]['sub_field_name'];
    
            $latestPhotos .= '<a href="/photos/">';
            $latestPhotos .= get_image_with_alt('cover', get_the_ID(), '');
            $latestPhotos .= '<p>'.$rows[$i]['title'].'</p>';
            $latestPhotos .= '<span>'.$rows[$i]['name'].'</span>';
            $latestPhotos .= '</a>';
    
        }
        return $latestPhotos;
    }
  • I think I figured it out. I was using ‘Image URL’ and needed to switch to ‘Image Array’ and change the code to the following. If someone could confirm I’m doing this correctly that would be great.

    <?php while(the_repeater_field('banner')): ?>
    <?php $image = get_sub_field('image'); ?>
    <div>
        <h1><?php the_sub_field('heading'); ?></h1>
        <p><?php the_sub_field('description'); ?></p>
        <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>">
    </div>
    <?php endwhile; ?>
  • Perfect. Thanks so much!

Viewing 11 posts - 1 through 11 (of 11 total)