コード例 #1
0
ファイル: shortcodes.php プロジェクト: Grobyo/wp-listings
function wp_listings_shortcode($atts, $content = null)
{
    extract(shortcode_atts(array('id' => '', 'taxonomy' => '', 'term' => '', 'limit' => '', 'columns' => ''), $atts));
    /**
     * if limit is empty set to all
     */
    if (!$limit) {
        $limit = -1;
    }
    /**
     * if columns is empty set to 0
     */
    if (!$columns) {
        $columns = 0;
    }
    /*
     * query args based on parameters
     */
    $query_args = array('post_type' => 'listing', 'posts_per_page' => $limit);
    if ($id) {
        $query_args = array('post_type' => 'listing', 'post__in' => explode(',', $id));
    }
    if ($term && $taxonomy) {
        $query_args = array('post_type' => 'listing', 'posts_per_page' => $limit, 'tax_query' => array(array('taxonomy' => $taxonomy, 'field' => 'slug', 'terms' => $term)));
    }
    /*
     * start loop
     */
    global $post;
    $listings_array = get_posts($query_args);
    $count = 0;
    $output = '<div class="wp-listings-shortcode">';
    foreach ($listings_array as $post) {
        setup_postdata($post);
        $count = $count == $columns ? 1 : $count + 1;
        $first_class = 1 == $count ? 'first' : '';
        $output .= '<div class="listing-wrap ' . get_column_class($columns) . ' ' . $first_class . '"><div class="listing-widget-thumb"><a href="' . get_permalink() . '" class="listing-image-link">' . get_the_post_thumbnail($post->ID, 'listings') . '</a>';
        if ('' != wp_listings_get_status()) {
            $output .= '<span class="listing-status ' . strtolower(str_replace(' ', '-', wp_listings_get_status())) . '">' . wp_listings_get_status() . '</span>';
        }
        $output .= '<div class="listing-thumb-meta">';
        if ('' != get_post_meta($post->ID, '_listing_text', true)) {
            $output .= '<span class="listing-text">' . get_post_meta($post->ID, '_listing_text', true) . '</span>';
        } elseif ('' != wp_listings_get_property_types()) {
            $output .= '<span class="listing-property-type">' . wp_listings_get_property_types() . '</span>';
        }
        if ('' != get_post_meta($post->ID, '_listing_price', true)) {
            $output .= '<span class="listing-price">' . get_post_meta($post->ID, '_listing_price', true) . '</span>';
        }
        $output .= '</div><!-- .listing-thumb-meta --></div><!-- .listing-widget-thumb -->';
        if ('' != get_post_meta($post->ID, '_listing_open_house', true)) {
            $output .= '<span class="listing-open-house">' . __("Open House", 'wp_listings') . ': ' . get_post_meta($post->ID, '_listing_open_house', true) . '</span>';
        }
        $output .= '<div class="listing-widget-details"><h3 class="listing-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3>';
        $output .= '<p class="listing-address"><span class="listing-address">' . wp_listings_get_address() . '</span><br />';
        $output .= '<span class="listing-city-state-zip">' . wp_listings_get_city() . ', ' . wp_listings_get_state() . ' ' . get_post_meta($post->ID, '_listing_zip', true) . '</span></p>';
        if ('' != get_post_meta($post->ID, '_listing_bedrooms', true) || '' != get_post_meta($post->ID, '_listing_bathrooms', true) || '' != get_post_meta($post->ID, '_listing_sqft', true)) {
            $output .= '<ul class="listing-beds-baths-sqft"><li class="beds">' . get_post_meta($post->ID, '_listing_bedrooms', true) . '<span>' . __("Beds", 'wp_listings') . '</span></li> <li class="baths">' . get_post_meta($post->ID, '_listing_bathrooms', true) . '<span>' . __("Baths", 'wp_listings') . '</span></li> <li class="sqft">' . get_post_meta($post->ID, '_listing_sqft', true) . '<span>' . __("Square Feet", 'wp_listings') . '</span></li></ul>';
        }
        $output .= '</div><!-- .listing-widget-details --></div><!-- .listing-wrap -->';
    }
    $output .= '</div><!-- .wp-listings-shortcode -->';
    wp_reset_postdata();
    return $output;
}
コード例 #2
0
<?php

