Skip to content

Instantly share code, notes, and snippets.

@contempoinc
Created January 19, 2016 18:24
Show Gist options
  • Save contempoinc/d8af9d091232f6e32950 to your computer and use it in GitHub Desktop.
Save contempoinc/d8af9d091232f6e32950 to your computer and use it in GitHub Desktop.
Consultant Portfolio Page Builder Block
<?php
/** A simple text block **/
if(!class_exists('AQ_Portfolio_Block')) {
class AQ_Portfolio_Block extends AQ_Block {
//set and create block
function __construct() {
$block_options = array(
'name' => 'Portfolio',
'size' => 'span12',
'resizable' => 0,
);
//create the block
parent::__construct('aq_portfolio_block', $block_options);
}
function form($instance) {
$defaults = array(
'column' => 'items-2-col',
'items' => 3
);
$instance = wp_parse_args($instance, $defaults);
extract($instance);
$columns_options = array(
'items-2-col' => 'Two Columns',
'items-3-col' => 'Three Columns',
'items-4-col' => 'Four Columns',
);
?>
<p>Note: You should only use this block on a full-width template</p>
<p class="description">
<label for="<?php echo $this->get_field_id('title') ?>">
Title (optional)<br/>
<input id="<?php echo $this->get_field_id('title') ?>" class="input-full" type="text" value="<?php echo $title ?>" name="<?php echo $this->get_field_name('title') ?>">
</label>
</p>
<p class="description half">
<label for="<?php echo $this->get_field_id('items') ?>">
Number of Items<br/>
<?php echo aq_field_input('items', $block_id, $items) ?>
</label>
</p>
<?php
}
function block($instance) {
extract($instance); ?>
<h4 class="aq-block-title"><?php echo $title; ?></h4>
<div class="portfolio-wrap">
<div class="container">
<?php if(!is_single()) { ?>
<div id="portfolio-inner"></div>
<div id="ct-loader"><img src="<?php echo get_template_directory_uri() ?>/images/loader.gif"/></div>
<?php } ?>
<div>
<?php ct_tags_nav(); ?>
<?php if(!is_single()) { ?>
<a class="view-all right" href="<?php echo home_url(); ?>/?post_type=portfolio"><?php _e('View All', 'contempo'); ?> <em>&rarr;</em></a>
<div class="clear"></div>
<div id="isotope-container">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
echo '<ul>';
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => $items,
'paged' => $paged
);
$query = new WP_Query($args);
while ( $query->have_posts() ) : $query->the_post(); ?>
<li class="<?php ct_first_term(); ?> item">
<?php ct_first_image_linked_portfolio(); ?>
</li>
<?php endwhile; ?>
</ul>
<?php wp_reset_query(); ?>
</div>
<?php } ?>
</div>
</div>
</div>
<?php
}
function update($new_instance, $old_instance) {
$new_instance['title'] = htmlspecialchars(stripslashes($new_instance['title']));
return $new_instance;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment