to continue…
this the html that I want to turn into a loop:
<div class="post-cat-tabs">
<em class="cat-tab horror-tab" title="Horror"><span>Horror</span></em>
<em class="cat-tab scifi-tab" title="scifi"><span>scifi</span></em>
</div>
so for each cat-tab class there is a loop
Cheers again
could you post the php from index.php(?) that makes the html that displays the tab?
a possible way to get all category names from the post could be:
<?php $cats = wp_get_post_categories($post->ID); foreach($cats as $cat) { echo get_cat_name( $cat ).'<br />'; } ; ?>
this snippet above will simply echo a list of the category names (no links, no formatting,..)
the next, probably more complicated step, is to turn this into absolute positioned divs, which increase position with every category.
to even begin to develop this, the original php code is essential.
here is the part of the index.php that display the category at the moment:
<em class="cat-tab <?php the_category_unlinked(''); ?>-tab" title="
<?php the_category_unlinked(''); ?>"><span><?php the_category_unlinked(''); ?></span></em>
The css part is sorted. It’s just writing out the loop that’s the issue
Cheers for the help
is it something like this I should be creating:
<?php $cats = wp_get_post_categories($post->ID); foreach($cats as $cat) { ?>
<em class="cat-tab <?php echo get_cat_name( $cat ). ?>-tab" title="<?php echo get_cat_name( $cat ). ?>"><span><?php echo get_cat_name( $cat ). ?></span></em>
<?php } ?>
An alternative, the suggestion above should also be fine, and i don’t wish to cut into someone elses help…
// Get categories for post
$categories = get_the_terms( $post->ID , 'category' );
// Create empty string
$cat_string = '';
// If categories
if( $categories ) {
// Foreach of the array items returned
foreach( $categories as $key => $cat_obj ) {
// Append the string with category stuff for each result
$cat_string .= '<em class="cat-tab ' . $cat_obj->slug . '-tab" title="' . $cat_obj->name . '"><span>' . $cat_obj->name . '</span></em>';
}
}
// Echo the string, it's just an empty string if no data was found (so no errors)
echo $cat_string;
Thank you all so much for your help everyone. It’s working like a dream.
Cheers again.