The popular open-source contract for web designers and developers by Stuff & Nonsense
- Originally published: 23/12/2008
- Revised date: 15/12/2013
- Original post
| <?php | |
| /* ========================= */ | |
| /* == Configure our routes == */ | |
| /* ========================= */ | |
| // For month and/or year based archives | |
| function saos_rewrite_tags() { | |
| add_rewrite_tag('%getyear%', '([^&]+)'); // adds year to permalinks | |
| add_rewrite_tag('%getmonth%', '([^&]+)'); // adds month to permalinks | |
| // add_rewrite_tag( '%bf_events_year%', '([0-9]{4})' ); // adds year to single page permalinks |
| <?php | |
| /* -- Gravity Forms send email to me -- */ | |
| function set_post_content($entry, $form) { | |
| //Gravity Forms has validated the data | |
| //Our Custom Form Submitted via PHP will go here | |
| // Lets get the IDs of the relevant fields and prepare an email message | |
| $message = print_r($entry, true); | |
| // In case any of our lines are larger than 70 characters, we should use wordwrap() | |
| $message = wordwrap($message, 70); | |
| // Send |
| <?php // In functions.php: | |
| /* -- Year and month based archive listings -- */ | |
| function posts_by_year() { | |
| // array to use for results | |
| $years = array(); | |
| // get posts from WP | |
| $posts = get_posts(array( | |
| 'numberposts' => -1, | |
| 'orderby' => 'post_date', |
| <?php | |
| /* -- Compare the URL to the permalink, return true if matches -- */ | |
| function is_current_page($permalink) { | |
| $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; | |
| if (strpos($url,$permalink) !== false) | |
| return true; | |
| else | |
| return false; | |
| } | |
| ?> |
| <?php | |
| /** | |
| * This is an example of a custom loop with pagination and a custom URL structure | |
| * get_year and get_month are our custom query string variables | |
| * EX: http://saos.co/clevelandplus/public/news-press/cle-in-the-national-press/2014/09/page/3/ | |
| * where /2014/ and /09/ represent our custom query string parameters | |
| */ | |
| global $wp_query; | |
| if(isset($wp_query->query_vars['getyear'])) { |
| <?php | |
| // To instantiate the walker, pass it to wp_nav_menu | |
| wp_nav_menu(array( | |
| 'theme_location' => 'newsletter-archive-menu', | |
| 'walker' => new saos_walker_nav_menu() | |
| )); | |
| ?> |
| <?php $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; | |
| $args = array( | |
| 'post_type' => 'newsletters', | |
| 'posts_per_page' => 4, | |
| 'paged' => $paged | |
| ); | |
| $query = new WP_Query($args); | |
| // hack to get pagination to work on custom post type custom query | |
| $temp_query = $wp_query; | |
| $wp_query = NULL; |