Esempio n. 1
0
    function sw_portfolio_ajax()
    {
        $catid = isset($_POST["catid"]) && $_POST["catid"] != '' ? $_POST["catid"] : '';
        $page = isset($_POST["page"]) && $_POST["page"] > 0 ? $_POST["page"] : 0;
        $attributes = isset($_POST["attributes"]) && $_POST["attributes"] != '' ? $_POST["attributes"] : '';
        $number = isset($_POST["numb"]) && $_POST["numb"] > 0 ? $_POST["numb"] : 0;
        $orderby = isset($_POST["orderby"]) && $_POST["orderby"] != '' ? $_POST["orderby"] : '';
        $order = isset($_POST["order"]) && $_POST["order"] != '' ? $_POST["order"] : '';
        $style = isset($_POST["style"]) && $_POST["style"] != '' ? $_POST["style"] : '';
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        $categories = explode(',', $catid);
        $args = array('post_type' => 'portfolio', 'tax_query' => array(array('taxonomy' => 'portfolio_cat', 'field' => 'term_id', 'terms' => $categories)), 'posts_per_page' => $number, 'orderby' => $orderby, 'order' => $order, 'offset' => $number * $page);
        $output = '';
        $query = new wp_query($args);
        while ($query->have_posts()) {
            $query->the_post();
            global $post;
            $img_size = get_post_meta($post->ID, 'img_size', true);
            $pterms = get_the_terms($post->ID, 'portfolio_cat');
            $width = 0;
            $height = 0;
            if ($img_size == 'default') {
                $width = 400;
                $height = 270;
            } else {
                if ($img_size == 'p-double-width') {
                    $width = 682;
                    $height = 230;
                } else {
                    if ($img_size == 'p-double-wh') {
                        $width = 800;
                        $height = 540;
                    }
                }
            }
            $term_str = '';
            foreach ($pterms as $key => $term) {
                $term_str .= $term->slug . ' ';
            }
            $img = '';
            if ($style == 'masonry') {
                ?>
				<li class="<?php 
                echo $attributes . ' ' . esc_attr($term_str) . ' ' . esc_attr($img_size);
                ?>
">
					<div class="portfolio-item-inner">
						<div class="portfolio-in">
							<?php 
                if (has_post_thumbnail()) {
                    $img = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
                    $image = ya_image_resize($img, $width, $height, true, false);
                    ?>
							<a class="portfolio-img" href="<?php 
                    the_permalink();
                    ?>
" title="<?php 
                    the_title_attribute();
                    ?>
">
								<img src="<?php 
                    echo esc_attr($image['url']);
                    ?>
" alt="<?php 
                    the_title_attribute();
                    ?>
"/>
							</a>
							<?php 
                }
                ?>
							<a href="<?php 
                the_permalink();
                ?>
" class="p-item item-more" title="<?php 
                the_title_attribute();
                ?>
"><span class="fa fa-link"></span></a>
							<a href="<?php 
                echo esc_attr($img);
                ?>
" class="p-item item-popup" title="<?php 
                the_title_attribute();
                ?>
"><span class="fa fa-search"></span></a>
						</div>
						<div class="pitem-content">
							<h3><a href="<?php 
                the_permalink();
                ?>
" title="<?php 
                the_title_attribute();
                ?>
"><?php 
                the_title();
                ?>
</a></h3>
						</div>
					</div>
				</li>
			<?php 
            } else {
                ?>
					
				<li class="<?php 
                echo $attributes . ' ' . esc_attr($term_str);
                ?>
">
					<div class="portfolio-item-inner">
						<div class="portfolio-in">
							<?php 
                if (has_post_thumbnail()) {
                    $img = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
                }
                ?>
							<a class="portfolio-img" href="<?php 
                the_permalink();
                ?>
" title="<?php 
                the_title_attribute();
                ?>
">
							<?php 
                the_post_thumbnail('large');
                ?>
							</a>
							<a href="<?php 
                the_permalink();
                ?>
" class="p-item item-more" title="<?php 
                the_title_attribute();
                ?>
"><span class="fa fa-link"></span></a>
							<a href="<?php 
                echo esc_attr($img);
                ?>
" class="p-item item-popup" title="<?php 
                the_title_attribute();
                ?>
"><span class="fa fa-search"></span></a>
						</div>
						<div class="pitem-content">
							<h3><a href="<?php 
                the_permalink();
                ?>
" title="<?php 
                the_title_attribute();
                ?>
"><?php 
                the_title();
                ?>
</a></h3>
						</div>
					</div>
				</li>
		<?php 
            }
        }
        wp_reset_postdata();
        exit;
    }
            $term_str .= $term->slug . ' ';
        }
    }
    $img = '';
    if ($style == 'masonry') {
        ?>
				<li class="<?php 
        echo $attributes . ' ' . esc_attr($term_str) . ' ' . esc_attr($img_size);
        ?>
">
					<div class="portfolio-item-inner">
						<div class="portfolio-in">
							<?php 
        if (has_post_thumbnail()) {
            $img = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
            $image = ya_image_resize($img, $width, $height, true, false);
            ?>
							<a class="portfolio-img" href="<?php 
            the_permalink();
            ?>
" title="<?php 
            the_title_attribute();
            ?>
">
								<img src="<?php 
            echo esc_attr($image['url']);
            ?>
" alt="<?php 
            the_title_attribute();
            ?>
"/>