Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
Previous article can't be same as next one

I currently have code that gets all articles from a CMS, with a number, image and text and based on a true or false, the order of image text gets decided. So a image can be above text or under text. But I want it so it's always: image under - image above - image under - image above, and not that it can be like image under - image under - image top, so it can't be allowed to have imaged under for two articles next to each other.

Does someone have an idea what I can do to accomplish this? My current code:

export const GridArticle = ({ item, idx }) => {
  const img = item.image;

  // If true, image at the top, if false, image at the bottom
  const dataOrder = [true, false];
  dataOrder.sort(() => Math.random() - 0.5);
  console.log(dataOrder[0]);

  return (
    <Wrapper>
      {dataOrder[0] ? (
        <Wrapper>
          <a href={`/articles/${item._meta?.uid}`}>
            <Number>{idx + 1}</Number>
            <ImageWrapper>
              {img && <img src={img.url} alt={img.alt} style={{ marginBottom: '2rem' }} />}
            </ImageWrapper>
            <div>
              <h2>{item.title[0].text}</h2>
              <RichText render={item.intro} />
              <span className="link">Lees verder</span>
            </div>
          </a>
        </Wrapper>
      ) : (
        <Wrapper>
          <a href={`/articles/${item._meta?.uid}`}>
            <Number>{idx + 1}</Number>
            <div>
              <h2>{item.title[0].text}</h2>
              <RichText render={item.intro} />
              <span className="link">Lees verder</span>
            </div>
            <ImageWrapper>
              {img && <img src={img.url} alt={img.alt} style={{ marginTop: '2rem' }} />}
            </ImageWrapper>
          </a>
        </Wrapper>
      )}
    </Wrapper>
  );
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

if I understand correctly, you want your pictures to be through one bottom top of them top you can look at the index and if the element is even make a picture at the bottom odd at the top number % 2 === 0 ? "true" : "false"

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!