Custom Functions Wordpress.

 <?php 

/* Service Post Start */


function register_services_post_type() {


    $labels = array(

        'name'               => _x('Services', 'post type general name'),

        'singular_name'      => _x('Service', 'post type singular name'),

        'menu_name'          => _x('Services', 'admin menu'),

        'name_admin_bar'     => _x('Service', 'add new on admin bar'),

        'add_new'            => _x('Add New', 'service'),

        'add_new_item'       => __('Add New Service'),

        'new_item'           => __('New Service'),

        'edit_item'          => __('Edit Service'),

        'view_item'          => __('View Service'),

        'all_items'          => __('All Services'),

        'search_items'       => __('Search Services'),

        'not_found'          => __('No services found.'),

        'not_found_in_trash' => __('No services found in Trash.'),

    );


    $args = array(

        'labels'             => $labels,

        'description'        => __('A custom post type for services'),

        'public'             => true,

        'publicly_queryable' => true,

        'show_in_menu'       => true,

        'show_in_rest'       => true, // for Gutenberg or REST API

        'query_var'          => true,

        'rewrite'            => array('slug' => 'services'),

        'capability_type'    => 'post',

        'has_archive'        => true,

        'menu_position'      => 5,

        'supports'           => array('title', 'editor', 'thumbnail', 'excerpt', 'author', 'custom-fields', 'comments', 'revisions', 'post-formats'),

        'menu_icon'          => 'dashicons-hammer', // Dashicon icon

    );

    register_post_type('services', $args);

}

add_action('init', 'register_services_post_type');


