Skip to content

Instantly share code, notes, and snippets.

@oalansari82
Last active October 25, 2016 17:20
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 oalansari82/0390fd64e340606beddaeb9407ae8a88 to your computer and use it in GitHub Desktop.
Save oalansari82/0390fd64e340606beddaeb9407ae8a88 to your computer and use it in GitHub Desktop.
Add sources field in Genesis using ACF Pro
<?php
// Only include the code below this line
add_action( 'genesis_entry_footer', 'io_sources_custom_fields' );
/**
* Add sources to posts, if posts have sources assigned
*/
function io_sources_custom_fields() {
if ( is_singular( $post_types = 'post' ) ) {
// check if the repeater field has rows of data
if( have_rows('sources') ):
echo '<div class="sources">Sources:<ul>';
// loop through the rows of data
while ( have_rows('sources') ) : the_row();
$sourceLink = get_sub_field('source_link');
$sourceTitle = get_sub_field('source_title');
printf('<li><a href="%s" target="_blank">%s</a></li>', $sourceLink, $sourceTitle);
endwhile;
echo '</ul></div>';
else :
// no rows found
endif;
}
}
/* # Sources fields
---------------------------------------------------------------------------------------------------- */
.sources {
display: block;
font-size: 16px;
font-weight: 600;
}
.sources ul {
display: -webkit-box; /* OLD - iOS 6-, Safari 3.1-6 */
display: -moz-box; /* OLD - Firefox 19- (doesn't work very well) */
display: -ms-flexbox; /* TWEENER - IE 10 */
display: -webkit-flex; /* NEW - Chrome */
display: flex; /* NEW, Spec - Opera 12.1, Firefox 20+ */
-ms-flex-flow: row wrap;
flex-flow: row wrap;
-webkit-flex-flow: row wrap;
-webkit-box-pack: start;
-ms-flex-pack: start;
justify-content: flex-start;
-webkit-justify-content: flex-start;
margin-left: auto;
}
.sources ul li {
list-style: none;
-ms-flex-preferred-size: 33.333333%;
flex-basis: 33.333333%;
-webkit-flex-basis: 33.333333%;
padding: 5px;
font-weight: 300;
}
@media only screen and (max-width: 860px) {
.sources ul li {
-ms-flex-preferred-size: 50%;
flex-basis: 50%;
-webkit-flex-basis: 50%;
}
}
@media only screen and (max-width: 500px) {
.sources ul li {
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
-webkit-flex-basis: 100%;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment