/** * Return an array of portfolios * * @param array $array * * @return array * @since 1.0 * @author Antonio La Rocca <*****@*****.**> */ function yit_get_portfolios($array = array()) { $posts = get_posts(array('post_type' => YIT_Portfolio()->portfolios_post_type)); foreach ($posts as $post) { $array[$post->post_name] = $post->post_title; } return $array; }
/** * Print portfolio page title * * @return void * @since 2.0.0 * @author Antonio La Rocca <*****@*****.**> */ function yit_portfolio_title_bar() { global $post; $portfolio = YIT_Portfolio()->get_portfolio($post->post_type); $custom_button_label = $portfolio->get('custom_button_label'); $custom_button_url = $portfolio->get('custom_button_url'); $html = "<div class='portfolio_small_image portfolio-title-bar'>"; $html .= "<div class='container'>"; $html .= "<div class='row'>"; $html .= "<div class='col-sm-12'>"; $html .= yit_string("<h2 class='post-title portfolio-title'><a href='" . get_permalink() . "'>", get_the_title(), "</a></h2>", false); if ($custom_button_label != '' && $custom_button_url != '') { $html .= "<a class='btn btn-flat' href='" . $custom_button_url . "'>" . $custom_button_label . "</a>"; } $html .= "</div>"; $html .= "</div>"; $html .= "</div>"; $html .= "</div>"; echo $html; }
/** * The shortcode used to show the frontend * * @param array $atts * @param null $content * * @return string|null * @since 1.0 * @author Antonino Scarfi' <*****@*****.**> */ public function add_shortcode( $atts, $content = null ) { $atts = wp_parse_args( $atts, array( 'name' => null, 'cat' => array(), 'posts_per_page' => false, 'style' => null, ) ); // don't show the slider if 'name' is empty or is 'none' if ( empty( $atts['name'] ) || 'none' == $atts['name'] ) return null; // compatibility fix: remove prefix if exists in portfolio object if( function_exists( 'YIT_Portfolio' ) && method_exists( YIT_Portfolio(), 'is' ) && YIT_Portfolio()->is( $atts['name'] ) ){ $atts['name'] = str_replace( YIT_Portfolio()->post_type_prefix, '', $atts['name'] ); } // pass vars to template $atts['post_type'] = $this->_get_post_type_by_name( $atts['name'] ); $atts['layout'] = $this->_args['manage_layouts'] ? get_post_meta( $this->_get_id_by_name( $atts['post_type'] ), $this->_args['layout_option'], true ) : ''; extract( apply_filters( 'yit_cptu_frontend_vars', $atts, $this->_name ) ); // add the javascript assets if ( $this->_args['manage_layouts'] && isset( $this->layouts[ $layout ]['js'] ) && ! empty( $this->layouts[ $layout ]['js'] ) ) { foreach ( $this->layouts[ $layout ]['js'] as $asset ) { if ( empty( $asset ) ) continue; if ( empty( $asset['src'] ) ) { wp_enqueue_script( $asset['handle'] ); continue; } yit_enqueue_script( $asset['handle'], $this->locate_url( $layout ) . $asset['src'], $asset['deps'], $asset['ver'], $asset['in_footer'] ); } } // Unique sequential index to differentiate more cpt in the same page ++$this->index; ob_start(); include( $this->locate_file( $layout, 'markup' ) ); return ob_get_clean(); }
/** * Define the variables for the frontend of the shortcode * * @param $vars * @param $post_type * * @return array * @since 1.0 * @author Antonino Scarfì <*****@*****.**> */ public function frontend_vars($vars, $post_type) { if ($post_type != $this->portfolios_post_type) { return $vars; } $vars['portfolio'] = YIT_Portfolio()->get_portfolio($vars['name']); if (!is_single()) { $vars['portfolio']->init_query(); } return $vars; }
/** * widget function. * * @see WP_Widget * @access public * * @param array $args * @param array $instance * * @return void */ function widget($args, $instance) { ob_start(); extract($args); $title = apply_filters('widget_title', $instance['title']); if (!($number = (int) $instance['number'])) { $number = 6; } else { if ($number < 1) { $number = 3; } else { if ($number > 15) { $number = 15; } } } $current_portfolio = $instance['portfolio']; $portfolio = YIT_Portfolio()->get_portfolio($current_portfolio); $portfolio->init_query(); if ($portfolio->have_posts()) { ?> <?php echo $before_widget; ?> <div class="clearfix widget random-prjects"> <?php if ($title) { echo '<h3>' . $title . '</h3>'; } ?> <ul class="clearfix products-thumbnails"> <?php while ($portfolio->have_posts()) { $portfolio->the_post(); $image = $portfolio->get_image('portfolio_thumb', array('class' => 'img-responsive')); if (strcmp($image, '') != 0) { ?> <li> <a href="<?php echo $portfolio->get('permalink'); ?> " class="with-tooltip project_img" title="<?php echo esc_attr($portfolio->get('title')); ?> "> <?php echo $image; ?> </a> </li> <?php } ?> <?php } ?> </ul> </div> <?php echo $after_widget; ?> <?php } $content = ob_get_clean(); if (isset($args['widget_id'])) { $cache[$args['widget_id']] = $content; } echo $content; wp_reset_postdata(); }
/** * Add portfolio single layout setup on after setup theme * * @since 2.0.0 * @author Antonio La Rocca <*****@*****.**> */ function init_portfolio_layouts() { if (function_exists('YIT_Portfolio')) { add_filter('yit_cptu_' . YIT_Portfolio()->portfolios_post_type . '_layout_values', 'yit_portfolio_layout_values'); } }
/** * Get a value for the portfolio configuration (with 'config-') or current project loop * * @param string $var The name of variable * @param array $args * * @return mixed * @since 1.0 * @author Antonino Scarfì <*****@*****.**> */ public function get($var, $args = array()) { $defaults = array('post_id' => false, 'echo' => false, 'size' => 'post-thumbnail', 'attr' => ''); extract(wp_parse_args($args, $defaults)); // general variables if ('baseurl' == $var) { return YIT_Portfolio()->cptu->locate_url($this->config->layout); } // get from portfolio config if (strpos($var, 'config-') !== false) { if (!$post_id) { $post_id = $this->config->ID; } $var = str_replace('config-', '', $var); if (isset($this->config->{$var})) { return $this->config->{$var}; } elseif ($var = get_post_meta($post_id, '_' . $this->config->layout . '_' . $var, true)) { return $var; } elseif ($var = get_post_meta($post_id, '_' . $var, true)) { return $var; } else { return null; } } // get from item if (!is_null($this->query) || is_single()) { global $post; if (!$post_id && isset($post->ID)) { $post_id = $post->ID; } elseif (!isset($post->ID)) { return null; } if ('title' == $var) { return get_the_title($post_id); } elseif ('content' == $var) { $content = get_the_content(); if ($echo) { $content = apply_filters('the_content', $content); } return $content; } elseif ('permalink' == $var) { return get_permalink($post_id); } elseif ('image' == $var) { return $this->get_image($size, $attr); } elseif ('ID' == $var) { return $post_id; } elseif ('excerpt' == $var) { return get_the_excerpt(); } else { return get_post_meta($post_id, '_' . $var, true); } } }
* * This source file is subject to the GNU GENERAL PUBLIC LICENSE (GPL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://www.gnu.org/licenses/gpl-3.0.txt */ global $post; $enable_hover = $enable_hover == 'yes' ? true : false; $enable_title = $enable_title == 'yes' ? true : false; $enable_categories = $enable_categories == 'yes' ? true : false; $excluded_ids = isset($excluded_ids) ? explode(', ', $excluded_ids) : array(); $animate_data = $animate != '' ? 'data-animate="' . $animate . '"' : ''; $animate_data .= $animation_delay != '' ? ' data-delay="' . $animation_delay . '"' : ''; $animate = $animate != '' ? ' yit_animate' : ''; if (!empty($portfolios)) { $portfolio = YIT_Portfolio()->get_portfolio($portfolios); $portfolio->init_query(array('posts_per_page' => $nitems)); wp_enqueue_script('owl-carousel'); if ($portfolio->have_posts()) { ?> <div class="portfolio-slider-outer <?php echo esc_attr($animate . $vc_css); ?> " <?php echo $animate_data; ?> > <div class="portfolio-slider" data-postid="<?php echo $portfolio->config->ID; ?> ">