Esempio n. 1
0
function dt_shortcode_portfolio($atts)
{
    global $post;
    $temp = clone $post;
    extract(shortcode_atts(array("ppp" => 3, "orderby" => 'Date', "order" => 'DESC', "class" => 'benefits', "except" => '', "only" => ''), $atts));
    $output = $temp_cat = '';
    $args = array('post_type' => 'dt_portfolio', 'post_status' => 'publish', 'orderby' => $orderby, 'order' => $order);
    if ($ppp) {
        $args['posts_per_page'] = $ppp;
    }
    if ($except || $only) {
        if ($only) {
            $temp_cat = explode(',', str_replace(' ', '', $only));
        } elseif ($except) {
            $temp_cat = explode(',', str_replace(' ', '', $except));
        }
        $args['tax_query'] = array(array('taxonomy' => 'dt_portfolio_category', 'field' => 'id', 'terms' => $temp_cat, 'operator' => $except ? 'NOT IN' : 'IN'));
    }
    $query = new Wp_Query($args);
    if ($query->have_posts()) {
        $output .= '<div class="cols ' . $class . '">';
        while ($query->have_posts()) {
            $query->the_post();
            $defaults = array('quality' => 100, 'zc' => true, 'zc_align' => 'c', 'embed' => '');
            $opts = get_post_meta($post->ID, 'dt_post_thumb_opts_options', true);
            $opts = wp_parse_args($opts, $defaults);
            $post_t_id = get_post_thumbnail_id($post->ID);
            $img = dt_get_thumbnail(array('img_id' => $post_t_id, 'width' => 290, 'height' => 150, 'upscale' => $opts['zc'], 'zc_align' => $opts['zc_align'], 'quality' => $opts['quality']));
            $output .= '<a class="col_1-3" href="' . get_permalink($post->ID) . '">';
            $output .= sprintf('<img src="%s" alt="%s" />
                <div class="mask"></div>
                <div class="desc">
                <h4>%s</h4>
                <div class="desc_text">%s</div>
                </div>', $img['thumnail_img'], esc_attr($post->post_title), apply_filters('the_title', $post->post_title), apply_filters('the_excerpt', get_the_excerpt()));
            $output .= '</a>';
        }
        $output .= '</div>';
    }
    $post = $temp;
    return $output;
}
Esempio n. 2
0
function dt_filter_gallery_sc($output, $attr)
{
    static $hs_gallery_count = 0;
    $hs_gallery_count++;
    global $post, $wp_locale;
    $exclude_def = '';
    $event = '';
    if ($hide_in_gal = get_post_meta($post->ID, 'hide_in_gal', true) && 'gallery' == get_post_format($post->ID)) {
        $exclude_def = get_post_thumbnail_id($post->ID);
    }
    // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
    if (isset($attr['orderby'])) {
        $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
        if (!$attr['orderby']) {
            unset($attr['orderby']);
        }
    }
    extract(shortcode_atts(array('order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'itemtag' => 'li', 'columns' => 3, 'size' => 'thumbnail', 'include' => '', 'exclude' => $exclude_def), $attr));
    $id = intval($id);
    if ('RAND' == $order) {
        $orderby = 'none';
    }
    if (!empty($include)) {
        $include = preg_replace('/[^0-9,]+/', '', $include);
        $_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
        $attachments = array();
        foreach ($_attachments as $key => $val) {
            $attachments[$val->ID] = $_attachments[$key];
        }
    } elseif (!empty($exclude)) {
        $exclude = preg_replace('/[^0-9,]+/', '', $exclude);
        $attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
    } else {
        $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
    }
    if (empty($attachments)) {
        return '';
    }
    if (is_feed()) {
        $output = "\n";
        foreach ($attachments as $att_id => $attachment) {
            $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
        }
        return $output;
    }
    $hs_class = '';
    $hs_data_attr = '';
    if (isset($attr['link']) && 'post' == $attr['link']) {
        $hs_class = " to_attachment";
    } else {
        $event .= 'onclick="return hs.expand(this, { slideshowGroup: \'' . $post->ID . $hs_gallery_count . '\' })"';
        $hs_class = " hs_me";
        $hs_data_attr = ' data-hs_group="' . $post->ID . $hs_gallery_count . '"';
    }
    $itemtag = tag_escape($itemtag);
    $columns = intval($columns);
    $size_class = sanitize_html_class($size);
    $output = "<ul class='gall_std{$hs_class} gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'{$hs_data_attr}>";
    $i = 0;
    foreach ($attachments as $id => $attachment) {
        $class = $description = '';
        $class .= 'highslide ';
        if (isset($attr['link']) && 'post' == $attr['link']) {
            $href = get_permalink($id);
        } else {
            $href = wp_get_attachment_image_src($id, 'full');
            $href = $href ? current($href) : '#';
            $class .= "fadeThis ";
        }
        if ($attachment->post_content) {
            $description = '<p class="wp-caption-text">' . wptexturize($attachment->post_content) . '</p>';
            $class .= 'wp-caption ';
        }
        $alt = get_post_meta($id, '_wp_attachment_image_alt', true);
        $caption = wptexturize(trim($attachment->post_excerpt));
        $dt_img = dt_get_thumbnail(array('img_id' => $id, 'width' => 126, 'height' => 126, 'upscale' => true, 'quality' => 90, 'zc_align' => 'c'));
        $src[0] = $dt_img['thumnail_img'];
        $src[1] = $dt_img['width'];
        $src[2] = $dt_img['height'];
        //$src = wp_get_attachment_image_src($id, $size);
        $link = "<a class='{$class}' href='{$href}' title='{$caption}' {$event}>\n\t\t<img src='{$src[0]}' alt='{$alt}' width='{$src[1]}' height='{$src[2]}'/>{$description}\n\t\t</a>";
        $li_size = $src[1];
        $output .= "<{$itemtag} class='shadow_light gallery-item' style='width: {$li_size}px;'>";
        $output .= $link;
        $output .= "</{$itemtag}>";
    }
    $output .= "</ul>\n";
    return $output;
}