WordPress.org

Ready to get started?Download WordPress

Forums

How to have a featured-article-image on the frontpage (9 posts)

  1. denware
    Member
    Posted 5 years ago #

    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

  2. denware
    Member
    Posted 5 years ago #

    Eh, sorry for bumping but the website has to work tomorrow morning :P

  3. kymac
    Member
    Posted 5 years ago #

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

  4. denware
    Member
    Posted 5 years ago #

    Oh, thats my mistake...

  5. selfmade64856
    Member
    Posted 5 years ago #

    was that the problem?

  6. denware
    Member
    Posted 5 years ago #

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

  7. kymac
    Member
    Posted 5 years ago #

    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) ....

  8. denware
    Member
    Posted 5 years ago #

    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; ?>
  9. denware
    Member
    Posted 5 years ago #

    somebody!?

Topic Closed

This topic has been closed to new replies.

About this Topic