echo '<ul class="portfolio-list">';
if (have_posts()) {
    while (have_posts()) {
        the_post();
        $image_tag = get_image(array('post_id' => get_the_ID(), 'echo' => false, 'width' => 450, 'responsive' => true, 'class' => 'img-responsive'));
        echo $item_tmpl = '
            <li class="col-sm-6 col-xs-12 ' . get_column_class(get_setting('columns')) . ' isotope-item">
    			<div class="portfolio-item img-thumbnail">
    				<a href="' . get_permalink() . '" class="thumb-info">
    					' . $image_tag . '
    					<span class="thumb-info-title">
    						<span class="thumb-info-inner">' . get_the_title() . '</span>
    						<span class="thumb-info-type">' . single_cat_title('', false) . '</span>
    					</span>
    					<span class="thumb-info-action">
    						<span title="' . __('Universal', 'spyropress') . '" class="thumb-info-action-icon"><i class="fa fa-link"></i></span>
    					</span>
    				</a>
    			</div>
    		</li>';
    }
}
echo '</ul>';
コード例 #3
0
}
// Ensure visibility
if (!$product || !$product->is_visible()) {
    return;
}
// Increase loop count
$woocommerce_loop['loop']++;
// Extra post classes
$classes = array();
if (0 == ($woocommerce_loop['loop'] - 1) % $woocommerce_loop['columns'] || 1 == $woocommerce_loop['columns']) {
    $classes[] = 'first';
}
if (0 == $woocommerce_loop['loop'] % $woocommerce_loop['columns']) {
    $classes[] = 'last';
}
$classes[] = get_column_class($woocommerce_loop['columns']);
?>

<li <?php 
post_class($classes);
?>
>

	<?php 
/**
 * woocommerce_before_shop_loop_item hook
 *
 * @hooked woocommerce_show_product_loop_sale_flash - 10
 */
do_action('woocommerce_before_shop_loop_item');
?>
コード例 #4
0
 /**
  * @see Walker::end_lvl()
  */
 function end_lvl(&$output, $depth = 0, $args = array())
 {
     $indent = str_repeat("\t", $depth);
     if ($depth === 1 && $this->has_megamenu && $this->is_column) {
         // do nothing
     } elseif (0 === $depth && $this->has_megamenu) {
         $col_class = $this->columns > 4 ? get_column_class(6) : get_column_class($this->columns);
         $output = str_replace('{col_class}', $col_class, $output);
         $output .= '</div></div></li></ul>';
     } else {
         $output .= "{$indent}</ul>\n";
     }
 }
コード例 #5
0
/**
 * Query Generator
 * Generate query and loop through it, with column logic enabled.
 */
function spyropress_query_generator($atts, $content = null)
{
    // default setting
    $default = array('callback' => '', 'row' => 1, 'row_container' => 'div', 'row_class' => get_row_class(true), 'column_class' => '', 'columns' => 1, 'pagination' => false);
    $atts = wp_parse_args($atts, $default);
    $output = '';
    $counter = $column_counter = 0;
    $columns = $atts['columns'];
    $callback = $atts['callback'];
    $close = false;
    // Add Pagination
    if ($atts['limit']) {
        $atts['posts_per_page'] = $atts['limit'];
        unset($atts['limit']);
        if ($atts['pagination']) {
            $atts['paged'] = get_page_query();
        }
    }
    // set column cssClass
    $colclass = array();
    $colclass[] = get_column_class($columns);
    $colclass[] = $atts['column_class'];
    // if is archive merge wp_query
    if (is_archive() || is_search()) {
        global $wp_query;
        if (!empty($wp_query->query)) {
            $atts = array_merge($wp_query->query, $atts);
        }
    }
    // init wp_query
    $posts = new WP_Query($atts);
    if ($posts->have_posts()) {
        while ($posts->have_posts()) {
            $posts->the_post();
            $counter++;
            // if has column defined
            if ($columns) {
                $column_counter++;
                $colclass_fl = array();
                if ($column_counter == 1) {
                    if ($atts['row']) {
                        $output .= '<' . $atts['row_container'] . ' class="' . $atts['row_class'] . '">';
                        $close = true;
                    }
                    $colclass_fl[] = get_first_column_class();
                }
                if ($column_counter == $columns) {
                    $colclass_fl[] = get_last_column_class();
                }
                $atts['column_class'] = spyropress_clean_cssclass(array_merge($colclass, $colclass_fl));
                // get the item using the defined callback function
                if ($callback) {
                    $output .= call_user_func_array($callback, array(get_the_ID(), $atts, $counter, $column_counter));
                }
                if ($column_counter == $columns) {
                    $column_counter = 0;
                    if ($atts['row']) {
                        $output .= '</' . $atts['row_container'] . '>';
                        $close = false;
                    }
                }
            } else {
                if ($callback) {
                    $output .= call_user_func_array($callback, array(get_the_ID(), $atts, $counter, $column_counter));
                }
            }
        }
        // close last unclosed row
        if (isset($atts['row']) && $atts['row'] && $close) {
            $output .= '</' . $atts['row_container'] . '>';
        }
        wp_reset_query();
        // get pagination for query if enabled
        $pagination = '';
        if ($atts['pagination']) {
            $pagination = wp_pagenavi(array('query' => $posts, 'echo' => false));
        }
        return array('content' => $output, 'pagination' => $pagination);
    } else {
        wp_reset_query();
        return;
    }
}