function add_file_types_to_uploads($file_types){

     $new_filetypes = array();

     $new_filetypes['svg'] = 'image/svg';

     $file_types = array_merge($file_types, $new_filetypes );

     return $file_types; 

add_action('upload_mimes', 'add_file_types_to_uploads');


function wpb_service_shortcode() { 

global $post; 

$args = array('post_type'=> 'services', 'orderby' => 'ID', 'post_status' => 'publish', 'order' => 'DESC', 'posts_per_page' => -1 );

$result = new WP_Query( $args ); ?> 


<div class="container-fluid sermon pb-5">

            <div class="container py-5">

                <div class="row g-4 justify-content-center">

<?php if ( $result-> have_posts('seond_section') ) : 

while ( $result->have_posts('seond_section') ) : $result->the_post();

$featured_img_url = get_the_post_thumbnail_url(get_the_ID(), 'full');

$enquire_now = get_sub_field('enquire_now'); 

$contact = get_sub_field('button_contact');

?>

                    <div class="col-lg-4 col-xl-4 col-sm-12">

                        <div class="card sermon-item wow fadeIn" data-wow-delay="0.1s">

                            <div class="overflow-hidden pb-0">

                                <img src="<?php echo esc_url($featured_img_url); ?>" class="img-fluid w-100" alt="">

                            </div>

                            <div class="p-4 green-color text-white">

                                <a href="" class="d-inline-block h4 lh-sm mb-3 text-white"><?php echo the_title(); ?></a>

                                <p class="mb-0 text-white"><?php echo the_content(); ?></p>

                            </div>

                        </div>

                    </div>

<?php endwhile; 

endif; wp_reset_postdata(); ?>

                  

<div class="pt-4">

<?php if ( !empty($enquire_now) ) : ?>

<a href="<?php echo esc_url($enquire_now); ?>" class="btn btn-enquire py-2 px-4">All Services</a>

<?php endif; ?>


<?php if ( !empty($contact) ) : ?>

<a href="<?php echo esc_url($contact); ?>" class="btn contact">

Contact <i class="fa fa-angle-right text-white me-2"></i>

</a>

<?php endif; ?>

</div>

                </div>

            </div>

        </div>

 

<?php 

}

// register shortcode

add_shortcode('All-Services', 'wpb_service_shortcode');


wp_reset_postdata();


/* Service Post End */



function add_file_types_to_upload($file_types){

     $new_filetypes = array();

     $new_filetypes['svg'] = 'image/svg';

     $file_types = array_merge($file_types, $new_filetypes );

     return $file_types; 

add_action('upload_mimes', 'add_file_types_to_upload');


function wpb_blog_shortcode() { 

global $post; 

$args = array('post_type'=> 'post', 'orderby' => 'ID', 'post_status' => 'publish', 'order' => 'DESC', 'posts_per_page' => -1 );

$result = new WP_Query( $args );

?> 


<style>

.content {

  display: none;

}

#loadMore {

  width: 150px;

  color: #fff;

  display: block;

  text-align: center;

  margin: 20px auto;

  padding: 10px;

  border-radius: 10px;

  transition: .3s;

}

#loadMore:hover, #loadMore .fa-angle-down:hover {

  color: #000;

  background-color: #fff;

  text-decoration: none;

}


</style>

<div class="container-fluid sermon pb-5">

<div class="container py-5">

<div class="row g-4 justify-content-center ">

<?php if ( $result-> have_posts('seond_section') ) : 

while ( $result->have_posts('seond_section') ) : $result->the_post();

$featured_img_url = get_the_post_thumbnail_url(get_the_ID(), 'full');

$author_name = get_the_author();

$post_date = get_the_date('d M Y');

$reading_time = round(str_word_count(strip_tags(get_the_content())) / 200); // 200wpm

$author_id = get_the_author_meta('ID');

$author_image = get_field('profile_image', 'user_' . $author_id);

?>

<div class="col-lg-6 col-xl-4 content">

<div class="card sermon-item">

<div class="overflow-hidden pb-0">

<a href="<?php echo get_permalink( $post->ID ); ?>"> <img src="<?php echo $featured_img_url; ?>" class="img-fluid w-100" alt=""/></a>

</div>

<div class="p-4 green-color">

<?php foreach((get_the_category()) as $category) {

$postcat= $category->cat_ID;

$catname =$category->cat_name;

?>

<p class="fs-14 text-white poppins-semibold"><?php echo $catname;?> </p>

<?php } ?>

<h3><a href="<?php echo get_permalink( $post->ID ); ?>" class="f-height fs-24 poppins-bold text-white"><?php the_title(); ?></a></h3>

<div class="mb-0 fs-16 text-white arimo">

<?php $content = get_the_content(); 

if (!empty($content)) {

echo '<p>' . wp_trim_words($content, 10, '...') . '</p>';

} ?>

</div>

</div>

<div class="container pb-2">

<div class="row">

<div class="col-md-2 avatar-img">

<?php

$author_image = get_field('profile_image', 'user_' . $author_id);

if ( !empty($author_image) && is_array($author_image) ) {

echo '<img src="' . esc_url($author_image['url']) . '" alt="Author Avatar">';

} else {

echo get_avatar($author_id, 50);

}

?>

</div>

<div class="col-md-8">

<p class="fs-14 mb-1 text-white poppins-semibold"><?php echo esc_html($author_name); ?></p>

                                    <p class="fs-14 text-white arimo"><?php echo esc_html($post_date); ?> - <?php echo $reading_time; ?> min read</p>

</div>

</div>

</div>

</div>

</div>

<?php endwhile; endif; wp_reset_postdata(); ?>

</div>

<div class="row g-4 justify-content-center">

<div class="col-lg-12 col-xl-12">

<div class="pt-4 text-center">

<a href="#" id="loadMore" class="btn btn-enquire">View All <i class="fa fa-angle-down text-white me-2"></i></a>

</div>

</div>

</div>

</div>

</div>  

<script>

jQuery(document).ready(function(){

  jQuery(".content").slice(0, 3).show();

  jQuery("#loadMore").on("click", function(e){

    e.preventDefault();

    jQuery(".content:hidden").slice(0, 3).slideDown();

    if(jQuery(".content:hidden").length == 0) {

jQuery("#loadMore").hide();

     

    }

  });

})

</script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

<?php }

// register shortcode

add_shortcode('All-Blogs', 'wpb_blog_shortcode');

wp_reset_postdata();

/* Blog Post End */






/* Custom Post type Testimonial Slider start */


function testimonial_post_type() {

$supports = array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields', 'comments', 'revisions', 'post-formats', );

$labels = array(

'name' => _x('Testimonial Slider', 'plural'),

'singular_name' => _x('Testimonial Slider', 'singular'),

'menu_name' => _x('Testimonial Slider ', 'admin menu'),

'name_admin_bar' => _x('testimonial', 'admin bar'),

'add_new' => _x('Add New', 'add new'),

'add_new_item' => __('Add New testimonial'),

'new_item' => __('New testimonial'),

'edit_item' => __('Edit testimonial'),

'view_item' => __('View testimonial'),

'all_items' => __('All testimonial slides'),

'search_items' => __('Search testimonial'),

'not_found' => __('No testimonial found.'),

);

$args = array( 'supports' => $supports, 'labels' => $labels, 'public' => true, 'query_var' => true, 'rewrite' => array('slug' => 'testimonial'), 'has_archive' => true, 'hierarchical' => false, );

register_post_type('testimonial', $args);

}

add_action('init', 'testimonial_post_type');


/*Custom Post type Testimonial Slider end*/


