WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] thumbnails if, if not help (10 posts)

  1. skallerup
    Member
    Posted 1 year ago #

    I'm looking for a way to get this code to show thumbnails IF they page is called page1, page2 and so on:

    <?php if(has_post_thumbnail()) { ?>
    <?php the_post_thumbnail('homeblog'); ?>
    <?php } ?>

    How can i write that?

  2. esmi
    Forum Moderator
    Posted 1 year ago #

  3. skallerup
    Member
    Posted 1 year ago #

    is_single( array( 'beef-stew', 'pea-soup', 'chili' ) )
    i guys this is the code?

    I'm really not good at php, but is it like this then:

    <?php if(has_post_thumbnail(is_single( array( 'beef-stew', 'pea-soup', 'chili' ) ) )) { ?>
    <?php the_post_thumbnail('homeblog'); ?>
    <?php } ?>

    ??

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum's parser.]

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    That code would only show post thumbnails on single posts with the slugs beef-stew' or pea-soup, yes.

  5. skallerup
    Member
    Posted 1 year ago #

    I have a page named "contact" so the could so be:

    <?php if(has_post_thumbnail(is_single( array( 'contact' ) ) )) { ?>
    <?php the_post_thumbnail('homeblog'); ?>
    <?php } ?>

    But it's not working :/

    [No bumping. If it's that urgent, consider hiring someone.]

  6. esmi
    Forum Moderator
    Posted 1 year ago #

    Try:

    <?php if( is_single( 'contact') && has_post_thumbnail() ) the_post_thumbnail('homeblog');?>

  7. skallerup
    Member
    Posted 1 year ago #

    It does not seem to work :(

    The code is placed in top_info.php, can that have anything to say?

    what should I put instead of homeblog?

    Thank you very much for your help!

  8. esmi
    Forum Moderator
    Posted 1 year ago #

    can that have anything to say

    Possibly. What theme are you using?

  9. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    have a page named "contact"

    for pages, use is_page()

    http://codex.wordpress.org/Function_Reference/is_page

  10. skallerup
    Member
    Posted 1 year ago #

    Thank you both so much!!!

    The code is working:

    <?php if( is_page('contact') && has_post_thumbnail() ) the_post_thumbnail('somethingrandomiguess');?>

Topic Closed

This topic has been closed to new replies.

About this Topic