WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Random Custom Field in sidebar (4 posts)

  1. Saijo George
    Member
    Posted 4 years ago #

    Hi guys

    I use custom field to post an image thumbnail for each and every post. I use the key " Thumbnail "

    I was wondering if there is any way I can show say random posts in the sidebar. But instead of the text links I want the Custom Field Thumbnails to be shown which links to the post url.

  2. gerbilk
    Member
    Posted 4 years ago #

    Something like this

    <?php
        $recentPosts = new WP_Query();
        $recentPosts->query('showposts=1&orderby=rand');
        while ($recentPosts->have_posts()) : $recentPosts->the_post();
    ?>
    <!-- custom field here-->
    <a href="<?php the_permalink() ?>"><?php $key="Thumbnail"; echo get_post_meta($post->ID, $key, true); ?></a>
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
  3. Saijo George
    Member
    Posted 4 years ago #

    thanks..

  4. Saijo George
    Member
    Posted 4 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.