Quickly generate topic setting options by merging arrays

» WordPress » Quickly generate topic setting options by merging arrays

By adding arrays and merging arrays, we can quickly add a background option to the theme

通过合并数组快速生成主题设置选项-极客公园

preface

Recently, it has been found that many developers like to write plug-ins, which are tool plug-in dependent plug-ins. Some themes may have to install some plug-ins. If they do not install such plug-ins, they may not be able to run. Some users may resent this method, but it is a very cool thing for developers, After all, if you write code once and all the topics are used, it will greatly improve the development efficiency. Today, we just discuss the technical problems instead of dependence.

demand

Because Yunluo has also developed a plug-in to support the theme, it naturally has a complete background. This background is actually the same as the previous git theme. If there is a plug-in background, it is not a waste of code or repetitive work to write another theme background. What I want is that the theme does not need to be written in the background, Directly borrow the background of the plug-in, consider, test, OK, no problem

Implementation method

Here, let me first say that my plug-in background uses array construction options. Adding an array can add an option, which is very convenient and flexible. Then the problem becomes how to add arrays from the theme.

Here, my design method is to first determine whether there is an options.php file under the current theme directory. If so, it can be loaded directly. This options.php file is an option configuration array file just like the plug-in. Later, use the array related functions to merge it with the original configuration file of the plug-in to get a new configuration array, The plug-in loads the new array directly and generates background options.
This is probably the code

 //Load the theme configuration. The default path is in the theme root directory options.php if( file_ exists(get_ template_ directory() . '/options.php')) include(get_ template_ directory() . '/options.php'); if(! empty($gdk_ theme_ options)){ $gdk_ options = array_ merge($gdk_ theme_ options,$gdk_ options); }

Success effect

 Quickly generate theme setting options by merging arrays - geek Park

--Over--

Comment

Your email address will not be disclosed. Required item used * tagging

3 replies to "quickly generate topic setting options by merging arrays"

  1. It looks very powerful. I also want to make a theme, but I don't know PHP very well. Ha ha, I've read an article about the theme setting framework, which seems to have the same function. I don't know what kind of plug-in you have. It's convenient for me to develop my own theme.