Assuming you have one post with only one category assigned, you can edit the single post page (post.php or single.php depending on your theme) to add an HTML ID to the main class. You will have to use the get_the_category() function. Your PHP code will look something like this:
<article id="category-
<?php
$category = get_the_category();
if ( ! empty( $categories ) ) {
echo esc_html( $categories[0]->name );
}
else { echo "default"; }
?>"
class="single-post">
........
.....
</article>
this will create a dynamic id for a post with the category name. Suppose a post has a category “Horror” then the HTML ID for the main div will be “category-horror”. You can use this id in your CSS to add different styles to this on other HTML elements inside this. Something like this:
#category-horror .single-post {
margin-top: 10%; }
Hope this helps.
Related Posts:
- Create custom page templates with plugins?
- Is there a WordPress plugin that registers a plugin file as a custom page template?
- Is it possible to stop selected plugins from loading on certain template pages?
- Ways to have multiple front-page.php templates that can be swapped out?
- Add Archive Page Template via Plugin
- Why am I sometimes getting a 404 error when I try to update a page with Elementor?
- Template plugin for blog posts? [closed]
- Is it possible to upload a template file to a directory that can be used by all themes?
- Adding a post shortcode to a page template?
- Is there any way to get all the name or slug of template parts used in a page?
- Calling custom plugin class methods from a template
- Create a custom page template inside my wordpress plugin
- New to wordpress: would like to have pluggable main page sections [closed]
- Register Page Template from Plugin
- Plugin-generated pages use Not Found or Pages Archive templates?
- How to use get_template part in the plugin?
- Show author on every sub-page
- URLs Added to ACF Repeater Field are not working
- Create custom template in plugin and display it into post template section?
- Trying to add a page template for my custom post type from a plugin, but it will not display in the template dropdown unless file is in theme
- the_content() printing DOCTYPE, and tags in the middle of page
- How do I create a custom permalink structure for a page template
- Plugin create pages and use templates
- Custom form not showing in correct place on page
- Ajax Call in page theme not working?
- How do I show content from a plugin using the template the site is currently working with?
- How can recognize post’s category?
- How to dynamically change spots of text in custom page?
- Pull comments from one page/post into another page/post?
- Add custom PHP and HTML to the_content()
- How to modify the Loop from a plugin (instead of a theme)
- How to makes changes on the shop/category/tag pages but not on the product pages in woocommerce?
- Give custom page template a custom post ID
- WordPress Product Detail and catalog
- how do i fixe Page Builder on a custom page?
- Plugin json page
- How to use custom footer template in a site-plugin?
- Passing variable from template file to the plugin file
- Custom Page Templates for a complex application – code must sit in a plugin and not the Theme
- Sort Reviews/Ratings by date on Woocommerce
- How to create a page template using custom plugin
- Resources for building a custom event page template
- How to provide page_template path in custom plugin using WordPress
- How to use classes declared in another plugin?
- Hooking in to plugins
- How can I allow moderated anonymous contributors to post to my blog?
- How to only hook on Single.php after content?
- Finding WordPress sites using my plugins
- WordPress 4.0 Cookie Authentication to avoid nonce error when publishing a post and page
- Shortcode under a Shortcode Multiple times Possible?
- How can I include PHP-Code to my post?
- Seriously stuck with some custom meta box/plugin stuff
- How to Build a Movie Library in WordPress 3.x
- Intercept comment form submit/list by hook/filter
- How many security plugins are too many? [closed]
- Creating WordPress Plugin solely for Admin panel with dash menu and submenus
- Creating an Exit Confirmation Popup
- How to prevent action in ajax request, when in admin side?
- Can I delete plugin files using FTP?
- Reposition Woocommerce Message
- Get all categories of custom post even not assigned
- Plugin not appearing after uploading it via FTP
- Prevent duplicate records in plugin table
- Theme is Causing Ajax Conflicts for a plugin I cant identify it
- CSV syntax for WP All Import upload without ACF
- Error: Cannot find module ‘../build/Debug/nodegit.node’ [closed]
- Uncaught TypeError: jQuery(…).flipster is not a function in wordpress
- Get Time Taken By Each Action Hook in WordPress
- Buidling a translate plugin for wordpress
- Display wordpress post’s in popup?
- Save values from a pre_post_update
- How do I use add_action on custom widget?
- plugin active error
- (WordPress 5.8.3) Function.php or a plugin for better performance? [duplicate]
- Control page content visibility based on URL parameter
- WooCommerce Shopping Cart Not Initially Showing Products [closed]
- Elementor Custom Control: How to get input value?
- Creating a search form and displaying results
- should i use GLOB_ONLYDIR to hook add-ons for wordpress plugin
- How to downgrade plugin?
- Build a must-use plugin that tracks when other plugins are activated or deactivated
- Using sessions or an alternative in a plugin
- redirect to homepage once action is completed
- taxonomy_template filter not working on pagination [duplicate]
- How connect my plugin translation to my page
- Pagination not working with pagenavi
- multiple string replace of post’s content for large data
- Using WordPress to create a simple web app (SaaS) [closed]
- WordPress SSO SAML
- Attachments plugin cannot click media library button [closed]
- Is there any hook to change media html in post? [duplicate]
- plugins_loaded action is not working properly
- Creating a user ‘add custom field’ section
- WordPress Settings – Custom Button actions
- Links on FAQ page aren’t working
- How can I make the Twitter Tools plugin hyperlink every link?
- wp insert post not working
- WordPress shortcode plugin not working
- WordPress error Fatal error: Uncaught TypeError: Argument 3 passed to Automattic :get_setting_for_feature() [closed]
- Form with response button after on table after submission