SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | ||
3 | ======================================================================================= | |
4 | [style.css] | |
5 | ======================================================================================= | |
6 | /* | |
7 | Template Name: News Reporter | |
8 | Template URI: http://amanweb.net | |
9 | Author: Aman Ullah | |
10 | Author URI: http://amanweb.net/aman | |
11 | Version: 1.0 | |
12 | Description: This is News Template. | |
13 | */ | |
14 | .alignnone{float:left} | |
15 | .alignleft{float:left;margin-right:15px} | |
16 | .alignright{float:right;margin-left:15px} | |
17 | .aligncenter{float:center} | |
18 | ||
19 | ||
20 | ||
21 | ||
22 | ||
23 | ||
24 | ||
25 | ||
26 | ======================================================================================= | |
27 | /*----- REPLACE <title> TAG ------*/ | |
28 | ======================================================================================= | |
29 | <title><?php bloginfo('name'); ?><?php wp_title(); ?></title> | |
30 | ||
31 | ||
32 | ||
33 | ||
34 | ||
35 | ||
36 | ||
37 | ||
38 | DYNAMIC STYLE.CSS | |
39 | ======================================================================================= | |
40 | <link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url'); ?>" media="screen" /> | |
41 | ||
42 | ||
43 | ||
44 | ||
45 | ||
46 | ||
47 | ======================================================================================= | |
48 | /*----- NECESSARY CODES ------*/ | |
49 | ======================================================================================= | |
50 | <?php wp_head(); ?> | |
51 | <?php wp_footer(); ?> | |
52 | <?php bloginfo('name'); ?> [use in <title> tag] | |
53 | <?php bloginfo('home'); ?> [use for home menu (eg: logo)] | |
54 | <?php echo get_template_directory_uri(); ?>/ | |
55 | <?php bloginfo('stylesheet_url'); ?> | |
56 | <?php bloginfo( 'description' ); ?> [for use the tagline "just another wordpress site"] | |
57 | <?php get_header(); ?> | |
58 | <?php get_footer(); ?> | |
59 | <?php get_sidebar(); ?> | |
60 | <?php get_template_part('file_name_without_extension'); ?> | |
61 | <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?> | |
62 | <?php echo human_time_diff( get_comment_time('U'), current_time('timestamp') ) . ' ago'; ?> | |
63 | <?php the_permalink(); ?> | |
64 | <?php the_title(); ?> | |
65 | <?php the_content(); ?> | |
66 | <?php the_time('M d, Y') ?> | |
67 | <?php the_author();?> | |
68 | <?php the_excerpt(); ?> | |
69 | <?php the_category(', '); ?> | |
70 | <?php comments_popup_link('No Comment', '1 Comment', '% Comments'); ?> | |
71 | <?php the_ID(); ?> | |
72 | ||
73 | ||
74 | ||
75 | ||
76 | ||
77 | ||
78 | ======================================================================================= | |
79 | [functions.php] /*----- DYNAMIC NAVIGATION MENU ------*/ | |
80 | ======================================================================================= | |
81 | add_action('init', 'wpj_register_menu'); | |
82 | function wpj_register_menu() { | |
83 | if (function_exists('register_nav_menu')) { | |
84 | register_nav_menu( 'wpj_main_menu', __( 'Main Menu', 'brightpage' ) ); | |
85 | } | |
86 | } | |
87 | function wpj_default_menu() { | |
88 | echo '<ul id="nav">'; | |
89 | if ('page' != get_option('show_on_front')) { | |
90 | echo '<li><a href="'. home_url() . '/">Home</a></li>'; | |
91 | } | |
92 | wp_list_pages('title_li='); | |
93 | echo '</ul>'; | |
94 | } | |
95 | ||
96 | --------------------------------------------------------------------------------------- | |
97 | ||
98 | <?php | |
99 | if (function_exists('wp_nav_menu')) { | |
100 | wp_nav_menu(array('theme_location' => 'wpj_main_menu', 'menu_class' => 'nav pull-right', 'fallback_cb' => 'wpj_default_menu')); | |
101 | } | |
102 | else { | |
103 | wpj_default_menu(); | |
104 | } | |
105 | ?> | |
106 | ||
107 | ||
108 | ||
109 | ||
110 | ||
111 | ||
112 | ||
113 | ======================================================================================= | |
114 | [functions.php] /*----- WORDPRESS JQUERY ------*/ | |
115 | ======================================================================================= | |
116 | function wordpress_latest_jquery(){ | |
117 | wp_enqueue_script('jquery'); | |
118 | } | |
119 | add_action('init', 'wordpress_latest_jquery'); | |
120 | ||
121 | ||
122 | ||
123 | ||
124 | ||
125 | ||
126 | ======================================================================================= | |
127 | [functions.php] /*----- REGISTER SIDEBAR ------*/ | |
128 | ======================================================================================= | |
129 | ||
130 | function aman_widget_areas() { | |
131 | register_sidebar( array( | |
132 | 'name' => __( 'Left Menu', 'aman' ), | |
133 | 'id' => 'left_sidebar', | |
134 | 'before_widget' => '<div class="single_sidebar">', | |
135 | 'after_widget' => '</div>', | |
136 | 'before_title' => '<h2>', | |
137 | 'after_title' => '</h2>', | |
138 | ) ); | |
139 | } | |
140 | add_action('widgets_init', 'aman_widget_areas'); | |
141 | ||
142 | ||
143 | [Sidebar.php] | |
144 | ----------- | |
145 | <?php if ( ! dynamic_sidebar( 'left_sidebar' ) ) : ?> | |
146 | your static data | |
147 | <?php endif; ?> | |
148 | ||
149 | ||
150 | ||
151 | ||
152 | ||
153 | ||
154 | ======================================================================================= | |
155 | /*----- POST QUERY ------*/ | |
156 | ======================================================================================= | |
157 | ||
158 | <?php query_posts('post_type=post&post_status=publish&posts_per_page=10&paged='. get_query_var('paged')); ?> | |
159 | ||
160 | <?php $args = array( | |
161 | 'posts_per_page' => 5, | |
162 | 'offset' => 0, | |
163 | 'category' => '', | |
164 | 'orderby' => 'post_date', | |
165 | 'order' => 'DESC', | |
166 | 'include' => '', | |
167 | 'exclude' => '', | |
168 | 'meta_key' => '', | |
169 | 'meta_value' => '', | |
170 | 'post_type' => 'post', | |
171 | 'post_mime_type' => '', | |
172 | 'post_parent' => '', | |
173 | 'post_status' => 'publish', | |
174 | 'suppress_filters' => true ); ?> | |
175 | ||
176 | ||
177 | ||
178 | ||
179 | ======================================================================================= | |
180 | [index.php] /*----- POST LOOP ------*/ | |
181 | ======================================================================================= | |
182 | ||
183 | <?php if(have_posts()):while(have_posts()):the_post(); ?> | |
184 | <!-- Your Post content here --> | |
185 | <?php endwhile; endif; ?> | |
186 | ||
187 | ||
188 | ||
189 | ||
190 | ||
191 | ||
192 | ||
193 | ||
194 | ======================================================================================= | |
195 | /*----- STANDARD POST QUERY ------*/ | |
196 | ======================================================================================= | |
197 | ||
198 | <?php global $post; | |
199 | $args = array( 'posts_per_page' => 4, 'post_type'=> 'slider-items', 'category_name' => 'Featured'); | |
200 | $myposts = get_posts( $args ); | |
201 | foreach( $myposts as $post ) : setup_postdata($post); ?> | |
202 | data here | |
203 | <?php endforeach; ?> | |
204 | ||
205 | ||
206 | ||
207 | ||
208 | ||
209 | ||
210 | ======================================================================================= | |
211 | /*----- CUSTOM POST IN MAIN QUERY ------*/ | |
212 | ======================================================================================= | |
213 | // Show posts of 'post', 'page' and 'movie' custom post types on home page | |
214 | function add_my_post_types_to_query( $query ) { | |
215 | if ( is_home() && $query->is_main_query() ) | |
216 | $query->set( 'post_type', array( 'post', 'page', 'movie' ) ); | |
217 | return $query; | |
218 | } | |
219 | add_action( 'pre_get_posts', 'add_my_post_types_to_query' ); | |
220 | ||
221 | ||
222 | ||
223 | ||
224 | ||
225 | ||
226 | ||
227 | ======================================================================================= | |
228 | /*----- PAGINATION ------*/ | |
229 | ======================================================================================= | |
230 | <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts') ); ?></div> | |
231 | <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>') ); ?></div> | |
232 | ||
233 | ------------- | |
234 | ||
235 | <?php global $wp_query; | |
236 | $big = 999999999; // need an unlikely integer | |
237 | echo paginate_links( array( | |
238 | 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), | |
239 | 'format' => '?paged=%#%', | |
240 | 'current' => max( 1, get_query_var('paged') ), | |
241 | 'total' => $wp_query->max_num_pages | |
242 | ) ); | |
243 | ?> | |
244 | ||
245 | ||
246 | <?php $args = array( | |
247 | 'base' => '%_%', | |
248 | 'format' => '?page=%#%', | |
249 | 'total' => 1, | |
250 | 'current' => 0, | |
251 | 'show_all' => False, | |
252 | 'end_size' => 1, | |
253 | 'mid_size' => 2, | |
254 | 'prev_next' => True, | |
255 | 'prev_text' => __('« Previous'), | |
256 | 'next_text' => __('Next »'), | |
257 | 'type' => 'plain', | |
258 | 'add_args' => False, | |
259 | 'add_fragment' => '' | |
260 | ); ?> | |
261 | ||
262 | ||
263 | ||
264 | ======================================================================================= | |
265 | [single.php] | |
266 | ======================================================================================= | |
267 | <?php if(have_posts()) : while(have_posts()) : the_post(); ?> | |
268 | ||
269 | <h2><?php the_title(); ?></h2> | |
270 | <?php the_content(); ?> | |
271 | <?php comments_template( '', true ); ?> | |
272 | ||
273 | <?php endwhile; else : ?> | |
274 | <h3><?php _e('404 Error: Not Found'); ?></h3> | |
275 | <?php endif; ?> | |
276 | ||
277 | ||
278 | ||
279 | ||
280 | ||
281 | ||
282 | ======================================================================================= | |
283 | [archive.php] | |
284 | ======================================================================================= | |
285 | <h1> | |
286 | <?php if (have_posts()) : ?> | |
287 | <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?> | |
288 | <?php /* If this is a category archive */ if (is_category()) { ?> | |
289 | <?php _e('Archive for the'); ?> '<?php echo single_cat_title(); ?>' <?php _e('Category'); ?> | |
290 | <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?> | |
291 | <?php _e('Archive for the'); ?> <?php single_tag_title(); ?> Tag | |
292 | <?php /* If this is a daily archive */ } elseif (is_day()) { ?> | |
293 | <?php _e('Archive for'); ?> <?php the_time('F jS, Y'); ?> | |
294 | <?php /* If this is a monthly archive */ } elseif (is_month()) { ?> | |
295 | <?php _e('Archive for'); ?> <?php the_time('F, Y'); ?> | |
296 | <?php /* If this is a yearly archive */ } elseif (is_year()) { ?> | |
297 | <?php _e('Archive for'); ?> <?php the_time('Y'); ?> | |
298 | <?php /* If this is a search */ } elseif (is_search()) { ?> | |
299 | <?php _e('Search Results'); ?> | |
300 | <?php /* If this is an author archive */ } elseif (is_author()) { ?> | |
301 | <?php _e('Author Archive'); ?> | |
302 | <?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?> | |
303 | <?php _e('Blog Archives'); ?> | |
304 | <?php } ?> | |
305 | </h1> | |
306 | <?php if(have_posts()) : while(have_posts()) : the_post(); ?> | |
307 | ||
308 | <div class="index_post"> | |
309 | <a href="<?php the_permalink()?>"><h2><?php the_title()?></h2></a> | |
310 | <div class="single_post_item"> | |
311 | <?php the_content(); ?> | |
312 | </div> | |
313 | </div> | |
314 | ||
315 | <?php endwhile; endif; ?> | |
316 | <?php else : ?> | |
317 | <h3><?php _e('404 Error: Not Found'); ?></h3> | |
318 | <?php endif; ?> | |
319 | ||
320 | ||
321 | ||
322 | ||
323 | ||
324 | ||
325 | ======================================================================================= | |
326 | [404.php] | |
327 | ======================================================================================= | |
328 | ||
329 | <h2>404 Error: Not Found</h2> | |
330 | <p>Sorry, but the page you are trying to reach is unavailable or does not exist.</p> | |
331 | ||
332 | ||
333 | ||
334 | ||
335 | ||
336 | ||
337 | ======================================================================================= | |
338 | [functions.php] /*----- FEATURED IMAGE SUPPORT ------*/ | |
339 | ======================================================================================= | |
340 | ||
341 | add_theme_support( 'post-thumbnails', array( 'post', 'slider-image' ) ); | |
342 | add_image_size( 'post-image', 150, 150, true ); | |
343 | set_post_thumbnail_size( 200, 200, true ); | |
344 | ||
345 | ||
346 | //calling featured image | |
347 | <?php the_post_thumbnail('post_thumb', array('class' => 'post_thumb')); ?> | |
348 | <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID ), 'slider-thumb' ); echo $image[0]; ?> | |
349 | ||
350 | ||
351 | ||
352 | ||
353 | ||
354 | ||
355 | ======================================================================================= | |
356 | /*----- POST EXCERPT ------*/ | |
357 | ======================================================================================= | |
358 | <p><?php echo wp_trim_words(get_the_content(), 25);?></p> | |
359 | ||
360 | ||
361 | ||
362 | functions.php [Read More] | |
363 | --------------------------- | |
364 | function excerpt($num) { | |
365 | $limit = $num+1; | |
366 | $excerpt = explode(' ', get_the_excerpt(), $limit); | |
367 | array_pop($excerpt); | |
368 | $excerpt = "<p>". implode(" ",$excerpt)." </p>"."<a href='" .get_permalink($post->ID) ." ' class='".readmore."'>Read More</a>"; | |
369 | echo $excerpt; | |
370 | } | |
371 | ||
372 | use in instead of <?php the_content?> of post-loop.php | |
373 | -------------------------------------------------------- | |
374 | <?php echo excerpt(50); ?> | |
375 | ||
376 | ||
377 | ||
378 | ||
379 | ||
380 | ||
381 | ======================================================================================= | |
382 | [functions.php] /*----- CUSTOM POST REGISTER ------*/ | |
383 | ======================================================================================= | |
384 | add_action( 'init', 'create_post_type' ); | |
385 | function create_post_type() { | |
386 | register_post_type( 'testimonial', | |
387 | array( | |
388 | 'labels' => array( | |
389 | 'name' => __( 'Testimonial' ), | |
390 | 'singular_name' => __( 'Testimonial' ), | |
391 | 'add_new' => __( 'Add New' ), | |
392 | 'add_new_item' => __( 'Add New Testimonial' ), | |
393 | 'edit_item' => __( 'Edit Testimonial' ), | |
394 | 'new_item' => __( 'New Testimonial' ), | |
395 | 'view_item' => __( 'View Testimonial' ), | |
396 | 'not_found' => __( 'Sorry, we couldn\'t find the Testimonial you are looking for.' ) | |
397 | ), | |
398 | 'public' => true, | |
399 | 'publicly_queryable' => true, | |
400 | 'exclude_from_search' => true, | |
401 | 'menu_position' => 14, | |
402 | 'has_archive' => true, | |
403 | 'hierarchical' => false, | |
404 | 'capability_type' => 'page', | |
405 | 'rewrite' => array( 'slug' => 'testimonial' ), | |
406 | 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail' ) | |
407 | ) | |
408 | ); | |
409 | } | |
410 | ||
411 | shortform | |
412 | ||
413 | add_action( 'init', 'create_post_type' ); | |
414 | function create_post_type() { | |
415 | register_post_type( 'testimonial', | |
416 | array( | |
417 | 'labels' => array( | |
418 | 'name' => __( 'Testimonial' ), | |
419 | 'singular_name' => __( 'Testimonial' ), | |
420 | 'add_new' => __( 'Add New' ), | |
421 | ), | |
422 | 'public' => true, | |
423 | 'has_archive' => true, | |
424 | 'rewrite' => array( 'slug' => 'testimonial' ), | |
425 | 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail' ) | |
426 | ) | |
427 | ); | |
428 | } | |
429 | ||
430 | ||
431 | ||
432 | ||
433 | ||
434 | ||
435 | ===================================================================================================== | |
436 | /*----- REGISTER CUSTOM TAXONOMY ------*/ | |
437 | ===================================================================================================== | |
438 | <?php | |
439 | function pages_taxonomy() { | |
440 | register_taxonomy( | |
441 | 'testimonial_cat', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces). | |
442 | 'testimonial', //post type name | |
443 | array( | |
444 | 'hierarchical' => true, | |
445 | 'label' => 'testimonial Category', //Display name | |
446 | 'query_var' => true, | |
447 | 'show_admin_column' => true, | |
448 | 'rewrite' => array( | |
449 | 'slug' => 'testimonial-category', // This controls the base slug that will display before each term | |
450 | 'with_front' => false // Don't display the category base before | |
451 | ) | |
452 | ) | |
453 | ); | |
454 | } | |
455 | add_action( 'init', 'pages_taxonomy'); | |
456 | ?> | |
457 | ||
458 | ||
459 | ||
460 | ||
461 | ||
462 | ||
463 | ======================================================================================= | |
464 | /*----- CUSTOM FIELD ------*/ | |
465 | ======================================================================================= | |
466 | Conditional | |
467 | ----------- | |
468 | <?php $c_field = get_post_meta($post->ID, 'icon', true); if($c_field) : ?> | |
469 | <?php echo $icon ?> | |
470 | <?php else : ?> | |
471 | Static Data | |
472 | <?php endif; ?> | |
473 | ||
474 | ||
475 | Display custom field if exists | |
476 | ------------------------------ | |
477 | <?php $image = get_post_meta($post->ID, 'url', true); if($image) : ?> | |
478 | <?php echo $image; ?> | |
479 | <?php endif; ?> | |
480 | ||
481 | ||
482 | ||
483 | ||
484 | ||
485 | ||
486 | ======================================================================================= | |
487 | [functions.php] /*----- DYNAMIC BACKGROUND ------*/ | |
488 | ======================================================================================= | |
489 | ||
490 | $defaults = array( | |
491 | 'default-color' => '#000', | |
492 | 'default-image' => '', | |
493 | 'wp-head-callback' => '_custom_background_cb', | |
494 | 'admin-head-callback' => '', | |
495 | 'admin-preview-callback' => '' | |
496 | ); | |
497 | add_theme_support( 'custom-background', $defaults ); | |
498 | ||
499 | ||
500 | [header.php] replace the <body> tag with | |
501 | --------------------------------------- | |
502 | <body <?php body_class(); ?>> | |
503 | ||
504 | ||
505 | ||
506 | ||
507 | ||
508 | ||
509 | ======================================================================================= | |
510 | [functions.php] /*----- ACTIVATE OPTION TREE ------*/ | |
511 | ======================================================================================= | |
512 | ||
513 | add_filter( 'ot_show_pages', '__return_false' ); | |
514 | add_filter( 'ot_show_new_layout', '__return_false' ); | |
515 | add_filter( 'ot_theme_mode', '__return_true' ); | |
516 | include_once( 'option-tree/ot-loader.php' ); | |
517 | include_once( 'inc/theme-options.php' ); | |
518 | include_once( 'inc/meta-boxes.php' ); | |
519 | ||
520 | ||
521 | GET OPTION TREE DATA | |
522 | --------------------------------------------------------------------------------------- | |
523 | <?php get_option_tree( 'facebook', '', 'true' ); ?> | |
524 | ||
525 | ---------------------------------------------------- | |
526 | ||
527 | <?php if ( function_exists( 'get_option_tree') ) : if( get_option_tree( 'your_tree_id') ) : ?> | |
528 | <?php get_option_tree( 'your_tree_id', '', 'true' ); ?> | |
529 | <?php else : ?> | |
530 | Your Default Data | |
531 | <?php endif; endif; ?> | |
532 | ||
533 | ||
534 | ||
535 | ||
536 | ||
537 | ||
538 | ======================================================================================= | |
539 | [functions.php] /*----- BREADCRUMB ------*/ | |
540 | ======================================================================================= | |
541 | function brightpage_the_breadcrumb() { | |
542 | if (!is_home()) { | |
543 | echo '<a href="'; | |
544 | echo home_url('home'); | |
545 | echo '">'; | |
546 | echo ('Home'); | |
547 | echo "</a> » "; | |
548 | if (is_single()) { | |
549 | the_title(''); | |
550 | if (is_single()) { | |
551 | echo ""; | |
552 | } | |
553 | } elseif (is_page()) { | |
554 | echo the_title(); | |
555 | } | |
556 | } | |
557 | } | |
558 | ||
559 | ||
560 | [page.php] | |
561 | -------- | |
562 | <?php brightpage_the_breadcrumb() ?> | |
563 | ||
564 | ||
565 | ||
566 | ||
567 | ||
568 | ======================================================================================= | |
569 | /*----- SMOF THEME OPTIONS FRAMEWORK ------*/ | |
570 | ======================================================================================= | |
571 | ||
572 | SMOF activation | |
573 | --------------- | |
574 | add admin folder into themes root directory | |
575 | ||
576 | require_once ('admin/index.php'); | |
577 | ||
578 | SMOF Options Framework use | |
579 | --------------------------- | |
580 | single data : | |
581 | <?php global $data; echo $data['your_option_id']; ?> | |
582 | ||
583 | conditional data : | |
584 | <?php global $data; if($data['your_option_id']): ?> | |
585 | <?php echo $data['your_option_id']; ?> | |
586 | <?php endif; ?> | |
587 | ||
588 | conditional data with default data : | |
589 | ||
590 | <?php global $data; if($data['your_option_id']): ?> | |
591 | <?php echo $data['your_option_id']; ?> | |
592 | <?php else: ?> | |
593 | My Default data | |
594 | <?php endif; ?> | |
595 | ||
596 | ||
597 | ||
598 | ||
599 | ||
600 | ||
601 | ||
602 | ===================================================================================================== | |
603 | /*----- REGISTER CUSTOM TAXONOMY ------*/ | |
604 | ===================================================================================================== | |
605 | <?php | |
606 | function pages_taxonomy() { | |
607 | register_taxonomy( | |
608 | 'pages_cat', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces). | |
609 | 'staff', //post type name | |
610 | array( | |
611 | 'hierarchical' => true, | |
612 | 'label' => 'Page Category', //Display name | |
613 | 'query_var' => true, | |
614 | 'rewrite' => array( | |
615 | 'slug' => 'staff-category', // This controls the base slug that will display before each term | |
616 | 'with_front' => false // Don't display the category base before | |
617 | ) | |
618 | ) | |
619 | ); | |
620 | } | |
621 | add_action( 'init', 'pages_taxonomy'); | |
622 | ?> | |
623 | ||
624 | ||
625 | ||
626 | ||
627 | ||
628 | ===================================================================================================== | |
629 | [funcitons.php] /*----- MOVE FEATURED IMAGES UNDER POST EDITOR IN DASHBOARD ------*/ | |
630 | ===================================================================================================== | |
631 | add_action('do_meta_boxes','change_image_box'); | |
632 | function change_image_box() { | |
633 | remove_meta_box('postimagediv', 'gallery-page', 'side'); | |
634 | add_meta_box('postimagediv', __('Upload Gallery Page Thumbnail.'), 'post_thumbnail_meta_box', 'gallery-page', 'normal', 'high'); | |
635 | } | |
636 | ||
637 | ||
638 | ||
639 | ||
640 | ||
641 | ||
642 | ||
643 | ===================================================================================================== | |
644 | [funcitons.php] /*----- BLOCK ACCESS IN DASBOARD EXCEPT ADMINISTRATOR ------*/ | |
645 | ===================================================================================================== | |
646 | add_action( 'admin_init', 'restrict_admin', 1 ); | |
647 | function restrict_admin(){ | |
648 | if ( ! current_user_can( 'manage_options' ) ) { | |
649 | wp_die( __('You are not allowed to access this part of the site') ); | |
650 | } | |
651 | } | |
652 | ||
653 | ||
654 | ||
655 | ||
656 | ||
657 | ||
658 | ||
659 | ||
660 | ===================================================================================================== | |
661 | [funcitons.php] /*----- HIDE DASHBOARD FOR ALL EXCEPT ADMINISTRATOR ------*/ | |
662 | ===================================================================================================== | |
663 | add_action('after_setup_theme', 'remove_admin_bar'); | |
664 | function remove_admin_bar() { | |
665 | if (!current_user_can('administrator', 'editor') && !is_admin()) { | |
666 | show_admin_bar(false); | |
667 | } | |
668 | } | |
669 | ||
670 | ||
671 | ||
672 | ||
673 | ||
674 | ||
675 | ||
676 | ||
677 | ||
678 | ||
679 | ||
680 | ===================================================================================================== | |
681 | [funcitons.php] /*----- REDIRECT AFTER LOGIN ------*/ | |
682 | ===================================================================================================== | |
683 | function redirect_after_login(){ | |
684 | return admin_url("admin.php?page=functions.php"); | |
685 | } | |
686 | add_filter("login_redirect", "redirect_after_login", 10, 3); | |
687 | ||
688 | ||
689 | ||
690 | ||
691 | ||
692 | ||
693 | ||
694 | ||
695 | ||
696 | ||
697 | ||
698 | ||
699 | ===================================================================================================== | |
700 | [funcitons.php] /*----- REDIRECT AFTER ACTIVATE THEME ------*/ | |
701 | ===================================================================================================== | |
702 | ||
703 | global $pagenow; | |
704 | if ( is_admin() && isset( $_GET['activated'] ) && $pagenow == 'themes.php' ) | |
705 | { | |
706 | wp_redirect( admin_url( 'admin.php?page=theme-settings-slug' ) ); | |
707 | exit; | |
708 | } | |
709 | ||
710 | ||
711 | ------------------------------------------------------------- | |
712 | ||
713 | if ($_GET['activated']){ wp_redirect(admin_url("admin.php?page=functions.php")); } | |
714 | ||
715 | ||
716 | ||
717 | ||
718 | ||
719 | ===================================================================================================== | |
720 | /*----- GET ONLY TOP LEVEL CATEGORIES AS LISTS ------*/ | |
721 | ===================================================================================================== | |
722 | ||
723 | <?php $args = array( | |
724 | 'orderby' => 'name', | |
725 | 'parent' => 0 | |
726 | ); | |
727 | $categories = get_categories( $args ); | |
728 | foreach ( $categories as $category ) { | |
729 | echo '<a href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a><br/>'; | |
730 | } | |
731 | ?> | |
732 | ||
733 | ||
734 | ||
735 | ||
736 | ||
737 | ||
738 | ||
739 | ||
740 | ||
741 | ||
742 | ===================================================================================================== | |
743 | /*----- SHOW ALL CATEGORIES AS LISTS ------*/ | |
744 | ===================================================================================================== | |
745 | <?php | |
746 | $category_ID = get_query_var('cat'); | |
747 | $args = array( | |
748 | 'meta_key' => 'price', | |
749 | 'orderby' => 'meta_value_num', | |
750 | 'order' => 'ASC', | |
751 | 'tax_query' => array( | |
752 | array( | |
753 | 'taxonomy' => 'product-category', | |
754 | 'field' => 'slug', | |
755 | 'terms' => $slug, | |
756 | 'child_of' => $category_ID, | |
757 | ) | |
758 | ) | |
759 | ); | |
760 | ||
761 | $categories = get_categories($args); | |
762 | foreach($categories as $category) { | |
763 | echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> '; | |
764 | echo '<p> Description:'. $category->description . '</p>'; | |
765 | echo '<p> Post Count: '. $category->count . '</p>'; } | |
766 | ?> | |
767 | ||
768 | ||
769 | ||
770 | ||
771 | ||
772 | ||
773 | ===================================================================================================== | |
774 | /*----- GET ONLY TOP LEVEL CATEGORIES FROM CUSTOM POST ------*/ | |
775 | ===================================================================================================== | |
776 | ||
777 | <?php | |
778 | $customPostTaxonomies = get_object_taxonomies('product'); | |
779 | if(count($customPostTaxonomies) > 0) | |
780 | { foreach($customPostTaxonomies as $tax) | |
781 | { $args = array( | |
782 | 'orderby' => 'name', | |
783 | 'show_count' => 0, | |
784 | 'pad_counts' => 0, | |
785 | 'parent' => 0, | |
786 | 'hierarchical' => 1, | |
787 | 'taxonomy' => $tax, | |
788 | 'title_li' => '' | |
789 | ); | |
790 | wp_list_categories( $args ); | |
791 | } | |
792 | } | |
793 | ?> | |
794 | ||
795 | ||
796 | ||
797 | ||
798 | ||
799 | ||
800 | ||
801 | ||
802 | ||
803 | ===================================================================================================== | |
804 | /*----- IS USER LOGGED IN ------*/ | |
805 | ===================================================================================================== | |
806 | <?php if(is_user_logged_in()) : ?> | |
807 | <a href="<?php echo wp_logout_url( home_url() ); ?>" title="Logout">Logout</a> | |
808 | <?php else : ?> | |
809 | <a href="<?php echo wp_login_url( home_url() ); ?>" title="Login">Login</a> or <a href="<?php echo wp_registration_url(); ?>" title="Register">Register</a> | |
810 | <?php endif; ?> | |
811 | ||
812 | ||
813 | ||
814 | ||
815 | ||
816 | ||
817 | ||
818 | ||
819 | ||
820 | ||
821 | ||
822 | ||
823 | ||
824 | ||
825 | ===================================================================================================== | |
826 | /*----- UPLOAD FLASH FILE (.SWF) IN WORDPRESS ------*/ | |
827 | ===================================================================================================== | |
828 | WordPress do not support flash files MIME type. If you still want to upload flash file (.swf) in WordPress then you have to apply a filter in wordpress ‘upload_mimes’ | |
829 | Just add the bellow filter in your FUNCTIONS.PHP file : | |
830 | ||
831 | function demo($mimes) { | |
832 | if ( function_exists( 'current_user_can' ) ) | |
833 | $unfiltered = $user ? user_can( $user, 'unfiltered_html' ) : current_user_can( 'unfiltered_html' ); | |
834 | if ( !empty( $unfiltered ) ) { | |
835 | $mimes['swf'] = 'application/x-shockwave-flash'; | |
836 | } | |
837 | return $mimes; | |
838 | } | |
839 | add_filter('upload_mimes','demo'); | |
840 | ||
841 | ||
842 | ||
843 | ||
844 | ||
845 | ||
846 | ||
847 | ||
848 | ||
849 | ||
850 | ||
851 | ||
852 | ===================================================================================================== | |
853 | /*----- META BOX WITH PLUGIN ------*/ | |
854 | ===================================================================================================== | |
855 | /*-------------------------- meta box activate ----------------------------- */ | |
856 | // put meta-box folder in theme directory | |
857 | // Re-define meta box path and URL | |
858 | define( 'RWMB_URL', trailingslashit( get_stylesheet_directory_uri() . '/meta-box' ) ); | |
859 | define( 'RWMB_DIR', trailingslashit( STYLESHEETPATH . '/meta-box' ) ); | |
860 | // Include the meta box script | |
861 | require_once RWMB_DIR . 'meta-box.php'; | |
862 | ||
863 | ||
864 | ||
865 | ||
866 | /*-------------------------- adding meta box ----------------------------- */ | |
867 | add_action( 'admin_init', 'rw_register_meta_box' ); | |
868 | function rw_register_meta_box(){ | |
869 | // Check if plugin is activated or included in theme | |
870 | if ( !class_exists( 'RW_Meta_Box' ) ) | |
871 | return; | |
872 | ||
873 | $prefix = 'rw-'; | |
874 | ||
875 | $meta_box = array( | |
876 | 'id' => 'personal', | |
877 | 'title' => 'Personal Information', | |
878 | 'pages' => array( 'post', 'page', 'welcome' ), | |
879 | 'context' => 'normal', | |
880 | 'priority' => 'high', | |
881 | 'fields' => array( | |
882 | array( | |
883 | 'name' => 'Full name', | |
884 | 'id' => $prefix . 'calling_id', | |
885 | 'type' => 'text', | |
886 | 'class' => 'custom-class', | |
887 | ), | |
888 | ) | |
889 | ); | |
890 | new RW_Meta_Box( $meta_box ); | |
891 | } | |
892 | ||
893 | ||
894 | // fetching data in front=end | |
895 | <?php echo get_post_meta($post->ID, 'rw-page_editor', true);?> | |
896 | ||
897 | ||
898 | help: | |
899 | http://www.deluxeblogtips.com/meta-box/ | |
900 | ||
901 | ||
902 | ||
903 | ||
904 | ===================================================================================================== | |
905 | /*----- EXCLUDE CATEGORY FROM MAIN POST QUEIRY ------*/ | |
906 | ===================================================================================================== | |
907 | function excludeCat($query) { | |
908 | if ( $query->is_home ) { | |
909 | $query->set('cat', '-3,-5,-23'); | |
910 | } | |
911 | return $query; | |
912 | } | |
913 | add_filter('pre_get_posts', 'excludeCat'); | |
914 | ||
915 | ||
916 | ||
917 | ||
918 | ||
919 | ||
920 | ||
921 | ||
922 | ||
923 | ===================================================================================================== | |
924 | /*----- Attach a navigation menu to the admin bar ------*/ | |
925 | ===================================================================================================== | |
926 | add_action( 'admin_bar_menu', 'wpse15186_admin_bar_menu' ); | |
927 | function wpse15186_admin_bar_menu( &$wp_admin_bar ){ | |
928 | $menu = wp_get_nav_menu_object( 'WPSE 15186 test menu' ); | |
929 | $menu_items = wp_get_nav_menu_items( $menu->term_id ); | |
930 | $wp_admin_bar->add_menu( array( | |
931 | 'id' => 'wpse15186-menu-0', | |
932 | 'title' => 'WPSE 15186 menu', | |
933 | ) ); | |
934 | foreach ( $menu_items as $menu_item ) { | |
935 | $wp_admin_bar->add_menu( array( | |
936 | 'id' => 'wpse15186-menu-' . $menu_item->ID, | |
937 | 'parent' => 'wpse15186-menu-' . $menu_item->menu_item_parent, | |
938 | 'title' => $menu_item->title, | |
939 | 'href' => $menu_item->url, | |
940 | 'meta' => array( | |
941 | 'title' => $menu_item->attr_title, | |
942 | 'target' => $menu_item->target, | |
943 | 'class' => implode( ' ', $menu_item->classes ), | |
944 | ), | |
945 | ) ); | |
946 | } | |
947 | } | |
948 | ||
949 | ||
950 | ||
951 | ||
952 | ||
953 | ||
954 | ||
955 | ||
956 | ===================================================================================================== | |
957 | /*----- [FUNCTIONS.PHP] Redirect back to referring page after login ------*/ | |
958 | ===================================================================================================== | |
959 | if ( (isset($_GET['action']) && $_GET['action'] != 'logout') || (isset($_POST['login_location']) && !empty($_POST['login_location'])) ) { | |
960 | add_filter('login_redirect', 'my_login_redirect', 10, 3); | |
961 | function my_login_redirect() { | |
962 | $location = $_SERVER['HTTP_REFERER']; | |
963 | wp_safe_redirect($location); | |
964 | exit(); | |
965 | } | |
966 | } | |
967 | ||
968 | ||
969 | ||
970 | ||
971 | ||
972 | ||
973 | ||
974 | ||
975 | ||
976 | ===================================================================================================== | |
977 | /*----- Add a login link to the wp_nav_menu ------*/ | |
978 | ===================================================================================================== | |
979 | add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2); | |
980 | function add_login_logout_link($items, $args) { | |
981 | $loginoutlink = wp_loginout('index.php', false); | |
982 | $items .= '<li>'. $loginoutlink .'</li>'; | |
983 | return $items; | |
984 | } | |
985 | ||
986 | ||
987 | ||
988 | ||
989 | ||
990 | ||
991 | ||
992 | ||
993 | ||
994 | ===================================================================================================== | |
995 | /*----- How to Display Only Child Category in your WordPress Post Loop ------*/ | |
996 | ===================================================================================================== | |
997 | //To display only Child Category in the post loop (mostly single.php), all you have to do is replace the following code: | |
998 | <?php the_category(', '); ?> | |
999 | //with this code: | |
1000 | <?php | |
1001 | foreach((get_the_category()) as $childcat) { | |
1002 | if (cat_is_ancestor_of(10, $childcat)) { | |
1003 | echo '<a href="'.get_category_link($childcat->cat_ID).'">'; | |
1004 | echo $childcat->cat_name . '</a>'; | |
1005 | }} | |
1006 | ?> | |
1007 | //Remember to change the number 10 to your parent category’s ID. | |
1008 | ||
1009 | ||
1010 | ||
1011 | ||
1012 | ||
1013 | ||
1014 | ||
1015 | ||
1016 | ||
1017 | ===================================================================================================== | |
1018 | /*----- creating theme customizer ------*/ | |
1019 | ===================================================================================================== | |
1020 | /* creating theme customizer */ | |
1021 | ||
1022 | function aman_theme_customizer ($wp_customize){ | |
1023 | $wp_customize->add_section('aman_colors', array( | |
1024 | 'title' => 'Color', | |
1025 | 'description' => 'Modify the theme colors', | |
1026 | )); | |
1027 | $wp_customize->add_setting('background_colors', array( | |
1028 | 'default' => '#0f7c01', | |
1029 | )); | |
1030 | $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'background_colors', array( | |
1031 | 'label' => 'Background Color', | |
1032 | 'section' => 'aman_colors', | |
1033 | 'settings' => 'background_colors', | |
1034 | ))); | |
1035 | } | |
1036 | add_action('customize_register','aman_theme_customizer'); | |
1037 | ||
1038 | ||
1039 | function aman_theme_custom_css(){ | |
1040 | ?> | |
1041 | <style type="text/css"> | |
1042 | body { background:<?php echo get_theme_mod('background_colors') ?> } | |
1043 | </style> | |
1044 | <?php | |
1045 | } | |
1046 | add_action('wp_head', 'aman_theme_custom_css'); | |
1047 | ||
1048 | ||
1049 | ||
1050 | ||
1051 | ||
1052 | ||
1053 | ||
1054 | Class list: | |
1055 | ||
1056 | WP_Customize_Control() | |
1057 | Creates a control that allows users to enter plain text. This is also the parent class for the classes that follow. | |
1058 | ||
1059 | WP_Customize_Color_Control() | |
1060 | Creates a control that allows users to select a color from a color wheel. | |
1061 | ||
1062 | WP_Customize_Upload_Control() | |
1063 | Creates a control that allows users to upload media. | |
1064 | ||
1065 | WP_Customize_Image_Control() | |
1066 | Creates a control that allows users to select or upload an image. | |
1067 | ||
1068 | WP_Customize_Background_Image_Control() | |
1069 | Creates a control that allows users to select a new background image. | |
1070 | ||
1071 | WP_Customize_Header_Image_Control() | |
1072 | Creates a control that allows users to select a new header image. | |
1073 | ||
1074 | ||
1075 | ||
1076 | ||
1077 | ||
1078 | ||
1079 | ||
1080 | ===================================================================================================== | |
1081 | /*----- ------*/ | |
1082 | ===================================================================================================== | |
1083 | ||
1084 | ||
1085 | ||
1086 | ||
1087 | ||
1088 | ||
1089 | ||
1090 | ||
1091 | ||
1092 | ||
1093 | ===================================================================================================== | |
1094 | /*----- ------*/ | |
1095 | ===================================================================================================== | |
1096 | ||
1097 | ||
1098 | ||
1099 | ||
1100 | ||
1101 | ||
1102 | ||
1103 | ||
1104 | ||
1105 | ||
1106 | ===================================================================================================== | |
1107 | /*----- ------*/ | |
1108 | ===================================================================================================== | |
1109 | ||
1110 | ||
1111 | ||
1112 | ||
1113 | ||
1114 | ||
1115 | ||
1116 | ||
1117 | ||
1118 | ||
1119 | ===================================================================================================== | |
1120 | /*----- ------*/ | |
1121 | ===================================================================================================== | |
1122 | ||
1123 | ?> |