0

I'm trying to modify the 'display random posts' plugin. In the following code I would like the output display to show list of posts with the featured image and the title of the post below it. Currently this code displays only the featured image in front end. How do I add the post title below the image?

$string .= '<ul>';
while ( $the_query->have_posts() ) {
    $the_query->the_post();
    $string .= '<li><a href="'. get_permalink() .'">'. get_the_post_thumbnail() .'</a></li>';
}
$string .= '</ul>';

1 Answer 1

0

Personally I would not modify the plugin, as you'll just lose all your changes on each and every update.

But if you insist, just change line 4 to

$string .= '<li><a href="'. get_permalink() .'">'. get_the_post_thumbnail() .'</a><h6>'. get_the_title() .'</h6></li>';

Then you can target those h6s with CSS

1
  • Thank you. Yes, I'm not modifying the original plugin, instead I have created my own custom plugin using the original code.
    – Nish B
    Commented Feb 10, 2018 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.