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
Cash For Blogging

Cash For Blogging

There are sites that will pay you upfront, pay you a percentage of the revenue that your content makes, and sites that will hire you to write or blog for them. You can start earning money per article or blog post in as little as a few days with some of these sites.

Get My Free Ebook

Post a comment