functions - Reference multiple style sheets, clearing styles for permalink page, custom fields for css

admin2025-06-05  1

my wordpress theme will be styling posts on the index page based on their post-ID class -this will result in a lot of css code over longer durations of time. To keep the website lightweight as possible I wanted to -

a> split this code up into smaller stylesheets, but would also need to -

b> target stylesheets only when relevant to avoid references all the seperate style docs at once, would consider one style for a months worth of posts (set number of posts a day) - I can consider making one stylesheet for each days posts.

c> the index page style needs to be cleared for the permalink style, as the permalink pages will be styled completely differently.

I am not much of a coder however and I'm not sure where to begin, from what I understand somewhere along this following code -

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

I should be injecting some sort of php to pick up the post-ID class and match it to one of the stylesheets.

This would in turn require a filing of the stylesheets in a format where post-ID-class and stylesheet name are relatable.

This would presumably done by running fucntion to check post-ID-number range and match it to stylesheet which is paired with number range which encompasses the post-ID-number.

Would my theorizing above be along the right lines or would you suggest a different method? either way I'm not sure where to begin when it comes to coding this out.

The other method I had in mind was to use custom field (text-field) to hold names of classes that a function would pick up and add to the post's classes. I'm using Advanced Custom Fields as I cant seem to get default custom fields to appear even when disabling ACF, another issue I need help resolving. Even with ACF however, I dont know how to actually take advantage of the custom fields, I've set up the fields and field groups but I'm not sure where to do next.

Any help woould be much appreciated.

my wordpress theme will be styling posts on the index page based on their post-ID class -this will result in a lot of css code over longer durations of time. To keep the website lightweight as possible I wanted to -

a> split this code up into smaller stylesheets, but would also need to -

b> target stylesheets only when relevant to avoid references all the seperate style docs at once, would consider one style for a months worth of posts (set number of posts a day) - I can consider making one stylesheet for each days posts.

c> the index page style needs to be cleared for the permalink style, as the permalink pages will be styled completely differently.

I am not much of a coder however and I'm not sure where to begin, from what I understand somewhere along this following code -

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

I should be injecting some sort of php to pick up the post-ID class and match it to one of the stylesheets.

This would in turn require a filing of the stylesheets in a format where post-ID-class and stylesheet name are relatable.

This would presumably done by running fucntion to check post-ID-number range and match it to stylesheet which is paired with number range which encompasses the post-ID-number.

Would my theorizing above be along the right lines or would you suggest a different method? either way I'm not sure where to begin when it comes to coding this out.

The other method I had in mind was to use custom field (text-field) to hold names of classes that a function would pick up and add to the post's classes. I'm using Advanced Custom Fields as I cant seem to get default custom fields to appear even when disabling ACF, another issue I need help resolving. Even with ACF however, I dont know how to actually take advantage of the custom fields, I've set up the fields and field groups but I'm not sure where to do next.

Any help woould be much appreciated.

Share Improve this question asked Dec 27, 2018 at 5:19 bldingbloksbldingbloks 33 bronze badges 1
  • The above functionality is too complex to be implemented as you will need to have each css called based on the called classes moreover Can you please let me know the reason you need to make different CSS . instead of adding all code in one css – Pratik bhatt Commented Dec 27, 2018 at 7:12
Add a comment  | 

1 Answer 1

Reset to default 0

Managed to get the custom field method to work, which saves alot of headache in the long run, solution was simple -

<?php post_class(get_field('the-field')); ?>
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749065892a316058.html

最新回复(0)