1

I'm using the Canvas theme, and their framework.

I built a child theme and have my custom CSS segregated in a custom.css file in that directory. I've made some changes to one specific page layout file (loop-magazine.php) to pull posts from a specific category (id=7) from my database.

I've asked Woothemes the following CSS question with no luck with their paid support. Let's see if any smarties here can make this happen!

I want to hide the post metadata (author, date, comments, etc) on a specific category (id=7), such that the metadata never displays when those posts are viewed, either in excerpt mode or full-mode.

If hiding this data on a category basis isn't possible, I'd settle for hiding the meta data anytime this page template (magazine) is used.

My preference is to hide it per the category so that I never worry about that meta data displaying, but I can live with the page approach.

Though I don't know if that will help much.

Anybody out there used CSS to hide metadata by category?

1

Posting the answer that was solved by OP in one of the comments. This way it's easier to read it. Hopefully a moderator can mark the question as solved.

.page-template-template-magazine-php .post-meta, .category-services .post-meta {
    display:none;
}
0

Assuming that you category is 'services" then;

.category-services .post-meta {
    display:none;
}

Or if using LESS

.category-services {
     .post-meta {
         display:none;
     }
 }

Each category is appended to the class structure of so if category is called 'dog" it is appended as category-dog.

In your case it is

<article class="post-100 post type-post status-publish format-standard hentry category-services">
  • Thanks very much for the reply! Unfortunately it didn't work- I added this code to my custom.css file, and it didn't hide the post-meta. I also tried the LESS version, it didn't work either. I've since removed each/both, and will keep experimenting. Does Wordpress only allow references to slug names, rather than to category ID? Seems silly when you might choose to change the slug down the road. Wouldn't ID be a better controller? – ElliottRand Jul 16 '13 at 16:59
  • Something is not right - it works for me? I would check Chrome or Firefox inspector to see that your CSS has compiled or uploaded. In answer to your second question,yes the alternative would be to create a function not CSS. See codex.wordpress.org/Function_Reference/delete_post_meta – user1352792 Jul 17 '13 at 1:18
  • Solved this today with an expert Wordpress theme friend's help. I used: .page-template-template-magazine-php .post-meta, .category-services .post-meta, { display:none; } which addressed both the magazine template AND the individual post when displayed as a full link. I'm not sure why your code didn't work, but I did purge my cache to be sure the code was loading, and got nuthin. Thanks for the effort though! – ElliottRand Jul 17 '13 at 21:57
0

You could also add in your category template file a code similar to this one:

<?php if(is_category('category-slug-here') { ?>
    // display your HTML meta here
<?php } ?>

You would probably need to check for subcategories, but this should get you started if you want to take the PHP approach.

0
$category = get_the_category(); 

if ( $category[0]->cat_name == "featured" ) {

    // if first category in array is "featured", get next category in line

     $name = $category[1]->cat_name;
     $cat_id = get_cat_ID( $name );
     $link = get_category_link( $cat_id );
     echo '<a href="'. esc_url( $link ) .'"">'. $name .'</a>';

} else {

    // get the first category

     $name = $category[0]->cat_name;
     $cat_id = get_cat_ID( $name );
     $link = get_category_link( $cat_id );
     echo '<a href="'. esc_url( $link ) .'"">'. $name .'</a>';

}
  • 2
    Welcome to the WordPress Stack Exchange! It may be helpful to future readers if you edit the question ( using the edit link directly underneath your answer ) and add an explanation to how your code works and why it solves this particular problem. – Howdy_McGee Jan 19 '16 at 18:17

protected by Community May 9 '16 at 9:23

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.