Custom Fields on the Homepage
-
So I have a custom field on my posts called “Link” Using this, on my post page, I’m checking to see if the field has a value. If it does, I’d like to switch out the title link with the “Link” value, much the same way Daring Fireball does for Linked List items.
I have the code working on my post page, with some code in my theme’s functions.php, I have it working for RSS feeds.
I did this using this tutorial: http://johanbrook.com/development/wordpress/linked-list-style-posts-in-wordpress/
However, I can’t seem to get it to work on the homepage.
This code works fine, as it’s basically the standard loop:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <h2 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <p class="dateline"><em><?php the_time('l, F jS, Y'); ?></em></p> <p><?php the_content('Read More'); ?> <hr> <?php endwhile; else: ?> <p><?php _e('Sorry, there are no posts.'); ?></p> <?php endif; ?>
However, I’m trying to use the following code:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php $meta_link = get_post_meta(get_the_ID(), “Link”, true); ?> <?php if($meta_link):?> <h2 class=title><a title="follow link" href="<?php echo $meta_link;?>"><?php the_title();?></a> →</h2> <p class="dateline"><em><?php the_time('l, F jS, Y'); ?></em></p> <p><?php the_content(‘Read More’); ?></p> <br /> <p><a href="<?php the_permalink(); ?>">↵</a></p> <?php else: ?> <h2 class=title><?php the_title(); ?></h2> <p class="dateline"><em><?php the_time('l, F jS, Y'); ?></em></p> <p><?php the_content(‘Read More’); ?></p> <br /> <?php endif; ?> <?php endwhile; else: ?> <p>Sorry, no posts matched your criteria.</p> <?php endif; ?>
When I do, my homepage is entirely blank — even though very similar code is working on my posts pages.
Any ideas as to how I can get this working?
- The topic ‘Custom Fields on the Homepage’ is closed to new replies.