| @@ -1,104 +1,104 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -// don't load directly | |
| 4 | -defined( 'ABSPATH' ) || exit; | |
| 5 | - | |
| 6 | - | |
| 7 | -/*-----------------------------------------------------------------------------------*/ | |
| 8 | -/* *. Borderless Related Posts | |
| 9 | -/*-----------------------------------------------------------------------------------*/ | |
| 10 | - | |
| 11 | -function related_posts_after_post_content($content){ | |
| 12 | - | |
| 13 | - if ( !is_admin() && is_singular( 'post' ) ) { | |
| 14 | - | |
| 15 | - global $post; | |
| 16 | - $options = get_option('borderless'); | |
| 17 | - $related_post_background_color = isset( $options['related_post_background_color'] ) ?: '#FFFFFF'; | |
| 18 | - $related_post_background_color_hover = isset( $options['related_post_background_color_hover'] ) ?: '#F5F5F5'; | |
| 19 | - $related_post_title = isset( $options['related_post_title'] ) ?: '#3365c3'; | |
| 20 | - $related_post_title_hover = isset( $options['related_post_title_hover'] ) ?: '#3365c3'; | |
| 21 | - $related_post_content = isset( $options['related_post_content'] ) ?: '#000'; | |
| 22 | - $related_post_content_hover = isset( $options['related_post_content_hover'] ) ?: '#000'; | |
| 23 | - $related_posts_heading = isset( $options['related_posts_heading'] ) ?: 'Recommended For You'; | |
| 24 | - $related_posts_image = isset( $options['related_posts_image'] ) ?: true; | |
| 25 | - $related_posts_excerpt = isset( $options['related_posts_excerpt'] ) ?: true; | |
| 26 | - $related_posts_image_resolution = isset( $options['related_posts_image_resolution'] ) ?: 'medium'; | |
| 27 | - $related_posts_value = isset( $options['related_posts_value'] ) ?: '6'; | |
| 28 | - | |
| 29 | - $content .= '<style type="text/css"> | |
| 30 | - .borderless-related-post {background-color:'. $related_post_background_color .'; } | |
| 31 | - .borderless-related-post:hover {background-color:'. $related_post_background_color_hover .'; } | |
| 32 | - .borderless-related-post:hover .borderless-related-post-body-title {color:'. $related_post_title_hover .'; } | |
| 33 | - .borderless-related-post:hover .borderless-related-post-body-content {color:'. $related_post_content_hover .'; } | |
| 34 | - </style>'; | |
| 35 | - | |
| 36 | - $content .= '<div class="borderless-related-posts">'; | |
| 37 | - | |
| 38 | - $content .= '<h3 class="borderless-related-posts-title">'.$related_posts_heading.'</h3>'; | |
| 39 | - | |
| 40 | - function get_excerpt(){ | |
| 41 | - $options = get_option('borderless'); | |
| 42 | - $related_posts_excerpt_value = isset( $options['related_posts_excerpt_value'] ) ?: '60'; | |
| 43 | - $excerpt = get_the_content(); | |
| 44 | - $excerpt = preg_replace(" (\[.*?\])",'',$excerpt); | |
| 45 | - $excerpt = strip_shortcodes($excerpt); | |
| 46 | - $excerpt = strip_tags($excerpt); | |
| 47 | - $excerpt = substr($excerpt, 0, $related_posts_excerpt_value); | |
| 48 | - return $excerpt; | |
| 49 | - } | |
| 50 | - | |
| 51 | - $related = get_posts( | |
| 52 | - array( | |
| 53 | - 'category__in' => wp_get_post_categories(get_the_ID()), | |
| 54 | - 'numberposts' => $related_posts_value, | |
| 55 | - 'post__not_in' => array(get_the_ID()) | |
| 56 | - ) | |
| 57 | - ); | |
| 58 | - | |
| 59 | - if( $related ) | |
| 60 | - | |
| 61 | - $content .= '<div class="borderless-related-posts-grid">'; | |
| 62 | - | |
| 63 | - foreach( $related as $post ) { | |
| 64 | - | |
| 65 | - setup_postdata($post); | |
| 66 | - | |
| 67 | - if ($related_posts_image == true && has_post_thumbnail()) { | |
| 68 | - $img = get_the_post_thumbnail( get_the_ID(), $related_posts_image_resolution, array( 'class' => 'borderless-related-post-body-image' ) ); | |
| 69 | - } else { | |
| 70 | - $img = ''; | |
| 71 | - } | |
| 72 | - | |
| 73 | - $content .= '<div class="borderless-related-post">'; | |
| 74 | - $content .= '<a rel="bookmark" href="'.get_the_permalink().'">'; | |
| 75 | - | |
| 76 | - $content .= $img; | |
| 77 | - | |
| 78 | - $content .= '<div class="borderless-related-post-body">'; | |
| 79 | - $content .= '<h6 class="borderless-related-post-body-title">'. get_the_title() .'</h6>'; | |
| 80 | - if ($related_posts_excerpt == true) { | |
| 81 | - $content .= '<p class="borderless-related-post-body-content">'. get_excerpt() .'</p>'; | |
| 82 | - } | |
| 83 | - $content .= '</div>'; | |
| 84 | - | |
| 85 | - $content .= '</a>'; | |
| 86 | - $content .= '</div>'; | |
| 87 | - } | |
| 88 | - | |
| 89 | - $content .= '</div>'; | |
| 90 | - | |
| 91 | - wp_reset_postdata(); | |
| 92 | - | |
| 93 | - return $content; | |
| 94 | - | |
| 95 | - } else { | |
| 96 | - | |
| 97 | - return $content; | |
| 98 | - | |
| 99 | - } | |
| 100 | - } | |
| 101 | - | |
| 102 | - add_filter( "the_content", "related_posts_after_post_content" ); | |
| 103 | - | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +// don't load directly | |
| 4 | +defined( 'ABSPATH' ) || exit; | |
| 5 | + | |
| 6 | + | |
| 7 | +/*-----------------------------------------------------------------------------------*/ | |
| 8 | +/* *. Borderless Related Posts | |
| 9 | +/*-----------------------------------------------------------------------------------*/ | |
| 10 | + | |
| 11 | +function related_posts_after_post_content($content){ | |
| 12 | + | |
| 13 | + if ( !is_admin() && is_singular( 'post' ) ) { | |
| 14 | + | |
| 15 | + global $post; | |
| 16 | + $options = get_option('borderless'); | |
| 17 | + $related_post_background_color = isset( $options['related_post_background_color'] ) ?: '#FFFFFF'; | |
| 18 | + $related_post_background_color_hover = isset( $options['related_post_background_color_hover'] ) ?: '#F5F5F5'; | |
| 19 | + $related_post_title = isset( $options['related_post_title'] ) ?: '#3365c3'; | |
| 20 | + $related_post_title_hover = isset( $options['related_post_title_hover'] ) ?: '#3365c3'; | |
| 21 | + $related_post_content = isset( $options['related_post_content'] ) ?: '#000'; | |
| 22 | + $related_post_content_hover = isset( $options['related_post_content_hover'] ) ?: '#000'; | |
| 23 | + $related_posts_heading = isset( $options['related_posts_heading'] ) ?: 'Recommended For You'; | |
| 24 | + $related_posts_image = isset( $options['related_posts_image'] ) ?: true; | |
| 25 | + $related_posts_excerpt = isset( $options['related_posts_excerpt'] ) ?: true; | |
| 26 | + $related_posts_image_resolution = isset( $options['related_posts_image_resolution'] ) ?: 'medium'; | |
| 27 | + $related_posts_value = isset( $options['related_posts_value'] ) ?: '6'; | |
| 28 | + | |
| 29 | + $content .= '<style type="text/css"> | |
| 30 | + .borderless-related-post {background-color:'. $related_post_background_color .'; } | |
| 31 | + .borderless-related-post:hover {background-color:'. $related_post_background_color_hover .'; } | |
| 32 | + .borderless-related-post:hover .borderless-related-post-body-title {color:'. $related_post_title_hover .'; } | |
| 33 | + .borderless-related-post:hover .borderless-related-post-body-content {color:'. $related_post_content_hover .'; } | |
| 34 | + </style>'; | |
| 35 | + | |
| 36 | + $content .= '<div class="borderless-related-posts">'; | |
| 37 | + | |
| 38 | + $content .= '<h3 class="borderless-related-posts-title">'.$related_posts_heading.'</h3>'; | |
| 39 | + | |
| 40 | + function get_excerpt(){ | |
| 41 | + $options = get_option('borderless'); | |
| 42 | + $related_posts_excerpt_value = isset( $options['related_posts_excerpt_value'] ) ?: '60'; | |
| 43 | + $excerpt = get_the_content(); | |
| 44 | + $excerpt = preg_replace(" (\[.*?\])",'',$excerpt); | |
| 45 | + $excerpt = strip_shortcodes($excerpt); | |
| 46 | + $excerpt = strip_tags($excerpt); | |
| 47 | + $excerpt = substr($excerpt, 0, $related_posts_excerpt_value); | |
| 48 | + return $excerpt; | |
| 49 | + } | |
| 50 | + | |
| 51 | + $related = get_posts( | |
| 52 | + array( | |
| 53 | + 'category__in' => wp_get_post_categories(get_the_ID()), | |
| 54 | + 'numberposts' => $related_posts_value, | |
| 55 | + 'post__not_in' => array(get_the_ID()) | |
| 56 | + ) | |
| 57 | + ); | |
| 58 | + | |
| 59 | + if( $related ) | |
| 60 | + | |
| 61 | + $content .= '<div class="borderless-related-posts-grid">'; | |
| 62 | + | |
| 63 | + foreach( $related as $post ) { | |
| 64 | + | |
| 65 | + setup_postdata($post); | |
| 66 | + | |
| 67 | + if ($related_posts_image == true && has_post_thumbnail()) { | |
| 68 | + $img = get_the_post_thumbnail( get_the_ID(), $related_posts_image_resolution, array( 'class' => 'borderless-related-post-body-image' ) ); | |
| 69 | + } else { | |
| 70 | + $img = ''; | |
| 71 | + } | |
| 72 | + | |
| 73 | + $content .= '<div class="borderless-related-post">'; | |
| 74 | + $content .= '<a rel="bookmark" href="'.get_the_permalink().'">'; | |
| 75 | + | |
| 76 | + $content .= $img; | |
| 77 | + | |
| 78 | + $content .= '<div class="borderless-related-post-body">'; | |
| 79 | + $content .= '<h6 class="borderless-related-post-body-title">'. get_the_title() .'</h6>'; | |
| 80 | + if ($related_posts_excerpt == true) { | |
| 81 | + $content .= '<p class="borderless-related-post-body-content">'. get_excerpt() .'</p>'; | |
| 82 | + } | |
| 83 | + $content .= '</div>'; | |
| 84 | + | |
| 85 | + $content .= '</a>'; | |
| 86 | + $content .= '</div>'; | |
| 87 | + } | |
| 88 | + | |
| 89 | + $content .= '</div>'; | |
| 90 | + | |
| 91 | + wp_reset_postdata(); | |
| 92 | + | |
| 93 | + return $content; | |
| 94 | + | |
| 95 | + } else { | |
| 96 | + | |
| 97 | + return $content; | |
| 98 | + | |
| 99 | + } | |
| 100 | + } | |
| 101 | + | |
| 102 | + add_filter( "the_content", "related_posts_after_post_content" ); | |
| 103 | + | |
| 104 | 104 | ?> |