Skip to content

Instantly share code, notes, and snippets.

@goranseric
Forked from mrtwebdesign/page-game-dynamic.php
Created July 30, 2018 04:47
Show Gist options
  • Save goranseric/f53bf76f7f77e4c27019e5a8fb8a4983 to your computer and use it in GitHub Desktop.
Save goranseric/f53bf76f7f77e4c27019e5a8fb8a4983 to your computer and use it in GitHub Desktop.
<?php
/* Template Name: games dynamic */
global $avia_config;
/*
* get_header is a basic wordpress function, used to retrieve the header.php file in your theme directory.
*/
get_header();
if( get_post_meta(get_the_ID(), 'header', true) != 'no') echo avia_title();
$loading_gif_url = home_url().'/wp-content/uploads/2016/08/loading.gif';
?>
<div class='container_wrap container_wrap_first main_color shop_columns_3 <?php avia_layout_class( 'main' ); ?>'>
<div class='container'>
<div class="row game-header-row">
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id(),'featured');
$text_overlay = get_post_meta($post->ID,'_moblab_overlay_text',true);
?>
<div class="visible-xs-block col-xs-12 mobile-game-col-left">
<div class="mobile-image-container" style="background-image:url('<?php echo $image[0]; ?>');">
<div class="text_overlay_mobile"><?php echo $text_overlay; ?></div>
</div>
</div>
<div class="hidden-xs col-sm-9 game-header-col game-col-left" style="background-image:url('<?php echo $image[0]; ?>');">
<div class="text_overlay_desktop"><?php echo $text_overlay; ?></div>
</div>
<div class="col-xs-12 col-sm-3 game-header-col game-col-right">
<?php $topic_one_id = get_post_meta($post->ID,'_moblab_topic_one',true);
$term_one = get_term_by('id',$topic_one_id,'product_cat');
$term_one_image_id = get_post_meta($post->ID,'_moblab_image_top_id',true);
$image = wp_get_attachment_image_src( $term_one_image_id ,'featured');
?>
<div class="side-gamelink-container facet-data" data-topic="<?php echo $term_one->slug; ?>">
<img width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" src="<?php echo $image[0]; ?>">
<div class="text-overlay-wrap clearfix cf">
<?php
$topic_one_label = get_post_meta($post->ID,'_moblab_topic_one_label',true);
echo $topic_one_label;
?>
</div>
<div class="ajax-loading-indicator hidden"><img height="80" width="80" src="<?php echo $loading_gif_url; ?>"></div>
</div>
<?php
$topic_two_id = get_post_meta($post->ID,'_moblab_topic_two',true);
$term_two = get_term_by('id',$topic_two_id,'product_cat');
$term_two_image_id = get_post_meta($post->ID,'_moblab_image_middle_id',true);
$image = wp_get_attachment_image_src( $term_two_image_id ,'featured');
?>
<div class="side-gamelink-container facet-data" data-topic="<?php echo $term_two->slug; ?>">
<img width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" src="<?php echo $image[0]; ?>">
<div class="text-overlay-wrap clearfix cf">
<?php
$topic_two_label = get_post_meta($post->ID,'_moblab_topic_two_label',true);
echo $topic_two_label;
?>
</div>
<div class="ajax-loading-indicator hidden"><img height="80" width="80" src="<?php echo $loading_gif_url; ?>"></div>
</div>
<?php
$topic_three_link = get_post_meta($post->ID,'_moblab_topic_three_link',true);
$topic_three_label = get_post_meta($post->ID,'_moblab_topic_three_label',true);
$term_three_image_id = get_post_meta($post->ID,'_moblab_image_bottom_id',true);
$image = wp_get_attachment_image_src( $term_three_image_id ,'featured');
?>
<div class="side-gamelink-container side-gamelink-container-last">
<img width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" src="<?php echo $image[0]; ?>">
<a href="<?php $topic_three_link ?>">
<div class="text-overlay-wrap clearfix">
<?php
$topic_three_label = get_post_meta($post->ID,'_moblab_topic_three_label',true);
echo $topic_three_label;
?>
</div>
</a>
<div class="ajax-loading-indicator hidden"><img height="80" width="80" src="<?php echo $loading_gif_url; ?>"></div>
</div>
</div>
</div>
<?php
$args = wp_parse_args( $query_args, array(
'type' => 'product',
'post_type' => 'product',
'taxonomy' => 'category',
) );
$product_categories = get_terms( 'product_cat', $args );
$product_categories_hierarchical = array();
sort_terms_hierarchicaly($product_categories, $product_categories_hierarchical);
?>
<?php
$blurb[] = get_post_meta($post->ID,'_moblab_blurb_one',true);
$link_url[] = get_post_meta($post->ID,'_moblab_blurb_one_link',true);
$blurb[] = get_post_meta($post->ID,'_moblab_blurb_two',true);
$link_url[] = get_post_meta($post->ID,'_moblab_blurb_two_link',true);
$blurb[] = get_post_meta($post->ID,'_moblab_blurb_three',true);
$link_url[] = get_post_meta($post->ID,'_moblab_blurb_three_link',true);
?>
<div class="row row-search-bar">
<div class="col-sm-6 text-blurb">
<img class="bulb-games" src="<?php echo home_url(); ?>/wp-content/uploads/2016/08/bulb_games.png">
<?php $pick = rand(0,2); ?>
<a href"<?php echo $link_url[$pick]; ?>"><?php echo $blurb[$pick]; ?></a>
</div>
<div class="col-sm-3 filters">
<ul class="nfacet-controls">
<li>
<div class="nfacetwp-facet nfacetwp-type-dropdown">
<select id="filterset" class="nfacetwp-dropdown">
<option value="all">Show: All Games</option>
<option value="featured">Featured</option>
<option value="favorites">Go to: Favorites</option>
<?php foreach($product_categories_hierarchical as $product_category){
$value = $product_category->slug;
$name = $product_category->name;
echo '<option value="'.$value.'">'.$name.'</option>';
if ( count($product_category->children) > 0 ){
foreach($product_category->children as $category_child){
$value = $category_child->slug;
$name = $category_child->name;
echo '<option value="'.$value.'">&nbsp;&nbsp;'.$name.'</option>';
}
}
}
?>
</select>
</div>
</li>
<li class="hidden topics-wrap">
<?php //echo apply_filters( 'the_content', '[facetwp facet="topics"]' ); ?>
</li>
<li class="hidden featured-wrap">
<?php //echo apply_filters( 'the_content', '[facetwp facet="featured"]' ); ?>
</li>
</ul>
</div>
<div class="col-sm-3 search-box-container">
<?php echo do_shortcode('[yith_woocommerce_ajax_search]'); ?>
</div>
<div class="col-sm-9 loading-over-content">
<div class="ajax-loading-indicator hidden"><img height="80" width="80" src="<?php echo $loading_gif_url; ?>"></div>
</div>
</div>
<main class='template-page content <?php avia_layout_class( 'content' ); ?> units' <?php avia_markup_helper(array('context' => 'content','post_type'=>'page'));?>>
<?php $avia_config['size'] = avia_layout_class( 'main' , false) == 'entry_without_sidebar' ? '' : 'entry_with_sidebar';?>
<div id="game-catalog" class="row">
<div id="catalog-inner" class="col-sm-9">
<?php echo apply_filters( 'the_content', '[facetwp template="wc_products"]' ); ?>
</div>
<div id="games-sidebar" class="col-sm-3">
<?php dynamic_sidebar( 'gamepagesidebar' ); ?>
</div>
</div>
<!--end content-->
</main>
<?php
$avia_config['currently_viewing'] = 'page';
get_sidebar();
?>
</div><!--end container-->
</div><!-- close default .container_wrap element -->
<script>
jQuery(document).ready(function($){
$('.side-gamelink-container.facet-data').click(function(){
$(this).find('.ajax-loading-indicator').removeClass('hidden');
});
$(document).on('facetwp-refresh', function() {
console.log('facetwp-refresh event');
jQuery('.row-search-bar .ajax-loading-indicator').removeClass('hidden');
});
$(document).on('facetwp-loaded', function() {
console.log('facetwp-loaded event');
jQuery('.ajax-loading-indicator').addClass('hidden');
});
$('.inner_product_header > a:last-of-type').click(function(e){
console.log('title link clicked-on');
//e.stopPropagation();
e.preventDefault();
});
$('.yith-wcwl-wishlistexistsbrowse a').click(function(e){
console.log('favorited star clicked on');
e.stopPropagation();
//e.preventDefault();
});
$('.yith-wcwl-wishlistaddedbrowse a').click(function(e){
console.log('recently favorited star clicked on');
e.stopPropagation();
//e.preventDefault();
});
$('.inner_product a img.wp-post-image').click(function(e){
console.log('thumbnail clicked-on');
//e.stopPropagation();
e.preventDefault();
jQuery(this).parent().parent().parent().click();
});
var empty = new Array();
$("#filterset").change(function(e){
jQuery('.row-search-bar .ajax-loading-indicator').removeClass('hidden');
var currentSelectVal = $(this).val();
console.log('Current Selection: '+currentSelectVal);
if (currentSelectVal == 'all'){
FWP.reset();
} else if (currentSelectVal == 'featured'){
FWP.facets.featured = ['featured'];
FWP.facets.topics = [];
FWP.fetch_data();
} else if (currentSelectVal == 'favorites'){
window.location.href = "<?php echo home_url('favorites/view'); ?>";
} else if (currentSelectVal == 'test'){
console.log('running test');
FWP.facets.topics = ['psychology'];
FWP.facets.featured = [];
FWP.fetch_data();
} else {
console.log('Processing a Topic.');
FWP.facets['featured'] = [];
FWP.facets['topics'] = [currentSelectVal];
FWP.fetch_data();
}
console.log(FWP);
});
jQuery('.facet-data').click(function(){
console.log('topic link clicked');
var target = jQuery(this).data('topic');
FWP.facets['featured'] = [];
FWP.facets['topics'] = [target];
FWP.fetch_data();
jQuery('#filterset').val(target);
});
/*
(function($) {
window.fwp_is_paging = false;
$(document).on('facetwp-refresh', function() {
if (! window.fwp_is_paging) {
window.fwp_page = 1;
FWP.extras.per_page = 'default';
}
window.fwp_is_paging = false;
});
$(document).on('facetwp-loaded', function() {
window.fwp_total_rows = FWP.settings.pager.total_rows;
if (! FWP.loaded) {
window.fwp_default_per_page = FWP.settings.pager.per_page;
$(window).scroll(function() {
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
var rows_loaded = (window.fwp_page * window.fwp_default_per_page);
if (rows_loaded < window.fwp_total_rows) {
window.fwp_page++;
window.fwp_is_paging = true;
FWP.extras.per_page = (window.fwp_page * window.fwp_default_per_page);
FWP.soft_refresh = true;
FWP.refresh();
}
}
});
}
});
})(jQuery);
*/
/*
After FacetWP reloads, store any updates into a cookie
*/
$(document).on('facetwp-loaded', function() {
var date = new Date();
var facets = window.location.search;
date.setTime(date.getTime()+(24*60*60*1000));
document.cookie = "facetdata="+facets+"; expires="+date.toGMTString()+"; path=/";
});
/*
When FacetWP first initializes, look for the "facetdata" cookie
If it exists, set window.location.search= facetdata
*/
$(document).on('facetwp-refresh', function() {
if (! FWP.loaded) {
var facetdata = readCookie('facetdata');
if (null != facetdata && '' != facetdata) {
document.cookie = 'facetdata=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';
window.location.search = facetdata;
}
}
});
/*
Cookie handler
*/
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
});
</script>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment