Skip to content
This repository
Browse code

initial support for sticky posts

  • Loading branch information...
commit 970641da9c4e1c7b0b3bad2827cd11c74eaea732 1 parent 91df125
Alex King authored August 07, 2012

Showing 1 changed file with 38 additions and 0 deletions. Show diff stats Hide diff stats

  1. 38  utility.php
38  utility.php
@@ -583,6 +583,7 @@ function cfct_choose_general_template_default($dir, $files) {
583 583
 function cfct_choose_single_template($files = array(), $filter = '*', $dir = '') {
584 584
 // must be called within the_loop - cfct_choose_general_template_single() approximates a loop for this reason.
585 585
 	$exec_order = array(
  586
+		'sticky',
586 587
 		'author',
587 588
 		'meta',
588 589
 		'format',
@@ -632,6 +633,26 @@ function cfct_choose_single_template_type($dir, $files, $filter) {
632 633
 }
633 634
 
634 635
 /**
  636
+ * Chooses which template to display for the single context based on "sticky" status
  637
+ * 
  638
+ * @param string $dir Directory to use for selecting the template file
  639
+ * @param array $files A list of files to search through to find the correct template
  640
+ * @param string $filter Used in filtering the filename
  641
+ * @return mixed Path to the file, false if no file exists
  642
+ * 
  643
+**/
  644
+function cfct_choose_single_template_sticky($dir, $files, $filter) {
  645
+	$sticky_files = cfct_sticky_templates($dir, $files, $filter);
  646
+	if (count($sticky_files) && is_sticky()) {
  647
+		$file = cfct_filename_filter('sticky.php', $filter);
  648
+		if (in_array($file, $sticky_files)) {
  649
+			return $file;
  650
+		}
  651
+	}
  652
+	return false;
  653
+}
  654
+
  655
+/**
635 656
  * Chooses which template to display for the single context based on author login
636 657
  * 
637 658
  * @param string $dir Directory to use for selecting the template file
@@ -1218,6 +1239,23 @@ function cfct_author_templates($dir, $files = null, $filter = '*') {
1218 1239
 }
1219 1240
 
1220 1241
 /**
  1242
+ * Is there a sticky template?
  1243
+ * 
  1244
+ * @param string $dir Directory to search through for files if none are given
  1245
+ * @param array $files A list of files to search through
  1246
+ * @return array list of files that match the author template structure
  1247
+ * 
  1248
+**/
  1249
+function cfct_sticky_templates($dir, $files = null, $filter = '*') {
  1250
+	if (is_null($files)) {
  1251
+		$files = cfct_files(CFCT_PATH.$dir);
  1252
+	}
  1253
+	$prefix = str_replace('*', '', $filter).'sticky';
  1254
+	$matches = cfct_filter_files($files, $prefix);
  1255
+	return apply_filters('cfct_sticky_templates', $matches);
  1256
+}
  1257
+
  1258
+/**
1221 1259
  * Get a list of files that match the custom post type template structure
1222 1260
  * 
1223 1261
  * @param string $dir Directory to search through for files if none are given

0 notes on commit 970641d

Please sign in to comment.
Something went wrong with that request. Please try again.