I use this code to show different posts in different divs.
I have 2 problems:
get_category_link($recent['ID'])
<div class="modulex">
<?php
$args = array('numberposts' => '1', 'post_status' => 'publish', 'offset' => '2');
$recent_posts = wp_get_recent_posts($args);
foreach ($recent_posts as $recent) {?>
<div><?php echo get_the_post_thumbnail($recent['ID'],'small', array('class'=>'img-fluid')); ?></div>
<div class="spanlike"><h6><a href="<?php get_permalink($recent["ID"]) ?>"><?php echo $recent["post_title"] ?></a></h6></div>
<?php } ?>
</div><?php
wp_reset_query();
?>
The problem with this is that get_category_link
requires a category ID as argument, not post ID. To get around this, you'll have to perform several steps:
I would suggest using a custom function for this. Example below.
Here I think your problem is that get_permalink
returns rather than echos. You could use the permalink
instead:
<div class="spanlike"><h6><a href="<?php the_permalink($recent["ID"]) ?>"><?php echo $recent["post_title"] ?></a></h6></div>
Example function for retrieving category link from post ID:
function get_cat_link_from_postID($postID) {
$categories = get_the_category($postID);
$catID = $categories[0]->term_id;
return get_category_link($catID);
}