Thursday, May 22, 2014

How to Write Custom PHP Function Files for Thesis Theme



1. Open your file transfer program – also called an FTP program. Locate and double-click to open the 'wp-content/themes/thesis_version number' folder. Locate the custom-sample folder within the main Thesis folder, change its name to custom and then click to open the 'custom' folder and the 'custom_functions.php' source file.

2. Open a plain text editor such as Microsoft Notepad or a code editor in Web design software such as Dreamweaver or NetBeans. As an alternate option, you can use the custom file editor inside Thesis. Be aware that if you choose this option, PHP coding errors can cause your site to crash, making access to your site to fix the errors impossible. Writing custom functions to a text editor gives you the ability to access and make whatever changes are necessary.

3. Form the structure of a custom PHP function with opening and closing tags:

…custom function code goes here

?>

4. Add the code for the custom function using the following syntax:function function-name() {

contents go here

}As an example, a function that adds your six most popular posts above Sidebar 1 will appear as:function custom_popular_posts() {

thesis_widget_popular_posts('recent', 'Popular Posts', ‘6’);

}

5. Finish the function by identifying a location for the custom function:add_action('thesis_hook_before_sidebar_1', 'custom_popular_posts');

6. Copy and paste the custom function code into your open custom_functions.php source file in your FTP program.

7. Upload the edited custom_functions.php source file by dragging or by selecting the file to upload. When your FTP program tells you the file already exists and asks if you want to overwrite it, always select “Yes.”

No comments:

Post a Comment