2021-01-02, 11:42:11
(2015-04-22, 07:47:31)morvy Wrote: thanks for pointing me to right direction, if anybody needs similar posts by tag, here's my code
Code:$num_post = 5;
$slugs = array();
$url = nm_get_url('post');
$posts = nm_get_tags();
foreach($posts as $tag => $post) {
if(nm_post_has_tag($tag)) {
foreach ($post as $slug) {
$slugs[] = (string)$slug;
}
}
}
$slugs = array_unique($slugs);
if(($key = array_search(nm_post_slug(false), $slugs)) !== false) {
unset($slugs[$key]);
}
shuffle($slugs);
$slugs = array_slice($slugs, 0, $num_post);
$all = nm_get_posts();
echo '<ul class="nm_similar_post">';
foreach ($all as $post) {
if(in_array($post->slug, $slugs)) {
echo '<li><a href="'.$url.$post->slug.'" title="'.$post->title.'">'.$post->title.'</a></li>', PHP_EOL;
}
}
echo '</ul>';
I was wondering if there is a way to also implement the image with the post on this code...
I tried to modify it, but I only got the clickable image path underneath the title.
Thank you!