Support » Fixing WordPress » How to have a featured-article-image on the frontpage

  • Hi, im not a good with PHP so I hope you guys can help me.

    Here is my problem/question: I want to have a featured-article-image on the frontpage. Like the featured-article gallery plugin but this time with only one photo.

    Im now using

    <?php query_posts('showposts=1'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php $thumbnail = get_post_meta($post->ID, 'imgboard', true); ?>
        <li>
            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
            <img src="<?php echo $imgboard; ?>" alt="<?php the_title(); ?>" />
            </a>
        </li>
    <?php endwhile; endif; ?>

    But that doesnt work, the result is just a title of the latest post (because not all the article’s have the customfield ‘imgboard’ does somebody know how I can get this?

    so in short: I just want the image (customfield: imgboard) of the latest post on the frontpage

Viewing 8 replies - 1 through 8 (of 8 total)
  • Eh, sorry for bumping but the website has to work tomorrow morning 😛

    Why are you assigning get_post_meta to $thumbnail, but echoing $imgboard? Is that what you really intended?

    Oh, thats my mistake…

    was that the problem?

    I want wordpress to show the latest post with customfield ‘imgboard’and show that image on the index.php of my theme.

    Does the imgboard field contain just the name of the image file? If so, then you will need to create the full path to the image.

    Check the source code of your generated page to make sure the <img tag is generated properly.

    To put in the image on only those pages with the custom field, enclose your <li ... in <?php if ($thumbnail) ....

    It contains the full path.

    Its not working but someone told me this is a bit how I could make it:

    <?php query_posts('showposts=1'); ?>
        <?php setup_postdata($post); ?>
    
          <?  $querystr = "
        SELECT wposts.*
        FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
        WHERE wposts.ID = wpostmeta.post_id
        AND wpostmeta.meta_key = 'articleimg'
    	    AND wposts.post_type = 'page'
        ORDER BY wpostmeta.meta_value DESC
        ";
    
     $pageposts = $wpdb->get_results($querystr, OBJECT); ?>
    
    <?php query_posts('showposts=1'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php $articleimg = get_post_meta($post->ID, 'articleimg', true); ?>
            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
            <img src="<?php echo $articleimg; ?>" alt="<?php the_title(); ?>" />
            </a>
    
    <?php endwhile; endif; ?>

    somebody!?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to have a featured-article-image on the frontpage’ is closed to new replies.