最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to design a table based on css values set from admindashboard

programmeradmin8浏览0评论

I have created a table at Single Product Page via plugin. I want to change the color, border, bg-color etc.. according to the values that the admin will set/enter from dashboard.

I have done the following so far.

From the following form (attached image), the admin will choose the css values for table body, header etc.And after hitting the save button, all those css values will be saved inin wp_options as key value pair.

For Example

'table_background_color' => '#ff5'

What I want

I don't want to get the wp_option and then apply that css design value for particular element of the table, because I have huge form containing a lot of css design values and applying css inline is kind of messy.

I'm looking for some nice approach to apply those css values (which I have saved in wp_options) to the table.

How can I apply those saved css values from a separate file ? Any help/recommendation will be highly appreciated, thanks.

I have created a table at Single Product Page via plugin. I want to change the color, border, bg-color etc.. according to the values that the admin will set/enter from dashboard.

I have done the following so far.

From the following form (attached image), the admin will choose the css values for table body, header etc.And after hitting the save button, all those css values will be saved inin wp_options as key value pair.

For Example

'table_background_color' => '#ff5'

What I want

I don't want to get the wp_option and then apply that css design value for particular element of the table, because I have huge form containing a lot of css design values and applying css inline is kind of messy.

I'm looking for some nice approach to apply those css values (which I have saved in wp_options) to the table.

How can I apply those saved css values from a separate file ? Any help/recommendation will be highly appreciated, thanks.

Share Improve this question asked Jul 27, 2020 at 10:36 wp_learnerwp_learner 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

There's a discussion of a very similar question here.

As in that question, there are a few suggested options, each with their own pros and cons.

For what you describe, it sounds like you might want to consider the idea of generating a CSS file every time the admin changes any settings on this page. This is the fastest option because you don't need to re-do this work on every page load.

I'm not sure if there's an easy way to do this (perhaps someone else will know a way), so if you like that approach it seems like you need to do these steps:

  1. Make sure that from PHP you can write to a .css file somewhere. Perhaps make a new plugin for this feature and put the code and generated CSS file in the plugin.
  2. Make sure that the .css file can be easily enqueue'd from Wordpress
  3. Write a script which takes all of your options from wp_options and writes a complete CSS file
  4. Hook that script so that it re-generates the CSS every time the admin page is saved.

HTH

发布评论

评论列表(0)

  1. 暂无评论