Mixing Links Posts with Traditional Content

Maybe you want to mix this sort of linked title with your traditional content. You know, the kind of site where the post title leads to the actual post, and not elsewhere? Right, you're with me. Good.

So what you're looking at, then, is something of a linking aside. In fact, this is really easy to pull off. We'll just reuse the code and let the custom fields content check do all the work. Again, we'll use the index.php in the default WordPress theme as an example on how to pull this off:

<div <?php post_class() ?> id="post-<?php the_ID(); ?>"> <?php $CustomField = get_post_custom_values('URL'); if (isset($CustomField[0])) { ?> <div class="linkage">

<h2><a href="<?php echo get_post_meta($post->ID, URL, true); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <div class="entry">

<?php the_excerpt(); ?> </div> </div> <?php } else { ?>

<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_ title_attribute(); ?>"><?php the_title(); ?></a></h2>

<small><?php the_time('F jS, Y') ?> by <?php the_author() ?></small> <div class="entry">

<?php the_content('Read the rest of this entry &raquo;'); ?> </div>

<p class = "postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_ category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link ('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?></p> <?php } ?> </div>

There are some minor changes compared to the code used in the original example. That's because you want to actually output the posts with linked titles when there is no custom field value in 'URL', but when there is you do it the way you did before. Minus some categories and stuff, and with the div .linkage added to make it easier to style (although you can use the post_class() styles for most of it).

This code will make every post with content in the 'URL' custom field have a title linked to that URL, rather than the post itself. It is simple enough to add to any theme.

So, obviously you can make a links-driven site using WordPress. How about doing a gallery? Of course.

Authority Blog Success

Authority Blog Success

Blogs With an Authoritative Voice Attract a Loyal Audience. There are Lots of Rambling Blogs on the Web Today, but Blogging as an Authority on a Particular Subject is the Best Strategy for Generating a Perpetual Income. Blogging as an Expert on Your Subject is the Key to Blogging Success.

Get My Free Ebook

Post a comment