Skip to content

Instantly share code, notes, and snippets.

@jeremeylduvall
Last active December 14, 2017 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremeylduvall/49b1c734354d0a9f88d5e71a3d1a4aaa to your computer and use it in GitHub Desktop.
Save jeremeylduvall/49b1c734354d0a9f88d5e71a3d1a4aaa to your computer and use it in GitHub Desktop.
Display photos function
const photos = props.data.allWordpressPost.edges;
const displayPhotos = () => {
const photoArray = [];
let photoRow = [];
let count = 0;
photos.map( photo => {
if ( photo.node.featured_media ) {
photoArray.push( photo );
}
} );
return (
photoArray.map( photo => {
if ( photoRow.length === 3 ) {
photoRow = [];
}
photoRow.push( photo );
count++;
if ( photoRow.length === 3 ) {
return returnRow( photoRow, count );
} else if ( photoArray.length - count === 0 ) {
return returnRow( photoRow, count );
}
} )
)
}
const returnRow = ( photos, count ) => {
return (
<PhotoRow photos={ photos } key={ count } />
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment