/functions.php

  1. <?php 
  2. /** 
  3. * CWP-MegaR functions and definitions 
  4. * 
  5. * @package CWP-MegaR 
  6. */ 
  7.  
  8. /** 
  9. * Set the content width based on the theme's design and stylesheet. 
  10. */ 
  11. if ( ! isset( $content_width ) ) 
  12. $content_width = 640; /** pixels */ 
  13.  
  14.  
  15. /** 
  16. * Sets up theme defaults and registers support for various WordPress features. 
  17. * 
  18. * Note that this function is hooked into the after_setup_theme hook, which runs 
  19. * before the init hook. The init hook is too late for some features, such as indicating 
  20. * support post thumbnails. 
  21. */ 
  22. function cwp_megar_setup() { 
  23.  
  24. /** 
  25. * Make theme available for translation 
  26. * Translations can be filed in the /languages/ directory 
  27. * If you're building a theme based on CWP-MegaR, use a find and replace 
  28. * to change 'cwp-megar' to the name of your theme in all the template files 
  29. */ 
  30. load_theme_textdomain( 'cwp-megar', get_template_directory() . '/languages' ); 
  31.  
  32. /** 
  33. * Add default posts and comments RSS feed links to head 
  34. */ 
  35. add_theme_support( 'automatic-feed-links' ); 
  36.  
  37. /** 
  38. * Enable support for Post Thumbnails on posts and pages 
  39. * 
  40. * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails 
  41. */ 
  42. //add_theme_support( 'post-thumbnails' ); 
  43.  
  44. /** 
  45. * This theme uses wp_nav_menu() in one location. 
  46. */ 
  47. register_nav_menus( array( 
  48. 'primary' => __( 'Primary Menu', 'cwp-megar' ),  
  49. 'footer' => __( 'Footer Menu', 'cwp-megar' ),  
  50. 'sidebar_menu' => __( 'Sidebar menu', 'cwp-megar' ),  
  51. ) ); 
  52.  
  53. /** 
  54. * Enable support for Post Formats 
  55. */ 
  56. add_theme_support( 'post-formats', array( 'aside', 'audio', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video' ) ); 
  57.  
  58. /** 
  59. * Setup the WordPress core custom background feature. 
  60. */ 
  61. add_theme_support( 'custom-background', apply_filters( 'cwp_megar_custom_background_args', array( 
  62. 'default-color' => 'fefefe',  
  63. 'default-image' => '',  
  64. ) ) ); 
  65.  
  66.  
  67. /** 
  68. * Implement the Custom Header feature. 
  69. */ 
  70. //require get_template_directory() . '/inc/custom-header.php'; 
  71. $args = array( 
  72. 'width' => 980,  
  73. 'height' => 60,  
  74. 'default-image' => '',  
  75. 'uploads' => true,  
  76. ); 
  77. add_theme_support( 'custom-header', $args ); 
  78.  
  79. /** 
  80. * Custom template tags for this theme. 
  81. */ 
  82. require get_template_directory() . '/inc/template-tags.php'; 
  83.  
  84. /** 
  85. * Custom functions that act independently of the theme templates. 
  86. */ 
  87. require get_template_directory() . '/inc/extras.php'; 
  88.  
  89. /** 
  90. * Customizer additions. 
  91. */ 
  92. require get_template_directory() . '/inc/customizer.php'; 
  93.  
  94. /** 
  95. * Load Jetpack compatibility file. 
  96. */ 
  97. require get_template_directory() . '/inc/jetpack.php'; 
  98.  
  99. /** 
  100. * Enabling Support for Post Thumbnails. 
  101. */ 
  102. add_theme_support( 'post-thumbnails' );  
  103.  
  104. /** 
  105. * Banner widget. 
  106. */ 
  107. $widget_banner = locate_template( 'widgets/banner-widget/banner-widget.php', TRUE, TRUE ); 
  108.  
  109. /** 
  110. * Facebook like box widget. 
  111. */ 
  112. $widget_facebook_box = locate_template( 'widgets/facebook-like-box/fb-like-box.php', TRUE, TRUE ); 
  113.  
  114. add_action( 'after_setup_theme', 'cwp_megar_setup' ); 
  115.  
  116. /** 
  117. * Register widgetized area and update sidebar with default widgets 
  118. */ 
  119. function cwp_megar_widgets_init() { 
  120. register_sidebar( array( 
  121. 'name' => __( 'Sidebar', 'cwp-megar' ),  
  122. 'id' => 'sidebar-1',  
  123. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',  
  124. 'after_widget' => '</aside>',  
  125. 'before_title' => '<h1 class="widget-title">',  
  126. 'after_title' => '</h1>',  
  127. ) ); 
  128. add_action( 'widgets_init', 'cwp_megar_widgets_init' ); 
  129.  
  130. /** 
  131. * Enqueue scripts and styles 
  132. */ 
  133. function cwp_megar_scripts() { 
  134.  
  135. wp_enqueue_style( 'cwp-megar-bootstrap-style', get_template_directory_uri() . '/css/bootstrap.css', array(), '20130801', 'all' ); 
  136.  
  137. wp_enqueue_style( 'cwp-megar-custom-style', get_template_directory_uri() . '/css/bootstrap-responsive.css', array(), '20130801', 'all' ); 
  138.  
  139. wp_enqueue_style( 'cwp-megar-style', get_stylesheet_uri() ); 
  140.  
  141. wp_enqueue_script('jquery'); 
  142.  
  143. wp_enqueue_script( 'cwp-megar-jquery-min', get_template_directory_uri() . '/js/jquery.min.js', array(), '20130801', true ); 
  144.  
  145. wp_enqueue_script( 'cwp-megar-bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array(), '20130801', true ); 
  146.  
  147. wp_enqueue_script( 'cwp-megar-tinyscrollbar', get_template_directory_uri() . '/js/jquery.tinyscrollbar.min.js', array(), '', true ); 
  148.  
  149. wp_enqueue_script( 'cwp-megar-tinynav', get_template_directory_uri() . '/js/tinynav.js', array(), '20130801', true ); 
  150.  
  151. wp_enqueue_script( 'cwp-megar-functions', get_template_directory_uri() . '/js/functions.js', array('jquery'), '20130801', true ); 
  152.  
  153. wp_enqueue_script( 'cwp-megar-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true ); 
  154.  
  155. wp_enqueue_script( 'cwp-megar-ajaxLoop', get_template_directory_uri() . '/js/ajaxLoop.js', array('jquery'), '1.0.0', true ); 
  156.  
  157.  
  158. wp_enqueue_script( 'cwp-megar-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );  
  159. wp_register_style( 'cwp_open-sans', 'http://fonts.googleapis.com/css?family=Open+Sans:400, 600, 700, 300|Roboto+Slab');  
  160.  
  161. wp_enqueue_style( 'cwp_open-sans' ); 
  162.  
  163. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { 
  164. wp_enqueue_script( 'comment-reply' ); 
  165.  
  166. if ( is_singular() && wp_attachment_is_image() ) { 
  167. wp_enqueue_script( 'cwp-megar-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20120202' ); 
  168. add_action( 'wp_enqueue_scripts', 'cwp_megar_scripts' ); 
  169.  
  170.  
  171. /** 
  172. * No title 
  173. */ 
  174. add_filter( 'the_title', 'cwp_no_title'); 
  175. function cwp_no_title ($title) {  
  176. if( $title == "" ) {  
  177. $title = "(No title)";  
  178. }  
  179. return $title;  
  180.  
  181. function cwp_add_editor_styles() { 
  182. add_editor_style( '/css/custom-editor-style.css' ); 
  183. add_action( 'init', 'cwp_add_editor_styles' ); 
  184.  
  185. /** 
  186. * Load more posts 
  187. */ 
  188. add_action('wp_ajax_cwp_loop', 'cwp_loop_callback'); 
  189. add_action('wp_ajax_nopriv_cwp_loop', 'cwp_loop_callback'); 
  190.  
  191. function cwp_loop_callback() { 
  192. global $post; 
  193.  
  194. $args = array( 
  195. 'posts_per_page' => -1,  
  196. 'post__in' => get_option('sticky_posts') 
  197. ); 
  198. $my_query1 = new WP_Query($args); 
  199. while ($my_query1->have_posts()) : $my_query1->the_post(); 
  200. ?> 
  201. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 
  202. <header class="entry-header"> 
  203.  
  204. <div class="entry-thumbnail">  
  205. <?php 
  206. if ( has_post_thumbnail() ) { 
  207. ?> 
  208. <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark"> 
  209. <?php 
  210. the_post_thumbnail(array(350, 250), array('class' => 'alignleft')); 
  211. ?> 
  212. </a> 
  213. <?php 
  214. ?> 
  215. </div> 
  216.  
  217. <div class="entry-meta meta-top"> 
  218. <div class="post-categories"> 
  219. <?php the_category(' / '); ?> 
  220. </div> 
  221. <?php if ( 'post' == get_post_type() ) : ?> 
  222. <div class="entry-meta"> 
  223. <?php cwp_megar_posted_on(); ?> 
  224. </div><!-- .entry-meta --> 
  225. <?php endif; ?>  
  226. </div> 
  227. <h2 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2> 
  228. </header><!-- .entry-header --> 
  229.  
  230. <?php if ( is_search() ) : // Only display Excerpts for Search ?> 
  231. <div class="entry-summary"> 
  232. <?php the_excerpt(); ?> 
  233. </div><!-- .entry-summary --> 
  234. <?php else : ?> 
  235. <div class="entry-content"> 
  236. <?php the_excerpt(); ?> 
  237. <?php //the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'cwp-megar' ) ); ?> 
  238. <?php 
  239. wp_link_pages( array( 
  240. 'before' => '<div class="page-links">' . __( 'Pages:', 'cwp-megar' ),  
  241. 'after' => '</div>',  
  242. ) ); 
  243. ?> 
  244. </div><!-- .entry-content --> 
  245. <?php endif; ?> 
  246.  
  247. </article><!-- #post-## --> 
  248.  
  249. <?php 
  250. endwhile; 
  251. wp_reset_postdata(); 
  252.  
  253. $numPosts = (isset($_GET['numPosts'])) ? $_GET['numPosts'] : 0; 
  254. $page = (isset($_GET['pageNumber'])) ? $_GET['pageNumber'] : 0; 
  255. $catt = (isset($_GET['catNumber'])) ? $_GET['catNumber'] : -1; 
  256. $yearr = (isset($_GET['yearPar'])) ? $_GET['yearPar'] : -1; 
  257. $monthh = (isset($_GET['monthPar'])) ? $_GET['monthPar'] : -1; 
  258. $authorr = (isset($_GET['authorPar'])) ? $_GET['authorPar'] : -1; 
  259. $tagg = (isset($_GET['tagPar'])) ? $_GET['tagPar'] : -1; 
  260.  
  261.  
  262. if($catt != -1): 
  263.  
  264. query_posts(array( 
  265. 'posts_per_page' => $numPosts,  
  266. 'paged' => $page,  
  267. 'cat' => $catt,  
  268. 'post_status' => 'publish',  
  269. 'post__not_in' => get_option( 'sticky_posts' ) 
  270. )); 
  271. elseif($yearr != -1 && $monthh != -1): 
  272.  
  273. query_posts(array( 
  274. 'posts_per_page' => $numPosts,  
  275. 'paged' => $page,  
  276. 'year' => $yearr,  
  277. 'monthnum' => $monthh,  
  278. 'post_status' => 'publish',  
  279. 'post__not_in' => get_option( 'sticky_posts' ) 
  280. )); 
  281.  
  282. elseif($yearr != -1): 
  283.  
  284. query_posts(array( 
  285. 'posts_per_page' => $numPosts,  
  286. 'paged' => $page,  
  287. 'year' => $yearr,  
  288. 'post_status' => 'publish',  
  289. 'post__not_in' => get_option( 'sticky_posts' ) 
  290. )); 
  291.  
  292. elseif($authorr != -1): 
  293.  
  294. query_posts(array( 
  295. 'posts_per_page' => $numPosts,  
  296. 'paged' => $page,  
  297. 'author_name' => $authorr,  
  298. 'post_status' => 'publish',  
  299. 'post__not_in' => get_option( 'sticky_posts' ) 
  300. )); 
  301.  
  302. elseif($tagg != -1): 
  303.  
  304. query_posts(array( 
  305. 'posts_per_page' => $numPosts,  
  306. 'paged' => $page,  
  307. 'tag' => $tagg,  
  308. 'post_status' => 'publish',  
  309. 'post__not_in' => get_option( 'sticky_posts' ) 
  310. )); 
  311.  
  312. else: 
  313.  
  314. query_posts(array( 
  315. 'posts_per_page' => $numPosts,  
  316. 'paged' => $page,  
  317. 'post_status' => 'publish',  
  318. 'post__not_in' => get_option( 'sticky_posts' ) 
  319. )); 
  320. endif; 
  321.  
  322. $cpage = $page;  
  323.  
  324. while ( have_posts() ) : the_post(); ?> 
  325.  
  326.  
  327.  
  328.  
  329. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 
  330. <header class="entry-header"> 
  331.  
  332. <div class="entry-thumbnail">  
  333. <?php 
  334. if ( has_post_thumbnail() ) { 
  335. ?> 
  336. <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark"> 
  337. <?php 
  338. the_post_thumbnail(array(250, 250), array('class' => 'alignleft')); 
  339. ?> 
  340. </a> 
  341. <?php 
  342. ?> 
  343. </div> 
  344.  
  345. <div class="entry-meta meta-top"> 
  346. <div class="post-categories"> 
  347. <?php the_category(' / '); ?> 
  348. </div> 
  349. <?php if ( 'post' == get_post_type() ) : ?> 
  350. <div class="entry-meta"> 
  351. <?php cwp_megar_posted_on(); ?> 
  352. </div><!-- .entry-meta --> 
  353. <?php endif; ?>  
  354. </div> 
  355. <h2 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2> 
  356. </header><!-- .entry-header --> 
  357.  
  358. <?php if ( is_search() ) : // Only display Excerpts for Search ?> 
  359. <div class="entry-summary"> 
  360. <?php the_excerpt(); ?> 
  361. </div><!-- .entry-summary --> 
  362. <?php else : ?> 
  363. <div class="entry-content"> 
  364. <?php the_excerpt(); ?> 
  365. <?php //the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'cwp-megar' ) ); ?> 
  366. <?php 
  367. wp_link_pages( array( 
  368. 'before' => '<div class="page-links">' . __( 'Pages:', 'cwp-megar' ),  
  369. 'after' => '</div>',  
  370. ) ); 
  371. ?> 
  372. </div><!-- .entry-content --> 
  373. <?php endif; ?> 
  374.  
  375. </article><!-- #post-## --> 
  376.  
  377.  
  378. <?php endwhile; 
  379. $all = wp_count_posts(); 
  380. $pall = ceil($all->publish/$numPosts); 
  381. if($cpage<$pall) { 
  382. ?> 
  383.  
  384.  
  385. <?php }  
  386.  
  387.  
  388. die(); // this is required to return a proper result 
.