make a new PHP file and paste code into it?
-
I am trying to paste the code below and can’t seem to find clear info on how to make a PHP file? What I did so far is create a PHP folder within my Hosts file manager at wp-content/plug-ins/my php folder. But once the folder was created, I had nowhere to paste the code?
I am really new to wordpress and am starting from scratch with coding. Any help would be much appreciated. Here is the code:
<?php
/*
Plugin Name: Custom Post Templates
Plugin URI: https://boren.nu/
Description: Load custom single post templates.
Author: Ryan Boren
Version: 0.9
Author URI: https://boren.nu/
*/function cpt_custom_post_template($template) {
global $wp_query;$post = $wp_query->post;
$id = $post->ID;// If a template exists for this post ID, load it.
if ( file_exists(TEMPLATEPATH . “/single-{$id}.php”) )
return TEMPLATEPATH . “/single-{$id}.php”;// Add custom checks here. For example, give posts different templates
// depending on what categories they are in.
if ( in_category(‘1’) && file_exists(TEMPLATEPATH . ‘/single-cat-1.php’) )
return TEMPLATEPATH . ‘/single-cat-1.php’;return $template;
}add_filter(‘single_template’, ‘cpt_custom_post_template’);
?>
- The topic ‘make a new PHP file and paste code into it?’ is closed to new replies.