function wpb_testimonial_shortcode() { 


?>

<div class="container-fluid testimonial py-5" style="background-repeat: no-repeat, no-repeat;background-image: url('<?php echo get_template_directory_uri(); ?>/assets/img/Content.jpg'); background-size: cover; ">

            <div class="container py-5">

              

                <div class="testimonial-carousel owl-carousel">

           <?php

global $post; 

$args = array('post_type' => 'testimonial', 'orderby' => 'date', 'order' => 'DESC' );

//print_r($args);echo '</pre>';

$the_query = new WP_Query($args);

if ($the_query->have_posts()) :

while ($the_query->have_posts()) :

$the_query->the_post();

$featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full'); 

$testimonial_name = get_field('testimonial_name'); 

$testimonial_positions = get_field('testimonial_positions');

$value = get_field('five_star_review');

?>

<div class="testimonial-item" data-dot="<img class='img-fluid' src='<?php echo $featured_img_url; ?>' alt=''>">

                        <div class="testimonial-inner text-center py-5">

                            <div class="text-center pb-4">

<?php 

if ($value == 1) {

?>

<div class="d-flex justify-content-center">

<i class="fas fa-star text-white"></i>

</div>

<?php 

} elseif ($value == 2) {

?>

<div class="d-flex justify-content-center">

<i class="fas fa-star text-white"></i>

<i class="fas fa-star text-white"></i>

</div>

<?php 

elseif ($value == 3) {

?>

<div class="d-flex justify-content-center">

<i class="fas fa-star text-white"></i>

<i class="fas fa-star text-white"></i>

<i class="fas fa-star text-white"></i>

</div>

<?php 

elseif ($value == 4) {

?>

<div class="d-flex justify-content-center">

<i class="fas fa-star text-white"></i>

<i class="fas fa-star text-white"></i>

<i class="fas fa-star text-white"></i>

<i class="fas fa-star text-white"></i>

</div>

<?php 

elseif ($value == 5) {

?>

<div class="d-flex justify-content-center">

<i class="fas fa-star text-white"></i>

<i class="fas fa-star text-white"></i>

<i class="fas fa-star text-white"></i>

<i class="fas fa-star text-white"></i>

<i class="fas fa-star text-white"></i>

</div>

<?php 

else {

}


?>

</div>

                            <p class="titles fs-24 text-white poppins-bold pb-3">" <?php echo the_title(); ?> "</p>

<div class="d-flex align-items-center justify-content-center mb-4">

                                <div class="testimonial-inner-img border border-white border-3 me-4" style="border-radius: 50%;">

                                    <img src="<?php echo $featured_img_url; ?>" class="img-fluid rounded-circle" alt="">

                                </div>

                                <div class="right-border">

                                    <h5 class="mb-2 text-white"><?php echo $testimonial_name; ?></h5>

                                    <p class="mb-0 text-white"><?php echo $testimonial_positions; ?></p>

                                </div>

                            </div>

                        </div>

                    </div>

<?php endwhile;

wp_reset_postdata();

endif; ?>

                    

                </div>

            </div>

        </div>

<?php

}

// register shortcode

add_shortcode('testimonial', 'wpb_testimonial_shortcode');






/* Custom Post type Client logo Slider start */


function client_post_type() {

$supports = array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields', 'comments', 'revisions', 'post-formats', );

$labels = array(

'name' => _x('Client Logo Slider', 'plural'),

'singular_name' => _x('Client Logo Slider', 'singular'),

'menu_name' => _x('Client Logo Slider ', 'admin menu'),

'name_admin_bar' => _x('client', 'admin bar'),

'add_new' => _x('Add New', 'add new'),

'add_new_item' => __('Add New client'),

'new_item' => __('New client'),

'edit_item' => __('Edit client'),

'view_item' => __('View client'),

'all_items' => __('All client slides'),

'search_items' => __('Search client'),

'not_found' => __('No client found.'),

);

$args = array( 'supports' => $supports, 'labels' => $labels, 'public' => true, 'query_var' => true, 'rewrite' => array('slug' => 'client'), 'has_archive' => true, 'hierarchical' => false, );

register_post_type('client', $args);

}

add_action('init', 'client_post_type');

/* Custom Post type Client logo Slider end */



function wpb_client_shortcode() { 


?>

<?php

global $post; 

$args = array('post_type' => 'client', 'orderby' => 'date', 'order' => 'DESC' );

//print_r($args);echo '</pre>';

$the_query = new WP_Query($args);

?>

<div class="container-fluid blacks pt-5 pb-5">

<div class="container pt-5 pb-5">

<div class="row g-4 justify-content-center">

<div class="col-lg-8 col-xl-8 col-lg-offset-2 col-xl-offset-2">

<?php

$logo_title = get_sub_field('client_logo_title');

$logo_description = get_sub_field('client_logo_description');

?>

<p class="fs-16 poppins-regular text-center text-white">

<?php echo $logo_title; 

?>

</p>

<h2 class="fs-48 poppins-bold text-center text-white">

<?php echo $logo_description; ?></h2>

</div>

</div>

</div>

   <section class="customer-logos slider pb-5">

   <?php if ($the_query->have_posts()) :

while ($the_query->have_posts()) :

$the_query->the_post();

$featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full'); ?>

   

      <div class="slide">

<img src="<?php echo $featured_img_url; ?>">

  </div>

  

<?php endwhile;

wp_reset_postdata();

endif; ?>

   </section>

</div>


<?php }


// register shortcode

add_shortcode('All-Client', 'wpb_client_shortcode');






// show breadcrumbs


function qt_custom_breadcrumbs() {

 

  $showOnHome = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show

  $delimiter = '&raquo;'; // delimiter between crumbs

  $home = 'Home'; // text for the 'Home' link

  $showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show

  $before = '<span class="current">'; // tag before the current crumb

  $after = '</span>'; // tag after the current crumb

 

  global $post;

  $homeLink = get_bloginfo('url');

 

  if (is_home() || is_front_page()) {

 

    if ($showOnHome == 1) echo '<div id="crumbs"><a href="' . $homeLink . '">' . $home . '</a></div>';

 

  } else {

 

    echo '<div id="crumbs"><a href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' ';

 

    if ( is_category() ) {

      $thisCat = get_category(get_query_var('cat'), false);

      if ($thisCat->parent != 0) echo get_category_parents($thisCat->parent, TRUE, ' ' . $delimiter . ' ');

      echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after;

 

    } elseif ( is_search() ) {

      echo $before . 'Search results for "' . get_search_query() . '"' . $after;

 

    } elseif ( is_day() ) {

      echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';

      echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';

      echo $before . get_the_time('d') . $after;

 

    } elseif ( is_month() ) {

      echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';

      echo $before . get_the_time('F') . $after;

 

    } elseif ( is_year() ) {

      echo $before . get_the_time('Y') . $after;

 

    } elseif ( is_single() && !is_attachment() ) {

      if ( get_post_type() != 'post' ) {

        $post_type = get_post_type_object(get_post_type());

        $slug = $post_type->rewrite;

        echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a>';

        if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after;

      } else {

        $cat = get_the_category(); $cat = $cat[0];

        $cats = get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');

        if ($showCurrent == 0) $cats = preg_replace("#^(.+)\s$delimiter\s$#", "$1", $cats);

        echo $cats;

        if ($showCurrent == 1) echo $before . get_the_title() . $after;

      }

 

    } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {

      $post_type = get_post_type_object(get_post_type());

      echo $before . $post_type->labels->singular_name . $after;

 

    } elseif ( is_attachment() ) {

      $parent = get_post($post->post_parent);

      $cat = get_the_category($parent->ID); $cat = $cat[0];

      echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');

      echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a>';

      if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after;

 

    } elseif ( is_page() && !$post->post_parent ) {

      if ($showCurrent == 1) echo $before . get_the_title() . $after;

 

    } elseif ( is_page() && $post->post_parent ) {

      $parent_id  = $post->post_parent;

      $breadcrumbs = array();

      while ($parent_id) {

        $page = get_page($parent_id);

        $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';

        $parent_id  = $page->post_parent;

      }

      $breadcrumbs = array_reverse($breadcrumbs);

      for ($i = 0; $i < count($breadcrumbs); $i++) {

        echo $breadcrumbs[$i];

        if ($i != count($breadcrumbs)-1) echo ' ' . $delimiter . ' ';

      }

      if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after;

 

    } elseif ( is_tag() ) {

      echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after;

 

    } elseif ( is_author() ) {

       global $author;

      $userdata = get_userdata($author);

      echo $before . 'Articles posted by ' . $userdata->display_name . $after;

 

    } elseif ( is_404() ) {

      echo $before . 'Error 404' . $after;

    }

 

    if ( get_query_var('paged') ) {

      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';

      echo __('Page') . ' ' . get_query_var('paged');

      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';

    }

 

    echo '</div>';

 

  }

} // end qt_custom_breadcrumbs()








Comments

Popular posts from this blog

Get Post Data From Simple Post custom shortcode

Top 20 Beautiful Pen For Writing

Fatal error: Maximum execution time of 300 seconds exceeded in C:\xampp\phpMyAdmin\libraries\classes\Dbi\DbiMysqli.php on line 199