How would I echo this...
<?php if ( store( 'for-sale' ) ) { ?>
<?php echo get_post_meta( $post->ID, 'album', true ); ?>
<?php echo get_the_term_list( $post->ID, 'label' ); ?>
...within the .post div in this function?
if ($favorite_post_ids):
foreach ($favorite_post_ids as $post_id) {
$p = get_post($post_id);
echo "<div class='post'>";
echo get_the_post_thumbnail( $post_id );
echo "</div>";
}
Thanks!
Kailey Lampert answers:
I'm not sure if I'm missing some context, but maybe this will help
if ($favorite_post_ids):
foreach ($favorite_post_ids as $post_id) {
$p = get_post($post_id);
echo "<div class='post'>";
echo get_the_post_thumbnail( $post_id );
if ( store( 'for-sale' ) ) {
echo get_post_meta( $post_id, 'album', true );
echo get_the_term_list( $post_id, 'label' );
}
echo "</div>";
}
Note, there is a missing closing tag based on the original code you provided. To close what I've posted, add endif;
at the end.
Jeremy Phillips comments:
Thanks for your answer. I totally forgot the closing tag, and I think that the previous code was a bit out of context. Here's the entire code, the endif as is doesn't work.
echo "<div class='wpfp-span'>";
if (!empty($user)):
if (!wpfp_is_user_favlist_public($user)):
echo "$user's Favorite Posts.";
else:
echo "$user's list is not public.";
endif;
endif;
if ($wpfp_before):
echo "<p>".$wpfp_before."</p>";
endif;
echo "<ul>";
if ($favorite_post_ids):
foreach ($favorite_post_ids as $post_id) {
$p = get_post($post_id);
echo "<div class='post'>";
echo "<a href='".get_permalink($post_id)."'>";
echo get_the_post_thumbnail( $post_id );
if ( store( 'for-sale' ) ) {
echo get_post_meta( $post_id, 'album', true );
echo get_the_term_list( $post_id, 'label', true );
}
endif;
echo "<br>";
echo "<a href='".get_permalink($post_id)."' title='". $p->post_title ."'>" . $p->post_title . "</a> ";
wpfp_remove_favorite_link($post_id);
echo "</div>";
}
else:
echo "<li>";
echo $wpfp_options['favorites_empty'];
echo "</li>";
endif;
echo "</ul>";
// wpfp_clear_list_link();
echo "</div>";
wpfp_cookie_warning();
Kailey Lampert comments:
Looks like you now have an extra closing tag! :)
Change this
if ( store( 'for-sale' ) ) {
echo get_post_meta( $post_id, 'album', true );
echo get_the_term_list( $post_id, 'label', true );
}
endif;
To this:
if ( store( 'for-sale' ) ) :
echo get_post_meta( $post_id, 'album', true );
echo get_the_term_list( $post_id, 'label', true );
endif;
That'll clean up the extra closing tag and make the conditional's code match the style of the rest
Jeremy Phillips comments:
Thanks, that did not produce an error, although the conditional didn't work. I replaced the tax conditional with a custom field conditional and it worked so I'm wondering if it has to do with the way the tax conditional is registered in my functions:
<?php if ( store( 'for-sale' ) ) { ?>
function store( $store, $_post = null ) {
if ( empty( $store ) )
return false;
if ( $_post )
$_post = get_post( $_post );
else
$_post =& $GLOBALS['post'];
if ( !$_post )
return false;
$r = is_object_in_term( $_post->ID, 'store', $store );
if ( is_wp_error( $r ) )
return false;
return $r;
}
And yes, this works perfectly in my templates.
Kailey Lampert comments:
Try passing the post ID to the store function
<?php if ( store( 'for-sale', $post_id ) ) { ?>
Jeremy Phillips comments:
Perfect! Thanks so much!
John Cotton answers:
What about
if ($favorite_post_ids) {
foreach ($favorite_post_ids as $post_id) {
$p = get_post($post_id);
echo "<div class='post'>";
echo get_the_post_thumbnail( $post_id );
if ( store( 'for-sale' ) ) {
echo get_post_meta( $post_id, 'album', true );
echo get_the_term_list( $post_id, 'label' );
}
echo "</div>";
}
}
Luis Abarca answers:
Try this one
<?php if ($favorite_post_ids): ?>
<?php foreach ($favorite_post_ids as $post_id) : ?>
<?php $p = get_post($post_id); // i think this is not necessary, you already know the post ID ?>
<div class="post">
<?php echo get_the_post_thumbnail( $post_id ) ?>
<?php if ( store( 'for-sale' ) ): ?>
<?php echo get_post_meta( $post_id, 'album', true ) ?>
<?php echo get_the_term_list( $post_id, 'label' ) ?>
<?php endif ?>
</div>
<?php endforeach ?>
<?php endif ?>