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.

Was this article helpful?

0 0
Blogging From The Beginning

Blogging From The Beginning

The Blogging From The Beginning course was specifically designed with these people in mind. It starts at the very beginning, by helping them choose the right platform and takes them all the way though creating content, getting traffic and making money from their blog. It is simple, straight forward information that will help them even if they've never heard of blogging before. It will teach them how to get started and quickly harness the power of blogging for themselves.

Get My Free Ebook

Post a comment