Last active
January 11, 2017 16:45
-
-
Save oalansari82/4fc0d21840bc7ee65d7de837e493fcb5 to your computer and use it in GitHub Desktop.
Create related posts section in Genesis Framework using ACF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'genesis_before_comments', 'io_related_posts' ); | |
function io_related_posts() { | |
$relatedPosts = get_field( 'related_posts' ); | |
if( $relatedPosts ): | |
echo '<div class="related-posts-container">'; | |
echo '<h3>Related Posts</h3>'; | |
echo '<ul class="related-posts">'; | |
foreach( $relatedPosts as $relatedPost ): // variable must NOT be called $post (IMPORTANT) | |
echo '<li>'; | |
echo '<a href="' . get_permalink( $relatedPost->ID ) . '">' . get_the_post_thumbnail( $relatedPost->ID ) .'<h5>' . get_the_title( $relatedPost->ID ) . '</h5></a>'; | |
echo wp_trim_words( get_the_content( $relatedPost->ID ), 20, null ); | |
echo '</li>'; | |
endforeach; | |
echo '</ul>'; | |
echo '</div>'; | |
endif; | |
} | |
genesis(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.related-posts-container { | |
background-color: #fff; | |
font-size: 18px; | |
font-size: 1.8rem; | |
margin-bottom: 40px; | |
padding: 60px; | |
} | |
.related-posts-container h3 { | |
margin-bottom: 5%; | |
} | |
.related-posts { | |
display: -webkit-box; | |
display: -ms-flexbox; | |
display: flex; | |
-ms-flex-flow: row wrap; | |
flex-flow: row wrap; | |
-webkit-box-pack: justify; | |
-ms-flex-pack: justify; | |
justify-content: space-between; | |
} | |
.related-posts li { | |
-ms-flex-preferred-size: 32%; | |
flex-basis: 32%; | |
} | |
@media only screen and (max-width: 450px) { | |
.related-posts li { | |
-ms-flex-preferred-size: 100%; | |
flex-basis: 100%; | |
margin-bottom: 10%; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment