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
- Page not found when I click anything on my website
- How to customize a title by passing query string?
- How to create wordpress widget that is fixed position on the home page
- How do I rename a category in the menu bar only?
- Remove Advanced Custom Fields plugin for client?
- How to reset the plugins without deactivate the plugin
- plugins_url() works everywhere but wp_reqister_script()
- Better WP Security : dashboard doesn’t work any more
- Too many login attempts
- How to check if an email was sent from or originated from a specific plugin?
- Wooslider custom css
- Software to run on server checking outdated wordpress installations
- Where is this strange og:description coming from?
- Using Variable in WordPress Translate Functions
- How to change the wp_upload_dir() path in plugin
- how to connect the author profile with google webmaster tools in multiuser blog?
- Plugin getting Cannot modify header information errors
- Remove timthumb.php from my custom theme
- Ambrosite Next/Previous Post Link Plus or WP next_post_link to cycle through top level category
- Ajax Plugin Not Echoing Response
- How to add options to the plugin page?
- Adding inside wp-plugin jQuery script that receives JSON-formatted data, generated by php-function inside this plugin
- iframe not showing in post (with “allow php in posts” plugin activated)
- Saving widget options from class method
- Odd /wp-admin/admin-ajax.php entries showing in Wassup
- how can I query all wordpress users of a blog
- how can I do something on new user registration?
- where do I send my ajax calls
- Automate paragraphs in a post page to have a unique anchor link
- Affect on speed of wordpress membership plugins — currently trying s2member
- JQuery prepend a function
- This WordPress plugin isn’t creating links correctly
- How to get plugin’s folders permission
- Basics of changing plugin output
- Thesis 2 custom Page
- WordPress plugin url for form submit
- Hook into the rendering of a WordPress Template
- how to place a link on the first post only using a plugin
- Minimizing scripts & css files that plugins add
- How to setup a product that has multiple price options? [closed]
- How to install Google Analytics onto site without internet access
- Best way to count visitors?
- WordPress User Post Products
- Is there any pre-existing plugin to track and block IPs with suspicious activity on my site?
- WPTouch – how to remove shortcodes or make shortcodes function
- Adding class to last list item? Not WP generated
- How to make custom plugin run on demand?
- Replacing global wp_query
- Making my plugin create a page?
- Maintaining plugin addons while upgrading
- Not One ‘Contact Form Plugin’ will send email // Work
- creating a plug in that would tap into save/update action of posts [closed]
- WordPress plugin won’t show on some themes
- what is name of this plugin used for photo gallery page [closed]
- Why can’t I call a (member) function from within a foreach?
- Is there a way to make the main page only display a brief description of the full article?
- Photo Gallery Plugin and Touch Devices