template/wordpress/functions.php in edge_framework-0.6.0 vs template/wordpress/functions.php in edge_framework-0.6.1
- old
+ new
@@ -2,31 +2,32 @@
/* ------------------------------------
EDGE Press v0.1
- Extend functionality to Word Press
--------------------------------------- */
-add_theme_support( 'post-thumbnails' );
+add_theme_support("post-thumbnails");
function root() {
- return get_template_directory_uri().'/';
+ return get_template_directory_uri()."/";
}
/*
-Get path to assets directory
+Echo path to assets directory
@return = relative path to specified assets directory
*/
-function img() { return root().'assets/img/'; }
-function css() { return root().'assets/css/'; }
-function js() { return root().'assets/js/'; }
-function files() { return root().'assets/files/'; }
+function home() { echo home_url()."/"; }
+function img() { echo root()."assets/img/"; }
+function css() { echo root()."assets/css/"; }
+function js() { echo root()."assets/js/"; }
+function files() { echo root()."assets/files/"; }
/*
Get the last word from the URL, useful for Header-menu's active state
@return = the last word from the current page
*/
function get_current_page() {
- $pageURL = 'http';
+ $pageURL = "http";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
@@ -46,11 +47,11 @@
$text = html_entity_decode($text, ENT_QUOTES);
if (strlen($text) > $char_number) {
$text = substr($text, 0, $char_number);
$text = substr($text,0,strrpos($text," "));
- $punctuation = ".!?:;,-"; //punctuation you want removed
+ $punctuation = ".!?:;,-"; // punctuation you want removed
$text = (strspn(strrev($text), $punctuation) != 0)
?
substr($text, 0, -strspn(strrev($text), $punctuation))
:
@@ -58,6 +59,19 @@
$text = $text.$etc;
}
$text = htmlentities($text, ENT_QUOTES);
return $text;
-}
+}
+
+/*
+ Automatically use "single-{category_slug}.php" as post template for that category
+ Example:
+ "single-product.php" is used as template for post with category "product"
+*/
+add_filter("single_template", create_function(
+ '$the_template',
+ 'foreach( (array) get_the_category() as $cat ) {
+ if ( file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php") )
+ return TEMPLATEPATH . "/single-{$cat->slug}.php"; }
+ return $the_template;' )
+);
\ No newline at end of file