<h2 class="post-title"><a href="<?php echo get_permalink($item->ID); ?> "> <?php echo get_the_title($item->ID); ?> </a></h2> <div class="post-meta"> <span class="author"><?php echo get_the_author_meta('display_name', $item->post_author); ?> </span> <span class="date"><?php echo get_the_date("d/m/Y", $item->ID); ?> </span> </div> <div class="post-description"><?php echo get_post_excerpt_by_id($item->ID, 20, get_permalink($item->ID)); ?> </div> </li> <?php } ?> </ul> <?php }
<?php global $post; $currentPostID = $post->ID; if (is_page()) { $cat = get_field('categories'); } else { $cat = get_the_category($currentPostID); } $args = array('numberposts' => 3, 'category' => $cat[0]->term_id, 'post_status' => 'publish'); $recent_posts = wp_get_recent_posts($args); ?> <section class="l-box widget widget-related-news"> <h1 class="widget-title"><?php echo $title; ?> </h1> <?php foreach ($recent_posts as $recent) { echo '<a href="' . get_permalink($recent["ID"]) . '" class="widget-title-link"><h2>' . $recent["post_title"] . '</h2></a>'; echo '<div class="widget-snippet">' . get_post_excerpt_by_id($recent["ID"]) . '</div>'; } ?> </section>