Last active
November 9, 2024 00:51
-
-
Save zoerooney/11207411 to your computer and use it in GitHub Desktop.
Code snippets for my WordPress + Filtrify portfolio tutorial: http://zoerooney.com/blog/tutorials/wordpress-filtrify-a-tag-filtered-portfolio-or-gallery/
This file contains hidden or 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
data-platform="<?php echo implode(', ', get_field('platform')); ?>" | |
data-project-type="<?php echo implode(', ', get_field('project_type')); ?>" | |
data-designer="<?php the_field('designers'); ?>" |
This file contains hidden or 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
<div class="portfolio" data-platform="WordPress, Shopify" data-project-type="Ecommerce" data-designer="Ghostly Ferns"> | |
<div class="portfolio last" data-platform="WordPress" data-project-type="Info Site" data-designer="small shop"> |
This file contains hidden or 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
<div class="portfolio<?php if ( ($i%3) == 0 ) { echo ' last'; } elseif ( ($i%2) == 0 ) { echo ' two-last'; } elseif ( ($i%4) == 0 ) { echo ' very-large'; } ?>" data-platform="<?php echo implode(', ', get_field('platform')); ?>" data-project-type="<?php echo implode(', ', get_field('project_type')); ?>" data-designer="<?php the_field('designers'); ?>"> |
This file contains hidden or 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
function lets_add_some_scripts() { | |
wp_enqueue_script( | |
'filtrify', | |
get_template_directory_uri() . '/js/filtrify.min.js', | |
array('jquery') | |
); | |
wp_enqueue_style( | |
'filtrify-css', | |
get_template_directory_uri() . '/js/filtrify.css' | |
); | |
} | |
add_action('wp_enqueue_scripts', 'lets_add_some_scripts'); |
This file contains hidden or 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 | |
/** | |
* Template Name: Portfolio | |
*/ | |
get_header(); ?> | |
<div id="primary" class="full-width"> | |
<div id="content" role="main"> | |
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> | |
<div id="placeholder"></div> | |
<div id="legend"></div> | |
<div id="container"> | |
<?php | |
$args = array( | |
'post_type' => 'customportfolio', | |
'nopaging' => true | |
); | |
$the_query = new WP_Query( $args ); | |
while ( $the_query->have_posts() ) : $i++; | |
$the_query->the_post(); ?> | |
<div class="portfolio<?php if ( ($i%3) == 0 ) { echo ' last'; } elseif ( ($i%2) == 0 ) { echo ' two-last'; } elseif ( ($i%4) == 0 ) { echo ' very-large'; } ?>" data-platform="<?php echo implode(', ', get_field('platform')); ?>" data-project-type="<?php echo implode(', ', get_field('project_type')); ?>" data-designer="<?php the_field('designers'); ?>"> | |
<div class="project-image"> | |
<?php the_post_thumbnail('portfolio'); ?> | |
</div> | |
<div class="project-info"> | |
<?php the_title(); ?> | |
</div> | |
</div> | |
<?php endwhile; wp_reset_postdata(); ?> | |
</div> | |
</article> | |
</div><!-- #content --> | |
</div><!-- #primary --> | |
<script> | |
jQuery(document).ready(function($){ | |
$.filtrify("container", "placeholder", { | |
close : true, | |
callback : function( query, match, mismatch ) { | |
if ( !mismatch.length ) { | |
$("#legend").html("Viewing all projects"); | |
} else { | |
var category, tags, i, tag, legend = "<h4>Currently filtered by:</h4>"; | |
for ( category in query ) { | |
tags = query[category]; | |
if ( tags.length ) { | |
legend += ""; | |
for ( i = 0; i < tags.length; i++ ) { | |
tag = tags[i]; | |
legend += "" + tag + "&nbsp;&nbsp;&nbsp;&nbsp;"; | |
}; | |
legend += ""; | |
}; | |
}; | |
$("#legend").html( legend ); | |
}; | |
} | |
}); | |
}); | |
</script> | |
<?php get_footer(); ?> |
This file contains hidden or 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
<script> | |
jQuery(document).ready(function($){ | |
$.filtrify("container", "placeholder", { | |
close : true, | |
callback : function( query, match, mismatch ) { | |
if ( !mismatch.length ) { | |
$("#legend").html("Viewing all projects"); | |
} else { | |
var category, tags, i, tag, legend = "<h4>Currently filtered by:</h4>"; | |
for ( category in query ) { | |
tags = query[category]; | |
if ( tags.length ) { | |
legend += ""; | |
for ( i = 0; i < tags.length; i++ ) { | |
tag = tags[i]; | |
legend += "" + tag + "&nbsp;&nbsp;&nbsp;&nbsp;"; | |
}; | |
legend += ""; | |
}; | |
}; | |
$("#legend").html( legend ); | |
}; | |
} | |
}); | |
}); | |
</script> |
This file contains hidden or 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
<div id="placeholder"></div> | |
<div id="legend"></div> | |
<div id="container"> | |
..... | |
</div> |
This file contains hidden or 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
<div id="placeholder"></div> | |
<div id="legend"></div> | |
<div id="container"> | |
<?php | |
$args = array( | |
'post_type' => 'customportfolio', | |
'nopaging' => true | |
); | |
$the_query = new WP_Query( $args ); | |
while ( $the_query->have_posts() ) : $i++; | |
$the_query->the_post(); ?> | |
<div class="portfolio<?php if ( ($i%3) == 0 ) { echo ' last'; } elseif ( ($i%2) == 0 ) { echo ' two-last'; } elseif ( ($i%4) == 0 ) { echo ' very-large'; } ?>"> | |
<div class="project-image"> | |
<?php the_post_thumbnail('portfolio'); ?> | |
</div> | |
<div class="project-info"> | |
<?php the_title(); ?> | |
</div> | |
</div> | |
<?php endwhile; wp_reset_postdata(); ?> | |
</div> |
This file contains hidden or 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
<div class="portfolio<?php if ( ($i%3) == 0 ) { echo ' last'; } elseif ( ($i%2) == 0 ) { echo ' two-last'; } elseif ( ($i%4) == 0 ) { echo ' very-large'; } ?>"> | |
<div class="project-image"> | |
<?php the_post_thumbnail('thumbnail'); ?> | |
</div> | |
<div class="project-info"> | |
<?php the_title(); ?> | |
</div> | |
</div> |
This file contains hidden or 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 | |
$args = array( | |
'post_type' => 'customportfolio', | |
'nopaging' => true | |
); | |
$the_query = new WP_Query( $args ); | |
while ( $the_query->have_posts() ) : $i++; | |
$the_query->the_post(); ?> | |
<!-- stuff within the loop here --> | |
<?php endwhile; wp_reset_postdata(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment