Quickly generate topic setting options by merging arrays

» WordPress » Quickly generate topic setting options by merging arrays

Add a background option to the theme quickly by adding and merging arrays

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

preface

Recently, I found that many development themes like to write plug-ins, and they are tool class plug-in dependent plug-ins. Some themes may have to install a certain plug-in, and if they do not install this plug-in, they may not work. Some users may be disgusted with this method, but it is a very pleasant thing for developers, After all, once you write code, if all the topics are used, it will greatly improve the development efficiency. Today, we just discuss the technical issues aside from 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, writing another theme background is not intended to waste code or repeat work. What I want is that the theme does not need to write the background, Borrow the background of the plug-in directly, consider it, test it, OK, no problem

Implementation method

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

Here, my design method is to first determine whether there is an options.php file under the current theme directory, and if there is one, directly include the load. This options.php file, like the plug-in, is an option configuration array file. Later, use array related functions to merge it with the plug-in's original configuration file to get a new configuration array, The plug-in directly loads this new array to generate background options.
Maybe the code is like this

 //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

--End--

Post reply

Your email address will not be disclosed. Required items have been used * tagging

3 Replies to "Quickly generate topic setting options by merging arrays"

  1. How can I use git theme to set the home page like yours? Mine is totally different

  2. It seems that I want to make a theme, but I don't know much about PHP. Ha ha, I 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 a white man like me to develop his own theme.