Advertisement
Guest User

Untitled

a guest
Aug 16th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.32 KB | None | 0 0
  1. <?php
  2.  
  3. /*--------------------------------------------------------------
  4. ## Register Custom Post Type
  5. --------------------------------------------------------------*/
  6. function ad_register_jobs_post_type() {
  7.  
  8.     $singular = 'Service';
  9.     $plural = 'Services';
  10.  
  11.     $labels = array(
  12.         'name'                  => $plural,
  13.         'singular_name'         => $singular,
  14.         'menu_name'             => $plural,
  15.         'name_admin_bar'        => $plural,
  16.         'archives'              => $singular . ' Archives',
  17.         'parent_item_colon'     => $singular,
  18.         'all_items'             => $plural,
  19.         'add_new_item'          => 'Add ' . $singular,
  20.         'add_new'               => 'Add ' . $singular,
  21.         'new_item'              => 'New ' . $singular,
  22.         'edit_item'             => 'Edit ' . $singular,
  23.         'update_item'           => 'Update ' . $singular,
  24.         'view_item'             => 'View ' . $singular,
  25.         'search_items'          => 'Search ' . $plural,
  26.         'not_found'             => 'No ' . $plural . ' Found',
  27.         'not_found_in_trash'    => 'No ' . $plural . ' Found In Trash',
  28.         'featured_image'        => __( 'Featured Image', 'text_domain' ),
  29.         'set_featured_image'    => __( 'Set Featured Image', 'text_domain' ),
  30.         'remove_featured_image' => __( 'Remove Featured Image', 'text_domain' ),
  31.         'use_featured_image'    => __( 'Use as Featured Image', 'text_domain' ),
  32.         'insert_into_item'      => 'Insert into ' . $singular,
  33.         'uploaded_to_this_item' => 'Uploaded to this ' . $singular,
  34.         'items_list'            => $singular . ' List',
  35.         'items_list_navigation' => $singular . ' List Navigation',
  36.         'filter_items_list'     => 'Filter ' . $singular . ' List',
  37.     );
  38.     $rewrite = array(
  39.         'slug'                  => 'services',
  40.         'with_front'            => false,
  41.         'pages'                 => true,
  42.         'feeds'                 => false,
  43.     );
  44.     $capabilities = array(
  45.         'edit_post'             => 'edit_service',
  46.         'read_post'             => 'read_service',
  47.         'delete_post'           => 'delete_service',
  48.         'edit_posts'            => 'edit_services',
  49.         'edit_others_posts'     => 'edit_others_services',
  50.         'publish_posts'         => 'publish_services',
  51.         'read_private_posts'    => 'read_private_services',
  52.         'create_posts'          => 'edit_services',
  53.     );
  54.     $company = 'Calm Trees Printing ';
  55.     $args = array(
  56.         'label'                 => $plural,
  57.         'description'           => $company . $plural,
  58.         'labels'                => $labels,
  59.         'supports'              => array( 'title', 'thumbnail', 'editor' ),
  60.         // 'taxonomies'            => array( 'category', 'post_tag' ),
  61.         'hierarchical'          => false,
  62.         'public'                => true,
  63.         'show_ui'               => true,
  64.         'show_in_menu'          => true,
  65.         'menu_position'         => 5,
  66.         'menu_icon'             => 'dashicons-screenoptions',
  67.         'show_in_admin_bar'     => true,
  68.         'show_in_nav_menus'     => true,
  69.         'can_export'            => true,
  70.         'has_archive'           => false,      
  71.         'exclude_from_search'   => true,
  72.         'publicly_queryable'    => true,
  73.         // 'query_var'             => 'links',
  74.         'capability_type'       => 'post',
  75.         'rewrite'               => $rewrite,
  76.         // 'capabilities'          => $capabilities,
  77.     );
  78.     register_post_type( 'ctp_services', $args );
  79.  
  80. }
  81. add_action( 'init', 'ad_register_jobs_post_type', 0 );
  82.  
  83. /*--------------------------------------------------------------
  84. ## Home Page
  85. --------------------------------------------------------------*/
  86. function ctp_services() {
  87.     $args = array(
  88.         'post_type'   =>  'ctp_services',
  89.         'post_status' => 'publish',
  90.         'posts_per_page' => -1,
  91.         // 'orderby' => 'rand',
  92.         'order' => 'ASC',
  93.     );
  94.  
  95.     $services = new WP_Query( $args );
  96.  
  97.     if ( $services->have_posts() ) :
  98.  
  99.         $html_out = '';
  100.  
  101.         $html_out .= '<section class="services">';
  102.             $html_out .= '<div class="container">';
  103.                 $html_out .= '<div class="row">';
  104.                     // $html_out .= '<div class="ctp-col col-xs-10">';
  105.  
  106.                     while ($services->have_posts()) : $services->the_post();  
  107.  
  108.                         $title = get_the_title();
  109.                         $content = apply_filters( 'the_content', get_the_content() );
  110.                         $link = get_the_permalink();
  111.                         $icon = get_field('service_icon');
  112.  
  113.                         // Output Services Here
  114.                         $html_out .= '<div class="service-col">'; //col-xs-12 col-sm-4 col-md-2
  115.  
  116.                         if( $title ):
  117.                             $html_out .= '<a href="' . $link . '">';
  118.                                 $html_out .='<div class="service-item">';
  119.                                     if( $icon ):
  120.                                         $html_out .= '<div class="service-icon">';
  121.                                             $html_out .= '<img src="' . $icon . '" alt="' . $title . '" class="style-svg" />';
  122.                                         $html_out .= '</div>'; // service-icon
  123.                                     endif;
  124.                                     $html_out .= '<h4>' . $title . '</h4>';
  125.                                     // $html_out .= $content;
  126.                                 $html_out .= '</div>'; // service-item
  127.                             $html_out .= '</a>';
  128.                         endif;
  129.  
  130.                         $html_out .= '</div>'; // service-col
  131.                          
  132.                     endwhile;
  133.  
  134.                     // $html_out .= '</div>'; // col
  135.                 $html_out .= '</div>'; // row
  136.             $html_out .= '</div>';  // service-type
  137.         $html_out .= '</section>'; // services 
  138.  
  139.     else : // No results
  140.         $html_out = "No Services Found.";
  141.     endif;
  142.  
  143.     wp_reset_postdata();
  144.  
  145.     return $html_out;
  146. }
  147. add_shortcode('all_services', 'ctp_services');
  148.  
  149.  
  150. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement