Skip to content

Instantly share code, notes, and snippets.

@Rayhanuc
Created December 4, 2018 17:12
Show Gist options
  • Save Rayhanuc/0ff04f1b4ee3fbab157573fa8e9ce46a to your computer and use it in GitHub Desktop.
Save Rayhanuc/0ff04f1b4ee3fbab157573fa8e9ce46a to your computer and use it in GitHub Desktop.
<?php
//industry_project_shortcode start --4
function industry_project_shortcode($atts){
extract( shortcode_atts( array(
'theme' => '1',
), $atts) );
$project_categories = get_terms('project_cat');
$dynamic_number = rand(45648451, 5646515946);
$industry_project_markup = '
<script>
jQuery(document).ready(function($) {
$(".industry-project-s-active li").click(function(){
$(".industry-project-s-active li").removeClass("active");
$(this).addClass("active");
var selector = $(this).attr("data-filter");
$(".project-list-'.$dynamic_number.'").isotope({
filter: selector,
});
});
});
jQuery(window).load(function() {
jQuery(".project-list-'.$dynamic_number.'").isotope();
});
</script>
<div class="row">';
if ($theme == '1') {
$industry_project_markup .='
<div class="col-md-3">';
$project_list_class = 'industry-project-shorting';
}else {
$industry_project_markup .='
<div class="col-md-12">';
$project_list_class = 'industry-project-shorting-2';
}
$industry_project_markup .= '
<ul class="industry-project-s-active '.$project_list_class.' industry-project-shorting-'.$theme.'">
<li class="active" data-filter="*">All Works</li>';
if ( !empty($project_categories) && ! is_wp_error( $project_categories ) ) {
foreach ($project_categories as $project_category ) {
$industry_project_markup .= '<li data-filter=".'.$project_category->slug.'">'.$project_category->name.'</li>';
}
}
$industry_project_markup .= '
</ul>';
$industry_project_markup .= '
</div>';
if ($theme == '1') {
$project_column_width = 'col-md-9';
$project_inner_column_width = 'col-md-4';
}else {
$project_column_width = 'col-md-12';
$project_inner_column_width = 'col-md-3';
}
$industry_project_markup .= '
<div class="'.$project_column_width.'">
<div class="row project-list-'.$dynamic_number.'">';
$projects_array = new WP_Query(array('post_per_page' => -1, 'post_type' => 'project') );
while($projects_array->have_posts()) : $projects_array->the_post();
$project_category = get_the_terms( get_the_ID(), 'project_cat' );
if ($project_category && ! is_wp_error( $project_category )) {
$project_cat_list = array();
foreach ($project_category as $category ) {
$project_cat_list[] = $category->slug;
}
$project_assigned_cat = join( " ", $project_cat_list );
} else{
$project_assigned_cat = '';
}
$industry_project_markup .= '
<div class="'.$project_inner_column_width.' '.$project_assigned_cat.'">
<a class="single-work-box" href="'.get_permalink().'">
<div class="work-box-bg" style="background-image: url('.get_the_post_thumbnail_url( get_the_ID(), 'large' ).')"><i class="fa fa-link"></i></div>
<p>'.get_the_title().'</p>
</a>
</div>';
endwhile;
wp_reset_query();
$industry_project_markup .= '
</div>
</div>
</div>
';
return $industry_project_markup;
}
add_shortcode('industry_project', 'industry_project_shortcode');
//industry_project_shortcode end
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment