-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshortcode-related-inner-post.php
44 lines (35 loc) · 1.08 KB
/
shortcode-related-inner-post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* masukan [neon_related_posts] didalam artikel,
* ingat harus digunakan didalam artikel.
*/
add_action('neon_related_posts', 'neon_related_posts_func');
function neon_related_posts_func()
{
global $post;
$render = '';
$categories = get_the_category($post->ID);
$cat_ids = array();
if ( ! empty($categories) ) {
foreach($categories as $cat) {
$cat_ids[] = $cat->term_id;
}
}
if ( ! empty($cat_ids) ) {
$args = array(
'cat' => $cat_ids ,
'posts_per_page' => 3
);
$related = new WP_Query($args);
if ( $related->have_posts() ) :
$render .= '<div class="neon-related-posts"><div class="neon-related-post-title">Baca Juga</div><ul>';
$n = 1;
while( $related->have_posts() ) : $related->the_post();
$render .='<li><a href="'. get_permalink() .'" target="_blank" title="'. get_the_title() .'">'. get_the_title().'</a></li>';
endwhile;
$render .= '</ul></div>';
wp_reset_postdata();
endif;
}
return $render;
}