Пример #1
0
function zp_portfolio($columns, $preselect_cat, $lightbox)
{
    global $post;
    $output = '';
    $selected = '';
    $gallery_class = '';
    $size = '3col_portfolio';
    $recent = new WP_Query(array('post_type' => 'portfolio', 'showposts' => '-1'));
    $output .= '<div id="filters" class="gallery-filter">';
    $output .= '<select> <option value="*">' . __('All', 'start') . '</option>';
    $categories = get_categories(array('taxonomy' => 'portfolio_category'));
    foreach ($categories as $category) {
        if ($preselect_cat === $category->slug) {
            $selected = 'selected="selected"';
        } else {
            $selected = '';
        }
        $output .= '<option value=".' . $category->slug . '" ' . $selected . '>' . $category->name . '</option>';
    }
    $output .= '</select></div>';
    $output .= '<div id="gallery-items">';
    //check the no of columns
    if ($columns == 2) {
        $columns = 'col-md-6 col-sm-6 col-xs-12';
        $size = '2col_portfolio';
    } elseif ($columns == 3) {
        $columns = 'col-md-4 col-sm-6 col-xs-12';
        $size = '3col_portfolio';
    } elseif ($columns == 4) {
        $columns = 'col-md-3 col-sm-6 col-xs-12';
        $size = '4col_portfolio';
    }
    while ($recent->have_posts()) {
        $recent->the_post();
        $image_url = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
        $image = get_the_post_thumbnail($post->ID, $size, array('class' => 'img-responsive'));
        // get video link
        $video_link = get_post_meta($post->ID, 'video_link', true);
        if ($lightbox == 'true') {
            // check if video link exists
            if ($video_link) {
                $gallery_class = 'gallery-video';
            } else {
                $gallery_class = 'gallery-image';
            }
        } else {
            $gallery_class = 'gallery-link';
        }
        $output .= '<div class="' . $columns . ' gallery-item all ' . $gallery_class . ' ' . zp_portfolio_items_term($post->ID) . '">';
        if ($lightbox == 'true') {
            if ($video_link) {
                $output .= '<a href="' . $video_link . '">' . $image . '</a>';
            } else {
                $output .= '<a href="' . $image_url . '">' . $image . '</a>';
            }
        } else {
            $output .= '<a href="' . get_permalink() . '">' . $image . '</a>';
        }
        $output .= '</div>';
    }
    wp_reset_query();
    $output .= '</div>';
    return $output;
}
/**
 * Displays the related portfolio in the single portfolio page. 
 */
function zp_related_portfolio()
{
    global $post;
    $terms = get_the_terms($post->ID, 'portfolio_category');
    $term_ids = array_values(wp_list_pluck($terms, 'term_id'));
    $related_columns = genesis_get_option('zp_related_portfolio_columns', ZP_SETTINGS_FIELD);
    $args = array('post_type' => 'portfolio', 'tax_query' => array(array('taxonomy' => 'portfolio_category', 'field' => 'id', 'terms' => $term_ids, 'operator' => 'IN')), 'posts_per_page' => 3, 'orderby' => 'rand', 'post__not_in' => array($post->ID));
    query_posts($args);
    ?>
    <div class = "related_portfolio">		
        <div class="section-title"> <h4><?php 
    echo genesis_get_option('zp_related_portfolio_title', ZP_SETTINGS_FIELD);
    ?>
</h4></div>
    </div>
   <div class="related_container ">
      
      <?php 
    if (have_posts()) {
        while (have_posts()) {
            the_post();
            $t = get_the_title();
            $content = get_the_content_limit(50, '');
            $permalink = get_permalink();
            $thumbnail = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
            ?>
				<div class="element element-3col <?php 
            echo zp_portfolio_items_term($post->ID);
            ?>
">
         			<a href="<?php 
            echo $permalink;
            ?>
" title="<?php 
            echo $t;
            ?>
">
                	<span class="portfolio_overlay">
                    	<h4 class="portfolio_title"><?php 
            echo $t;
            ?>
</h4>
                    </span> <?php 
            echo get_the_post_thumbnail($post->ID, '3col');
            ?>
                 </a>  
 
                </div>
	

		   <?php 
        }
    } else {
        _e('No related projects.', 'novo');
    }
    wp_reset_query();
    ?>

	</div>

<?php 
}