Advertisement
romimitu

sortcode

Nov 14th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.68 KB | None | 0 0
  1. <?php
  2. /* create recent post ********************************************/
  3. function create_post_type() {
  4.  
  5. register_post_type( 'services',
  6. array(
  7. 'labels' => array(
  8. 'name' => __( 'our services' ),
  9. 'singular_name' => __( 'our services' ),
  10. 'add_new' => __( 'Add New' ),
  11. 'add_new_item' => __( 'Add our service' ),
  12. 'edit_item' => __( 'Edit service' ),
  13. 'new_item' => __( 'New service' ),
  14. 'view_item' => __( 'View our service' ),
  15. 'not_found' => __( 'Sorry, we couldn\'t find the home our services you are looking for.' )
  16. ),
  17. 'public' => true,
  18. 'publicly_queryable' => true,
  19. 'exclude_from_search' => true,
  20. 'menu_position' => 14,
  21. 'has_archive' => true,
  22. 'hierarchical' => true,
  23. 'capability_type' => 'post',
  24. 'rewrite' => array( 'slug' => 'service' ),
  25. 'supports' => array( 'title', 'editor', 'thumbnail' )
  26. )
  27. );
  28.  
  29. register_post_type( 'recent-works',
  30. array(
  31. 'labels' => array(
  32. 'name' => __( 'recent work' ),
  33. 'singular_name' => __( 'recent work' ),
  34. 'add_new' => __( 'Add New' ),
  35. 'add_new_item' => __( 'Add New recent work' ),
  36. 'edit_item' => __( 'Edit recent work' ),
  37. 'new_item' => __( 'New recent work' ),
  38. 'view_item' => __( 'View recent work' ),
  39. 'not_found' => __( 'Sorry, we couldn\'t find the recent works you are looking for.' )
  40. ),
  41. 'public' => true,
  42. 'publicly_queryable' => true,
  43. 'exclude_from_search' => true,
  44. 'menu_position' => 14,
  45. 'has_archive' => true,
  46. 'hierarchical' => true,
  47. 'capability_type' => 'post',
  48. 'rewrite' => array( 'slug' => 'recent-work' ),
  49. 'supports' => array( 'title', 'editor', 'thumbnail' )
  50. )
  51. );
  52.  
  53. }
  54. add_action( 'init', 'create_post_type' );
  55.  
  56.  
  57.  
  58.  
  59. /************************sortcode register for recent works*********************************/
  60. function recent_works_post_shortcode($atts){
  61. extract( shortcode_atts( array(
  62. 'title' => '',
  63. 'category' => '',
  64. ), $atts, 'recent_works' ) );
  65.  
  66. $q = new WP_Query(
  67. array( 'recent_works_cat' => $category, 'posts_per_page' => '4', 'post_type' => 'recent-works')
  68. );
  69. $list = '<h2 class="recent_header">'.$title.'</h2><div class="portfolio">';
  70.  
  71. while($q->have_posts()) : $q->the_post();
  72. //get the ID of your post in the loop
  73. $id = get_the_ID();
  74.  
  75. $portfolio_link = get_post_meta($id, 'portfolio_link', true);
  76. $post_thumbnail= get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
  77. $list .= '
  78. <div class="work col-md-3">
  79. '.$post_thumbnail.'
  80. <h4>'.get_the_title().'</h4>
  81. <p>'.get_the_content().'</p>
  82. <div class="icon-awesome">
  83. <a href="'. get_permalink() .'" rel="prettyPhoto"><i class="fa fa-search"></i></a>
  84. <a href="'.$portfolio_link.'" target="_blank"><i class="fa fa-link"></i></a>
  85. </div>
  86. </div>
  87.  
  88.  
  89. ';
  90. endwhile;
  91. $list.= '</div>';
  92. wp_reset_query();
  93. return $list;
  94. }
  95. add_shortcode('recent_works', 'recent_works_post_shortcode');
  96.  
  97. /* recent_works_taxonomy ********************************************/
  98. function recent_works_taxonomy() {
  99. register_taxonomy(
  100. 'recent_works_cat', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
  101. 'recent-works', //post type name
  102. array(
  103. 'hierarchical' => true,
  104. 'label' => 'recent works Category', //Display name
  105. 'query_var' => true,
  106. 'show_admin_column' => true,
  107. 'rewrite' => array(
  108. 'slug' => 'recent-works-category', // This controls the base slug that will display before each term
  109. 'with_front' => false // Don't display the category base before
  110. )
  111. )
  112. );
  113. }
  114. add_action( 'init', 'recent_works_taxonomy');
  115.  
  116.  
  117. /************************sortcode register for our services *********************************/
  118. function our_services_shortcode($atts){
  119. extract( shortcode_atts( array(
  120. 'title' => '',
  121. 'category' => '',
  122. ), $atts, 'our_services' ) );
  123.  
  124. $q = new WP_Query(
  125. array( 'our_services_cat' => $category, 'posts_per_page' => '6', 'post_type' => 'services')
  126. );
  127. $list = '<div class="service_list">';
  128.  
  129. while($q->have_posts()) : $q->the_post();
  130. //get the ID of your post in the loop
  131. $id = get_the_ID();
  132.  
  133. $service_icon = get_post_meta($id, 'service_icon', true);
  134.  
  135. $list .= ' <div class="service col-md-4 col-sm-4">
  136.  
  137. <h3>'. get_the_title() .'</h3>
  138. <div class="icon_holder_service">
  139. <a href="'. get_permalink() .'" ><i class="fa fa-'.$service_icon.'"></i></a>
  140. </div>
  141. <p>'.get_the_content().'</p>
  142.  
  143. </div>
  144.  
  145. ';
  146. endwhile;
  147. $list.= '</div>';
  148. wp_reset_query();
  149. return $list;
  150. }
  151. add_shortcode('our_services', 'our_services_shortcode');
  152.  
  153.  
  154. /* our_services_taxonomy ********************************************/
  155. function our_services_taxonomy() {
  156. register_taxonomy(
  157. 'our_services_cat', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
  158. 'services', //post type name
  159. array(
  160. 'hierarchical' => true,
  161. 'label' => 'our services Category', //Display name
  162. 'query_var' => true,
  163. 'show_admin_column' => true,
  164. 'rewrite' => array(
  165. 'slug' => 'service-category', // This controls the base slug that will display before each term
  166. 'with_front' => false // Don't display the category base before
  167. )
  168. )
  169. );
  170. }
  171. add_action( 'init', 'our_services_taxonomy');
  172.  
  173.  
  174. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement