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>';
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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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