Hi,
I didn’t add any ” <br> ” codes. And I didn’t use a css for the h2 tag, how can I fix them , here the codes which I have used
Thank you
------related-posts-template.php
<?php if (!empty($related_posts)) { ?>
<div class="related-posts">
<h2 class="widget-title"><?php _e('Related Article', 'generatepress'); ?></h2>
<ul class="related-posts-list">
<?php
foreach ($related_posts as $post) {
setup_postdata($post);
?>
<li><font face="Calibri" size="3" color="#666666"><?php echo (int) get_post_meta(get_the_ID(), 'post_views_count', true) . ' Views'; ?></font>
<a class="title" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php if (has_post_thumbnail()) { ?>
<div class="thumb">
<?php echo get_the_post_thumbnail(null, 'medium', array('alt' => the_title_attribute(array('echo' => false)))); ?>
</div>
<?php } ?>
<h4><?php the_title(); ?><?php if ( has_post_thumbnail() ) {
the_post_thumbnail('large');
} else { $post_image_link = catch_that_image(); if ( $post_image_link ) { echo '<div class="post-thumbnail-wrap"><a href="' . esc_url( get_permalink() ) . '" class="post-thumbnail" rel="bookmark">'; echo '<img width="650" height="366" src="' . esc_attr( $post_image_link ) . '" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="' . esc_attr( get_the_title() ) . '"title="' . esc_attr( get_the_title() ) .'">'; echo '</a></div>'; } } ?></h4>
</a>
</li>
<?php } ?>
</ul>
<div class="clearfix"></div>
</div>
<?php
}
---- function.php
// relatedpost
function wcr_related_posts($args = array()) {
global $post;
// default args
$args = wp_parse_args($args, array(
'post_id' => !empty($post) ? $post->ID : '',
'taxonomy' => 'category',
'limit' => 4,
'post_type' => !empty($post) ? $post->post_type : 'post',
'orderby' => 'rand',
'order' => 'DESC'
));
// check taxonomy
if (!taxonomy_exists($args['taxonomy'])) {
return;
}
// post taxonomies
$taxonomies = wp_get_post_terms($args['post_id'], $args['taxonomy'], array('fields' => 'ids'));
if (empty($taxonomies)) {
return;
}
// query
$related_posts = get_posts(array(
'post__not_in' => (array) $args['post_id'],
'post_type' => $args['post_type'],
'tax_query' => array(
array(
'taxonomy' => $args['taxonomy'],
'field' => 'term_id',
'terms' => $taxonomies
),
),
'posts_per_page' => $args['limit'],
'orderby' => $args['orderby'],
'order' => $args['order']
));
include( locate_template('related-posts-template.php', false, false) );
wp_reset_postdata();
}
// relatedpost
-------rand-post.php
<div class="related-posts">
<h2 class="widget-title"><?php _e('Trend Article', 'generatepress'); ?></h2>
<?php
$popular_posts_args = array(
'posts_per_page' => 3,
'meta_key' => 'post_views_count',
'orderby' => 'rand',
'order' => 'DESC'
);
$popular_posts_loop = new WP_Query($popular_posts_args);
while ($popular_posts_loop->have_posts()):
$popular_posts_loop->the_post();
?>
<!-- Post Title -->
<font face="Calibri" size="3" color="#666666"><?php echo (int) get_post_meta(get_the_ID(), 'post_views_count', true) . ' Views'; ?></font>
<a href="<?php the_permalink(); ?>"> <?php the_title(); ?><?php if ( has_post_thumbnail() ) {
the_post_thumbnail('large');} else { $post_image_link = catch_that_image(); if ( $post_image_link ) { echo '<div class="post-thumbnail-wrap"><a href="' . esc_url( get_permalink() ) . '" class="post-thumbnail" rel="bookmark">'; echo '<img width="650" height="366" src="' . esc_attr( $post_image_link ) . '" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="' . esc_attr( get_the_title() ) . '"title="' . esc_attr( get_the_title() ) .'">'; echo '</a></div>'; } } ?></a>
<!-- Post Image -->
<?php the_post_thumbnail('delicious-recent-thumbnails'); ?>
<?php
endwhile;
wp_reset_query();
?>