Displaying content from a category using custom fields
-
I hope I can explain this well.
Typical layout 80% of the screen has the post (single.php) and the other 20% to the right has content of the same post. I have 4 different types of post categories (latest, back issues, current issues, podcasts) and they are all being served up correctly using a conditional statement in single.php that redirects the user to the appropriate version of single.php (1, 2, or 3).
In the 80% section I have the following
<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); $do_not_duplicate = $post->ID; $illustration_variable = get_post_meta($post->ID, 'illustration', true);?> <div class="day-issue-container-single"> <img src="<?php echo $illustration_variable; ?>" width="630" height="276" alt="<?php the_title(); ?>" /> <div class="grey-trans-box flash-fiction-single-title-trans-box"> <h2 class="flash-fiction-feature"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>" ><?php the_title(); ?></a></h3> <p class="flesh"><?php the_author_firstname() ?> <?php the_author_lastname() ?></p> </div> </div> <div style="width:624px;height:auto;background-color:#ececec;padding-left:6px;"> <?php the_content(); ?>Now in the 20% section I want a list of all the posts of the same category as the post in the 80% region. (there will be 10 at most)
You will see in the snippet below that I am calling the value of a custom field outside of the loop and am thinking that might be my problem.
<?php query_posts('meta_key=issue&meta_value=the-sea-issue'); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); $do_not_duplicate = $post->ID; $illustration_variable = get_post_meta($post->ID, 'illustration', true);?> <?php echo $post->post_name ?> <div class="single-page-sidebar-content"> <img class="current-issue-cover float-left" src="<?php echo $illustration_variable; ?>" width="60" height="45" alt="<?php the_title(); ?>" /> <h3 class="flash-fiction-header"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>" ><?php the_title(); ?></a></h3> <p class="author-name"><?php the_author_firstname() ?> <?php the_author_lastname() ?></p> <p class="break"><?php the_excerpt(); ?></p> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>" ><p>continue reading</p></a><p class="date-right"><strong><?php the_time('F j Y') ?></strong></p> </div>To try and shed some light on what i am doing here the structure of the posts are as follows; There is an issue and within that issue there are stories.
So we have The Sea Issue and with in The Sea Issue there are say 3 stories.
The post for The Sea Issue has two categories The Sea Issue and Back issues
The stories with in the sea issue also have two categories The Sea Issue and Back Issue Stories.
The story post also has a custom field called Issue with the value of the-sea-issue. This is the same value as the category (The Sea Issue) slug
So for this particular functionality user visits the Back Issues page and selects The Sea Issue. The user is presented with a splash page with text about The Sea Issue and all the titles of the stories in the issue and links to the stories. The user clicks on a story and is directed to this 80% / 20% page that im writing about here.
The 80% section has the story and the 20% has the links to the other stories in that issue. When hard coding this meta_key=issue&meta_value=the-sea-issue the content displays as intended, but since there are many back issue this would need to be dynamic.
My idea was to create the “issue” custom field and give it the same value as the slug of category of the post (The Sea Issue …the-sea-issue). needless to say my execution didn’t work.
If anyone out there has been able to understand my gibberish a second set of eyes would be great. As you can probably tell i am new to this so my logic might be off.
Thanks
The topic ‘Displaying content from a category using custom fields’ is closed to new replies.