コード例 #1
0
 /**
  * Get a unique id to be used mainly in blocks
  * 
  * WARNING: Not persistent - will change with request order.
  * 
  * @param string   $prefix          a prefix for internal distinction and for output unless disabled  
  * @param boolean  $return_id_only  return id without prefix
  */
 public function unique_id($prefix = '', $return_id_only = false)
 {
     // get item from registry
     $ids = (array) Bunyad::registry()->bunyad_markup_ids;
     $key = $prefix ? $prefix : 'default';
     if (!isset($ids[$key])) {
         $ids[$key] = 0;
     }
     $ids[$key]++;
     // update registry
     Bunyad::registry()->set('bunyad_markup_ids', $ids);
     return ($return_id_only ? '' : $prefix) . $ids[$key];
 }
コード例 #2
0
    /**
     * Get HTML for category label with link. 
     * 
     * Checks global and local settings before generating the output.
     *
     * @uses  Bunyad::registry()->block_atts  The current block attribs in registry
     * @return string|void  HTML with category label
     */
    public function cat_label()
    {
        $category = $this->get_primary_cat();
        $block = Bunyad::registry()->block_atts;
        if (!empty($block) && !$block['cat_labels']) {
            return;
        }
        // Object has category taxonomy? i.e., is it a post or a valid CPT?
        if (!in_array('category', get_object_taxonomies(get_post_type()))) {
            return;
        }
        ob_start();
        ?>
		
		<span class="cat-title cat-<?php 
        echo $category->cat_ID;
        ?>
"><a href="<?php 
        echo esc_url(get_category_link($category));
        ?>
" title="<?php 
        echo esc_attr($category->name);
        ?>
"><?php 
        echo esc_html($category->name);
        ?>
</a></span>
		
		<?php 
        return apply_filters('bunyad_blocks_cat_label', ob_get_clean());
    }
コード例 #3
0
/**
 * Determine the listing style to use
 */
if (empty($type)) {
    $type = Bunyad::options()->default_cat_template;
}
// loop template
$template = strstr($type, 'modern') ? 'loop' : 'loop-' . $type;
// set loop grid type
$loop_grid = '';
if (strstr($type, '-3')) {
    $loop_grid = 3;
    // remove -3 suffix
    $template = str_replace('-3', '', $template);
}
Bunyad::registry()->set('loop_grid', $loop_grid);
// save current options so that can they can be restored later
$options = Bunyad::options()->get_all();
// enable pagination if infinite scroll is enabled - required
if ($pagination_type == 'infinite') {
    $pagination = 1;
}
Bunyad::options()->set('blog_no_pagination', $pagination == 0 ? 1 : 0)->set('pagination_type', $pagination_type);
if ($heading && $heading_type != 'block') {
    ?>
	<h1 class="main-heading prominent"><?php 
    echo $heading;
    ?>
</h1>
<?php 
} elseif ($heading) {
コード例 #4
0
<?php

/**
 * "loop" to display posts when using an existing query. Used for categories and arhives.
 */
?>

	<?php 
global $bunyad_loop;
if (!is_object($bunyad_loop)) {
    $bunyad_loop = $wp_query;
}
// Define the current loop type
$loop_type = empty($loop_type) ? 'grid-overlay' : $loop_type;
// Grid type
$loop_grid = Bunyad::registry()->loop_grid;
if (!isset($loop_grid_class)) {
    $loop_grid_class = $loop_grid ? 'grid-' . $loop_grid : '';
}
if ($bunyad_loop->have_posts()) {
    $attribs = array('class' => array('row listing', 'grid-overlay', $loop_type, $loop_grid_class));
    // infinite load?
    if (Bunyad::options()->pagination_type == 'infinite') {
        $attribs['data-infinite'] = Bunyad::markup()->unique_id('listing-');
    }
    /**
     * Select the image to use 
     */
    if (!isset($loop_image)) {
        // set larger image when full-width, for 2-col grid
        $image = Bunyad::core()->get_sidebar() == 'none' ? 'main-slider' : 'grid-overlay';
コード例 #5
0
 /**
  * Magic handler for blocks
  */
 public function __call($name, $args = array())
 {
     if (!stristr($name, 'sc_block_')) {
         return false;
     }
     $tag = str_replace('sc_block_', '', $name);
     $block = $this->blocks[$tag];
     // get attributes and content from the args array
     $atts = $args[0];
     // intentionally supporting non-listed atts
     $content = $args[1];
     // extract attributes
     if (isset($block['attribs']) && is_array($block['attribs'])) {
         $atts = shortcode_atts($block['attribs'], $atts);
     }
     extract($atts, EXTR_SKIP);
     /*
      * String replacement
      */
     if (isset($block['template'])) {
         $atts['content'] = $content;
         foreach ($atts as $key => $val) {
             $block['template'] = str_replace('%' . $key . '%', $val, $block['template']);
         }
         return do_shortcode($block['template']);
     }
     /*
      * File based
      */
     // include block file from within plugin if no path is specified
     if (!isset($block['render']) or !strstr($block['render'], '/')) {
         $block_file = plugin_dir_path(__FILE__) . 'blocks/' . sanitize_file_name(str_replace('_', '-', $block['render'])) . '.php';
     } else {
         $block_file = $block['render'];
     }
     // no file
     if (!is_array($block) or !file_exists($block_file)) {
         return false;
     }
     // save the current block in registry
     if (class_exists('Bunyad_Registry')) {
         Bunyad::registry()->set('block', $block)->set('block_atts', $atts);
     }
     // get file content
     ob_start();
     include apply_filters('bunyad_block_file', $block_file, $block);
     $block_content = ob_get_clean();
     return do_shortcode($block_content);
 }
コード例 #6
0
<?php

/**
 * Classic Blog Style "loop" to display posts
 */
?>

	<?php 
global $bunyad_loop;
if (!is_object($bunyad_loop)) {
    $bunyad_loop = $wp_query;
}
if ($bunyad_loop->have_posts()) {
    $attribs = array('class' => array('listing-classic', Bunyad::registry()->listing_class));
    if (Bunyad::options()->pagination_type == 'infinite') {
        $attribs['data-infinite'] = Bunyad::markup()->unique_id('listing-');
    }
    ?>
		
	<div <?php 
    Bunyad::markup()->attribs('loop', $attribs);
    ?>
>
	
			<?php 
    while ($bunyad_loop->have_posts()) {
        $bunyad_loop->the_post();
        ?>

				<?php 
        get_template_part('content', get_post_format());