- This topic has 7 replies, 5 voices, and was last updated 3 years, 11 months ago by David.
-
AuthorPosts
-
October 21, 2015 at 9:00 am #146258Antonio
Hi
is it possible to show/hide post elements per category?
For example, into News category I want to show the date and the category, not the author. In Products category instead I want to not show the author neither the date but the category yes.October 21, 2015 at 12:53 pm #146325bdbrownHi Antonio. Are you wanting to hide the post elements on the category archive page, or on the single post page?
October 21, 2015 at 11:26 pm #146412AntonioOn both, if possibile.
October 22, 2015 at 1:21 pm #146595bdbrownFor single posts we need to add the category name to the page. Add this function to a child theme functions.php file:
/* add post category class to body tag */ add_filter('body_class','add_category_to_single'); function add_category_to_single($classes, $class) { if (is_single() ) { global $post; foreach((get_the_category($post->ID)) as $category) { // add category slug to the $classes array $classes[] = $category->category_nicename; } } // return the $classes array return $classes; }
Adding PHP Functions: https://generatepress.com/knowledgebase/adding-php-functions/
The individual post element classes are:
.entry-header .entry-meta = date and author
.entry-meta .posted-on = date
.entry-meta .byline = author
.entry-meta .cat-links = categoriesThen add the appropriate CSS based on the category class.
For single posts in your News category it would be:
/* hide author on News single post */ .single .news .entry-meta .byline { display: none; }
For your Products cateogry:
/* hide date and author on Products single post */ .single .products .entry-header .entry-meta { display: none; }
Adding CSS: https://generatepress.com/knowledgebase/adding-css/
For the category archive page the category name is already in the <body> element in the form of “category-slugname” where slugname is the slug of the category. So you would use this:
/* hide post author on News archive page */ .archive .category-news .entry-meta .byline { display: none; } /* hide post date and author on Products archive page */ .archive .category-products .entry-header .entry-meta { display: none; }
Let me know how that works.
September 22, 2016 at 7:42 am #228642JanHi there,
I would also like to hide the author and date on single posts or post categories.
I tried the code above and got the following error:
Warning: Missing argument 2 for add_category_to_single() in /home/eersdiek/public_html/wp-content/themes/generatepress_child/functions.php on line 10
class=”single single-post postid-1921 single-format-aside logged-in admin-bar no-customize-support fl-builder post-image-below-header post-image-aligned-center secondary-nav-above-header secondary-nav-aligned-right sections-no-sidebars sticky-menu-no-transition navigation-logo sticky-enabled menu-logo menu-logo-enabled has-dashicons leiding-elke-dag generatepress full-width-content no-sidebar nav-below-header fluid-header separate-containers active-footer-widgets-0 nav-aligned-left header-aligned-center dropdown-hover”>Is there an easier way of doing this?
Regards,
JanSeptember 22, 2016 at 9:07 am #228651JanHi there,
Please Ignore above or delete it. I found another way in:
https://generatepress.com/forums/topic/move-author-date-to-the-bottom-after-content/
Jan
May 3, 2020 at 2:23 am #1267105FazzHi – is there a way to unhide an entry element (like post date) that was previously CSS display:none?
May 3, 2020 at 6:24 am #1267329DavidStaffCustomer SupportHi there,
this is a really old topic – could you start a new topic where you can privately share a link to your site and we can provide some help.
-
AuthorPosts
- You must be logged in to reply to this topic.