Last active
September 2, 2020 00:44
-
-
Save aschleg/91f5371424dfca9c577f to your computer and use it in GitHub Desktop.
When creating a custom Wordpress theme with Bootstrap, it took me forever for it to play nicely with the Isotope plugin for image filtering. Wanted to share in hopes it helps others.
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
<!-- | |
The function code enables a custom Portfolio type in the Wordpress admin section. Projects added here and their categories | |
will appear where the portfolio code is placed. You will need to register the Isotope plugin in order for it to function properly. | |
Isotope website: http://isotope.metafizzy.co/ | |
--> | |
<?php | |
wp_register_script( 'plugins', get_template_directory_uri() . '/assets/js/build/plugins.min.js', array( 'jquery' ), '', all ); | |
wp_enqueue_script( 'plugins'); | |
if ( function_exists( 'add_image_size' ) ) { | |
add_image_size( 'portfolio', 350, 350 ); | |
} | |
add_action('init', 'create_portfolio'); | |
function create_portfolio() { | |
$labels = array( | |
'name' => _x('Portfolio', 'post type general name'), | |
'singular_name' => _x('Portfolio', 'post type singular name'), | |
'add_new' => _x('Add New', 'portfolio'), | |
'add_new_item' => __('Add New Portfolio Item'), | |
'edit_item' => __('Edit Item'), | |
'new_item' => __('New Item'), | |
'view_item' => __('View Item'), | |
'search_items' => __('Search Items'), | |
'not_found' => __('No items found'), | |
'not_found_in_trash' => __('No items found in Trash'), | |
'parent_item_colon' => '' | |
); | |
$args = array( | |
'labels' => $labels, | |
'public' => true, | |
'show_ui' => true, | |
'query_var' => true, | |
'rewrite' => true, | |
'capability_type' => 'post', | |
'hierarchical' => false, | |
'menu_position' => null, | |
'menu_icon' => 'dashicons-portfolio', | |
'supports' => array('title', 'editor', 'thumbnail', 'comments') | |
); | |
register_post_type('portfolio', $args); | |
} | |
register_taxonomy( "portfolio-categories", | |
array( "portfolio" ), | |
array( "hierarchical" => true, | |
"labels" => array('name'=>"Creative Fields", 'add_new_item'=>'Add New Field'), | |
"singular_label" => __( "Field" ), | |
"rewrite" => array( 'slug' => 'fields', | |
'with_front' => false) | |
) | |
); | |
function portfolio_icons() { | |
?> | |
<style type="text/css" media="screen"> | |
#menu-posts-portfolio .wp-menu-image { | |
background: url(<?php bloginfo('template_url') ?>/assets/Pages_Add.png) no-repeat 6px -17px !important; | |
} | |
#menu-posts-portfolio:hover .wp-menu-image, | |
#menu-posts-portfolio.wp-has-current-submenu .wp-menu-image { | |
background-position: 6px 7px !important; | |
} | |
</style> | |
<?php } | |
?> |
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 file for adding a basic template portfolio page for Wordpress themes using the Bootstrap framework.--> | |
<?php | |
/* | |
Template Name: Portfolio | |
*/ | |
?> | |
<?php get_header(); ?> | |
<div class="page-header"> | |
<div class="container"> | |
<h1>Portfolio</h1> | |
<div class="portfolio-filter" class="row"> | |
<ul class="filter"> | |
<?php | |
$terms = get_terms('portfolio-categories'); | |
$count = count($terms); | |
echo '<li><a class="active" href="#" data-filter="*">All</a></li>'; | |
if ( $count > 0 ) { | |
foreach ( $terms as $term ) { | |
$termname = strtolower($term->name); | |
$termname = str_replace(' ', '-', $termname); | |
echo '<li><a href="#" data-filter=".'.$termname.'">'.$term->name.'</a><li>'; | |
} | |
} | |
?> | |
</ul> | |
</div> | |
</div> | |
</div> | |
<div class="portfolio"> | |
<div class="row"> | |
<div class="container"> | |
<div class="isotope"> | |
<ul class="projects"> | |
<?php | |
$args = array( 'post_type' => 'portfolio', 'posts_per_page' => -1 ); | |
$wp_query_portfolio = new WP_Query( $args ); | |
while( $wp_query_portfolio->have_posts() ) : $wp_query_portfolio->the_post(); | |
$terms = get_the_terms( $post->ID, 'portfolio-categories' ); | |
if( $terms && ! is_wp_error( $terms ) ) : | |
$links = array(); | |
foreach ( $terms as $term ) { | |
$links[] = $term->name; | |
} | |
$tax_links = join( " ", str_replace(' ', '-', $links)); | |
$tax = strtolower($tax_links); | |
else : | |
$tax = ''; | |
endif; | |
echo '<li class="project col-xs-12 col-sm-3 col-md-3 all '. $tax .'">'; | |
echo '<a class="wrap-overlay" href="'. get_permalink() .'">'; | |
echo the_post_thumbnail('portfolio'); | |
echo '<div class="overlay">'; | |
echo '</div>'; | |
echo '</a>'; | |
echo '<a class="project-name" href="'. get_permalink() .'">'; | |
echo '<p>'. get_the_title() .'</p>'; | |
echo '<p>'. ucfirst($tax) .'</p>'; | |
echo '</a>'; | |
echo '</li>'; | |
endwhile; ?> | |
</ul> | |
</div> | |
</div> | |
</div> | |
</div> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment