Forums

[resolved] Custom fields with if+else conditionals (4 posts)

  1. fortkentgent
    Member
    Posted 1 year ago #

    Hopefully somebody can assist me because I'm having no luck. I'm not an experienced coder but I'd really like to accomplish this. I want to link the title of my posts to external sources and I hope to use a conditional+custom field to do this. The custom field key is titled "source" and the value will be a url. So id like to say..

    IF source (the key of my custom field)
    
    url (the value of my custom field)
    
    ELSE
    
    <?php the_permalink() ?>

    Could somebody please give me some help?

  2. fortkentgent
    Member
    Posted 1 year ago #

    Sorry to bump but I can't figure this out. This is what I have but I get errors and I'm basically clueless.

    `<?php if (get_post_meta($post->ID, 'source', true) ) {
    <h1>ID, "source", $single = true); ?>" rel="external" title="External Link to <?php the_title(); ?>"><?php the_title(); ?></h1>
    } else {
    <h1>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></h1>
    }
    ?>`

  3. fortkentgent
    Member
    Posted 1 year ago #

    I got it.

    <?php if (get_post_meta($post->ID, 'source', true) ) { ?>
    				<h1><a href="<?php echo get_post_meta($post->ID, "source", $single = true); ?>" rel="external" title="External Link to <?php the_title(); ?>"><?php the_title(); ?></a></h1>
    				<?php } else { ?>
                    <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h1>
    				<?php } ?>
  4. subiectiv
    Member
    Posted 10 months ago #

    thanks man, i tried almost five days to make that thing work. of course, in some other circumstances, but it worked. you rule :)

Topic Closed

This topic has been closed to new replies.

About this Topic