I've done some research and tried different solutions but this snippet gets me the actual post content in sidebar, when on a single/article page, from the category the post belogs to.
But I need to show the excerpt instead of the whole text and also a thumbnail and can't figure out how to add them.
Any suggestions please?
<?php
$categories = get_the_category();
echo '<ul><li>';
foreach ($categories as $c) {
if (strpos(get_permalink($post->ID), $c->slug) !== false) {
echo '<a href="/' . $c->slug . '/">' . $c->name . '</a>';
$current_cat = $c->cat_ID;
}
}
$posts = get_posts(array('cat' => $current_cat));
if (!empty($posts)) {
echo '<ul>';
foreach ($posts as $p) {
echo '<li><a href="' . get_permalink($p->ID) . '">' . $p->post_title . '</a></li>';
echo $p->post_content;
}
echo '</ul>';
}
echo '</li></ul>';
?>
Or another approach maybe? Thank you.