Services loop
Fri Mar 31 2023 11:52:05 GMT+0000 (Coordinated Universal Time)
Saved by @hamzahanif192
function create_service()
{
$labels = array(
'name' => _x('Service', 'Post Type General Name', 'textdomain'),
'singular_name' => _x('Service ', 'Post Type Singular Name', 'textdomain'),
'menu_name' => _x('Service', 'Admin Menu text', 'textdomain'),
'name_admin_bar' => _x('Service ', 'Add New on Toolbar', 'textdomain'),
'archives' => __('Service Archives', 'textdomain'),
'attributes' => __('Service Attributes', 'textdomain'),
'parent_item_colon' => __('Parent Service :', 'textdomain'),
'all_items' => __('All Service', 'textdomain'),
'add_new_item' => __('Add New Service ', 'textdomain'),
'add_new' => __('Add New', 'textdomain'),
'new_item' => __('New Service ', 'textdomain'),
'edit_item' => __('Edit Service ', 'textdomain'),
'update_item' => __('Update Service ', 'textdomain'),
'view_item' => __('View Service ', 'textdomain'),
'view_items' => __('View Service', 'textdomain'),
'search_items' => __('Search Service ', 'textdomain'),
'not_found' => __('Not found', 'textdomain'),
'not_found_in_trash' => __('Not found in Trash', 'textdomain'),
'featured_image' => __('Featured Image', 'textdomain'),
'set_featured_image' => __('Set featured image', 'textdomain'),
'remove_featured_image' => __('Remove featured image', 'textdomain'),
'use_featured_image' => __('Use as featured image', 'textdomain'),
'insert_into_item' => __('Insert into Service ', 'textdomain'),
'uploaded_to_this_item' => __('Uploaded to this Service ', 'textdomain'),
'items_list' => __('Service list', 'textdomain'),
'items_list_navigation' => __('Service list navigation', 'textdomain'),
'filter_items_list' => __('Filter Service list', 'textdomain'),
);
$rewrite = array(
'slug' => 'service',
'with_front' => true,
'pages' => true,
'feeds' => true,
);
$args = array(
'label' => __('Service ', 'textdomain'),
'description' => __('', 'textdomain'),
'labels' => $labels,
'menu_icon' => 'dashicons-admin-appearance',
'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'page-attributes', 'post-formats', 'custom-fields'),
'taxonomies' => array(),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'hierarchical' => true,
'exclude_from_search' => true,
'show_in_rest' => true,
'publicly_queryable' => true,
'capability_type' => 'post',
'rewrite' => $rewrite,
);
register_post_type('service', $args);
register_taxonomy('service_category', 'service', array('hierarchical' => true, 'label' => 'Category', 'query_var' => true, 'rewrite' => array('slug' => 'service-category')));
}
add_action('init', 'create_service', 0);
function service_loop()
{
$arg = array(
'post_type' => 'service',
'posts_per_page' => -1,
);
$servicePost = new WP_Query($arg);
?>
<div id="mainService">
<?php if ($servicePost->have_posts()) : ?>
<?php while ($servicePost->have_posts()) : ?>
<?php $servicePost->the_post();
$content= get_the_content();
?>
<div class="single-service">
<?php the_post_thumbnail( 'full', array( 'class' => 'service' ) ); ?>
<div class="contentArea">
<h2><?php the_title(); ?></h2>
<p><?php echo substr($content, 0, 180); ?>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php
wp_reset_postdata();
}
add_shortcode('mainService', 'service_loop');



Comments