/** * Display related projects. * */ function presscore_display_related_projects() { global $post; $html = ''; $config = presscore_get_config(); // if related projects turn on in theme options if ($config->get('post.related_posts.enabled')) { $terms = array(); switch ($config->get('post.related_posts.query.mode')) { case 'custom': $terms = $config->get('post.related_posts.query.terms'); break; default: $terms = wp_get_object_terms($post->ID, 'dt_portfolio_category', array('fields' => 'ids')); } if ($terms && !is_wp_error($terms)) { $options = array('cats' => $terms, 'select' => 'only', 'post_type' => 'dt_portfolio', 'taxonomy' => 'dt_portfolio_category', 'args' => array('posts_per_page' => intval($config->get('post.related_posts.query.posts_per_page')), 'post__not_in' => array(get_the_ID()))); $posts = presscore_get_posts_in_categories($options); $portfolio_scroller = new Presscore_Portfolio_Posts_Scroller(); $portfolio_scroller->setup($posts, array('class' => 'related-projects slider-wrapper', 'width' => $config->get('post.related_posts.width'), 'height' => $config->get('post.related_posts.height'), 'show_title' => $config->get('post.related_posts.show.title'), 'show_excerpt' => $config->get('post.related_posts.show.description'), 'appearance' => 'under_image', 'padding' => 20, 'bg_under_projects' => false, 'content_aligment' => 'center', 'hover_animation' => 'fade', 'hover_bg_color' => 'accent', 'hover_content_visibility' => 'on_hoover', 'show_link' => $config->get('post.related_posts.show.link'), 'show_details' => $config->get('post.related_posts.show.details_link'), 'show_zoom' => $config->get('post.related_posts.show.zoom'), 'show_date' => $config->get('post.related_posts.meta.fields.date'), 'show_categories' => $config->get('post.related_posts.meta.fields.categories'), 'show_comments' => $config->get('post.related_posts.meta.fields.comments'), 'show_author' => $config->get('post.related_posts.meta.fields.author'), 'arrows' => 'accent')); $html .= $portfolio_scroller->get_html(); if ($html) { $html = '<div class="full-width-wrap">' . $html . '</div>'; // fancy separator $html = presscore_fancy_separator(array('title' => $config->get('post.related_posts.title'), 'class' => 'fancy-projects-title')) . $html; if (!(post_password_required() || !comments_open() && 0 == get_comments_number())) { // add gap after projects $html .= do_shortcode('[dt_gap height="40"]'); } } } } echo (string) apply_filters('presscore_display_related_projects', $html); }
/** * Get related posts attachments data slightly modified. * * @return array Attachments data. */ function presscore_get_related_posts($options = array()) { $default_options = array('select' => 'only', 'exclude_current' => true, 'args' => array()); $options = wp_parse_args($options, $default_options); // exclude current post if in the loop if (in_the_loop() && $options['exclude_current']) { $options['args'] = array_merge($options['args'], array('post__not_in' => array(get_the_ID()))); } $posts = presscore_get_posts_in_categories($options); update_post_thumbnail_cache($posts); $attachments_ids = array(); $attachments_data_override = array(); $posts_data = array(); // get posts attachments id if ($posts->have_posts()) { global $post; $post_back = $post; while ($posts->have_posts()) { $posts->the_post(); // thumbnail or first attachment id if (has_post_thumbnail()) { $attachment_id = get_post_thumbnail_id(); } else { if ($attachment = presscore_get_first_image()) { $attachment_id = $attachment->ID; } else { $attachment_id = 0; } } switch (get_post_type()) { case 'post': $post_meta = presscore_new_posted_on('post'); break; case 'dt_portfolio': $post_meta = presscore_new_posted_on('dt_portfolio'); break; default: $post_meta = presscore_new_posted_on(); } $post_data = array(); ///////////////////////// // attachment data // ///////////////////////// $post_data['full'] = $post_data['width'] = $post_data['height'] = ''; $meta = wp_get_attachment_image_src($attachment_id, 'full'); if (!empty($meta)) { $post_data['full'] = esc_url($meta[0]); $post_data['width'] = absint($meta[1]); $post_data['height'] = absint($meta[2]); } $post_data['thumbnail'] = wp_get_attachment_image_src($attachment_id, 'thumbnail'); $post_data['caption'] = ''; $post_data['video_url'] = esc_url(get_post_meta($attachment_id, 'dt-video-url', true)); $post_data['mime_type_full'] = get_post_mime_type($attachment_id); $post_data['mime_type'] = dt_get_short_post_myme_type($attachment_id); $post_data['ID'] = $attachment_id; $post_data['image_attachment_data'] = array('caption' => $post_data['caption'], 'description' => wp_kses_post(get_post_field('post_content', $attachment_id)), 'title' => presscore_imagee_title_is_hidden($attachment_id) ? '' : get_the_title($attachment_id), 'permalink' => get_permalink($attachment_id), 'video_url' => $post_data['video_url'], 'ID' => $attachment_id); /////////////////// // post data // /////////////////// $post_data['title'] = get_the_title(); $post_data['permalink'] = get_permalink(); $post_data['link'] = presscore_get_project_link('project-link'); $post_data['description'] = get_the_excerpt(); $post_data['alt'] = get_the_title(); $post_data['parent_id'] = get_the_ID(); $post_data['meta'] = $post_meta; // save data $posts_data[] = $post_data; } $post = $post_back; setup_postdata($post); } return $posts_data; }
/** * Get related posts attachments data slightly modified. * * @return array Attachments data. */ function presscore_get_related_posts($options = array()) { $default_options = array('select' => 'only', 'exclude_current' => true, 'args' => array()); $options = wp_parse_args($options, $default_options); // exclude current post if in the loop if (in_the_loop() && $options['exclude_current']) { $options['args'] = array_merge($options['args'], array('post__not_in' => array(get_the_ID()))); } $posts = presscore_get_posts_in_categories($options); $attachments_ids = array(); $attachments_data_override = array(); $posts_data = array(); // get posts attachments id if ($posts->have_posts()) { while ($posts->have_posts()) { $posts->the_post(); // thumbnail or first attachment id if (has_post_thumbnail()) { $attachments_ids[] = get_post_thumbnail_id(); } else { if ($attachment = presscore_get_first_image()) { $attachments_ids[] = $attachment->ID; } else { $attachments_ids[] = 0; } } switch (get_post_type()) { case 'post': $post_meta = presscore_new_posted_on('post'); break; case 'dt_portfolio': $post_meta = presscore_new_posted_on('dt_portfolio'); break; default: $post_meta = presscore_new_posted_on(); } $attachments_data_override[] = array('permalink' => get_permalink(), 'link' => presscore_get_project_link('project-link'), 'title' => get_the_title(), 'description' => get_the_excerpt(), 'alt' => get_the_title(), 'parent_id' => get_the_ID(), 'meta' => $post_meta); } wp_reset_postdata(); } if ($attachments_ids) { // what we want $attachments_data = presscore_get_attachment_post_data($attachments_ids); // what we get $attachments_data_ids = array(); if ($attachments_data) { $attachments_data_ids = wp_list_pluck($attachments_data, 'ID'); } $default_image = presscore_get_default_image(); foreach ($attachments_ids as $key => $id) { $attachments_data_key = array_search($id, $attachments_data_ids); // if there are image - add it to array if (false !== $attachments_data_key) { $posts_data[$key] = $attachments_data[$attachments_data_key]; // or add noimage } else { $posts_data[$key] = array('full' => $default_image[0], 'width' => $default_image[1], 'height' => $default_image[2]); } if (isset($attachments_data_override[$key])) { $posts_data[$key] = array_merge($posts_data[$key], $attachments_data_override[$key]); } } } return $posts_data; }