Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda