Forums

[resolved] IF custom field exists - display div (12 posts)

  1. ccmovies
    Member
    Posted 1 year ago #

    Hello,
    I have a custom field that displays a youtube video. In the value of the field, I am just entering part of the url. I want it so that if the key "yt-vid" exists, then it will display or include (using php) a div that has the youtube video with an old-style TV as the background. I already know how to display the youtube video in front of the TV however for some reason I cannot figure out how to show to custom field if it exists. This is my first wordpress theme I am making and I am intermediate when it comes to php, HMTL, css, etc.

    Thanks,
    Connor

  2. ccmovies
    Member
    Posted 1 year ago #

    By the way, I am doing this on my local server so I cannot share a url with anyone. And I reply fast.

  3. alchymyth
    The Sweeper
    Posted 1 year ago #

    general:

    <?php if( get_post_meta($post->ID, 'yt-vid', true) ) { ?>
    
    <!-- htmlcode to show the div and the video -->
    
    <?php } ?>

    if you need to switch between html and php in that code, make sure to close and open the php tags and html tags in proper order.

  4. ccmovies
    Member
    Posted 1 year ago #

    Okay, will try it, thanks!

  5. ccmovies
    Member
    Posted 1 year ago #

    Yeah it worked! Thanks so much, that helps me a lot!

  6. ccmovies
    Member
    Posted 1 year ago #

    Now how can I make it so if it is a certain category, such as Tutorials, that it displays tutorial information that I enter with custom fields?

    Thanks!

  7. alchymyth
    The Sweeper
    Posted 1 year ago #

  8. ccmovies
    Member
    Posted 1 year ago #

    Okay, thanks! I will try it out.

  9. ccmovies
    Member
    Posted 1 year ago #

    For some reason it is not working:

    
    <?php if ( in_category( array( 'tutorials', 'photoshop', 'illustrator', 'dvd studio pro', 'final cut pro', 'motion', 'after effects' ) )) {
    <? include('tutorials.php') ?>
    }
    ?>
  10. ccmovies
    Member
    Posted 1 year ago #

    All it shows is a blank page

  11. alchymyth
    The Sweeper
    Posted 1 year ago #

    no error messages?

    what if you put any echo 'test'; code instead of the include(..)?

    what if you try include(TEMPLATEPATH .'/tutorials.php');

    http://codex.wordpress.org/Include_Tags#Including_Any_Template

    also check if php short tags <? are working on your server.

  12. ccmovies
    Member
    Posted 1 year ago #

    I decided to go with something else:

    <?php if (in_category('tutorials')) : ?>
    <div id="tutorials">
    <h4>Tutorial Information</h4>
    <ul>
    <li><strong>You Will Need:</strong> <?php echo get_post_meta($post->ID, 'tut_you-will-need', true); ?></li>
    <li><strong>Optional:</strong> <?php echo get_post_meta($post->ID, 'tut_optional', true); ?></li>
    <li><strong>Difficulty:</strong> <?php echo get_post_meta($post->ID, 'tut_difficulty', true); ?></li>
    <li><strong>Est. Length of Time:</strong> <?php echo get_post_meta($post->ID, 'tut_time', true); ?></li>
    </ul>
    
    </div>
    <?php endif; ?>

    Thank you so much for the help!

Topic Closed

This topic has been closed to new replies.

About this Topic