Hi, I've searched everywhere and can't find an exact answer for what I'm trying to do.
I have given my posts a set of custom fields, for instance: project_type = magazine. These fields are then displayed in the post on my site. I'd like to be able to turn that field value in each post into a link that, when clicked, would take the user to listing of all posts of that project type. The same way that clicking a tag or category would take you to all posts with that tag or category. I just can't figure out how to accomplish this, though.
Here's the code from single.php:
<?php get_header(); ?>
<div id="content">
<?php if (have_posts()) : ?>
<?php the_post(); ?>
<div class="post">
<?php skimmed_milk_post_title('h2'); ?>
<div class="entry">
<?php skimmed_milk_post_entry(); ?>
</div><!-- entry -->
<div class="metadata">
<div class="top"></div>
<div class="navigation">
<div class="alignleft"><?php next_post_link('« %link', 'Previous', TRUE); ?></div>
<div class="alignright"><?php previous_post_link('%link »', 'Next', TRUE); ?></div>
<div class="snap-to-fit"></div>
</div><!-- navigation -->
<p class="postmetadata alt ">
<?php
$dateString = __('F jS, Y', 'skimmed');
printf(__('Posted in %1$s on %2$s', 'skimmed'),
get_the_category_list(', '),
apply_filters('the_time', get_the_time($dateString), $dateString),
apply_filters('the_time', get_the_time(''), ''));
the_tags('<br />' . __('Tagged with ', 'skimmed'), ', ', ' ');
?>
<br />Project Type: <?php if ( function_exists('get_custom_field_value') ){ get_custom_field_value('project_type', true); } ?>
<br />Client: <?php if ( function_exists('get_custom_field_value') ){ get_custom_field_value('client', true); } ?>
<br />Description: <?php if ( function_exists('get_custom_field_value') ){ get_custom_field_value('description', true); } ?>
</p>
<div class="bottom"></div>
</div>
</div><!-- post -->
<?php comments_template();
else : // no posts
skimmed_milk_something_not_found(__('Post not found', 'skimmed'));
endif; // end if have posts ?>
</div><!-- content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
And the archive.php:
<?php get_header(); ?>
<div id="content">
<?php if (have_posts()) :
if (is_category()) $archive_display_name = single_cat_title('', false);
elseif (is_tag()) $archive_display_name = single_tag_title('', false);
elseif (is_day()) $archive_display_name = get_the_time(__('F jS, Y', 'skimmed'));
elseif (is_month()) $archive_display_name = get_the_time(__('F Y', 'skimmed'));
elseif (is_year()) $archive_display_name = get_the_time(__('Y', 'skimmed'));
?>
<?php if (is_category()) : ?>
<h2 class="pagetitle"><span class="darkorange">/</span><span class="lightorange">/</span> <?php printf(__('%s', 'skimmed'), $archive_display_name); ?></h2>
<?php elseif (is_tag()) : ?>
<h2 class="pagetitle"><?php printf(__('Posts tagged with %s', 'skimmed'), $archive_display_name); ?></h2>
<?php else : ?>
<h2 class="pagetitle"><?php printf(__('%s Archive', 'skimmed'), $archive_display_name); ?></h2>
<?php endif;
skimmed_milk_nav_link(sprintf(__('Later %s posts', 'skimmed'), $archive_display_name), '');
while (have_posts()) : the_post();
global $page; $page = 1; ?>
<div class="thumb">
<div class="thumb_excerpt">
<?php the_excerpt('<span class="nowrap">' . __('Read more', 'skimmed') . ' »</span>'); ?>
</div><!-- entry -->
<div class="thumb_title">
<?php if ( get_post_meta($post->ID, 'project_type', true) ) { ?>
<h3><a href="<?php echo get_permalink(); ?>" rel="bookmark" title="<?php printf(__("Permanent link to '%s'", 'skimmed'), the_title_attribute(array('echo' => false))); ?>"><?php echo get_post_meta($post->ID, "project_type", $single = true); ?><?php } ?></a></h3>
<?php if( ! is_year()) : // don't show content if is full year archive ?>
</div>
<?php endif; ?>
<!-- <?php trackback_rdf(); ?> -->
</div> <!-- post -->
<?php endwhile;
skimmed_milk_nav_link('', sprintf(__('Earlier %s posts', 'skimmed'), $archive_display_name));
else : // no posts
skimmed_milk_something_not_found(__('Archive not found', 'skimmed'));
endif; // end if have posts ?>
</div><!-- content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
I've reached the limits of abilities with this one. If anyone could point me in the direction of how to accomplish this, I would really appreciate it. I'm very new at this, so if there's any information I've left out, please let me know!
Thanks.