shortcodes.php 10.7 KB
<?php 
function promos()
{
    $custom_args = array(
        'post_type' => 'promo',
        'posts_per_page' => 3,
        'paged' => 1,
    );
    $custom_query = new \WP_Query($custom_args);
      
    ob_start(); 
   $uniqid = uniqid();
    if ($custom_query->have_posts()):?>
    <div class="carousel">
    <div id="<?php echo  $uniqid; ?>" class="promo-carousel carousel-items">
        <div class='swiper-wrapper'>
                <?php while ($custom_query->have_posts()): $custom_query->the_post();
                    $id = get_the_ID();
                    $post = get_post($id);
                    $link = get_permalink($id);
                    if ($custom_link = get_post_meta($id, 'link', true)) {
                        $link = $custom_link;
                    }
                    $link_text = "Read More...";
                    if ($custom_link_text = get_post_meta($id, 'link_text', true)) {
                        $link_text = $custom_link_text;
                    }
                    $text = strip_shortcodes($post->post_content);
                    $text = apply_filters( 'the_content', $text );
                    $text = str_replace(']]>', ']]&gt;', $text);

                    $excerpt_length = apply_filters( 'excerpt_length', 40 );
                    $text = wp_trim_words( $text, $excerpt_length, ' ...' );
                    ?>
                         <div class="swiper-slide container">  
                            <div class="promo row align-items-center">
                                <div class="col-lg-4 col-md-12">
                                <div class="promo-img">
                                    <?php echo get_the_post_thumbnail($id, 'full' ); ?>
                                    <div class="promo-img-over"> </div>
                                </div>    
                                </div>
                                <div  class="promo_content col-lg-8 col-md-12">
                                    <?php  echo '<h3>'.$post->post_title.'</h3><p>'. $text.'</p>'; ?>
                                    <a class="promo-link" target="_blank" href="<?php echo $link; ?>" title="<?php the_title_attribute(); ?>"><?php echo  $link_text;?></a>
                                </div>
                            </div>
                        </div>
                <?php endwhile; ?> 
                </div>
                        <div class="swiper-pagination"></div>
                        <div class="swiper-button-prev" data-id="<?= $uniqid; ?>"></div>
                        <div class="swiper-button-next" data-id="<?= $uniqid; ?>"></div>
               </div>        
               </div>  
    <?php endif; ?>
    <?php  wp_reset_query(); ?>
   <?php $output = ob_get_clean();
 
     return $output;
}

add_shortcode( 'promos', 'promos' );



function share_this($atts)
{
    $atts = shortcode_atts(array(
        'post_id' => '',
    ), $atts, 'current-cover-articles');
    $post = get_post($atts['post_id']);
    ob_start();?>

<div class="custom-addtoany">
	<div class="shareIcons" id="shareRoundIcons<?php echo $post->post_name; ?>"></div>
</div>		
<script>
	jQuery(document).ready(function ($) {
		$("#shareRoundIcons<?php echo $post->post_name; ?>").jsSocials({
			url: "<?php echo site_url() . '/' . $post->post_name; ?>",
			text: ": <?php echo get_the_title($post->ID); ?>",
			showLabel: false,
			showCount: false,
			shares: ["facebook",  "twitter", "linkedin" ]
		});
	});
</script>
<?php
return ob_get_clean();
}

add_shortcode('share-this', 'share_this');




function course_list()
{
    $custom_args = array(
        'post_type' => 'sfwd-courses',
        'posts_per_page' => -1,
        'paged' => 1,
    );
    $custom_query = new \WP_Query($custom_args);
      
    ob_start(); 
   $uniqid = uniqid();
    if ($custom_query->have_posts()):?>
    <p><input type="text" class="quicksearch" placeholder="Search" /></p>

    <div class="button-group filters-button-group">
  <button class="button is-checked" data-filter="*">Clear</button>
  <button class="button" data-filter=".resilience-and-well-being">Resilience and Well-Being</button>
  <button class="button" data-filter=".leadership-and-teamwork">Leadership and Teamwork</button>
  <button class="button" data-filter=".clinical-skills">Clinical Skills</button>
  <button class="button" data-filter=".coaching-and-mentoring">Coaching and Mentoring</button>

 </div>
            <div class="grid">
                <?php while ($custom_query->have_posts()): $custom_query->the_post();  
                        $id = get_the_ID();
                        $post = get_post($id);
                        $link = get_permalink($id);
                        $text = strip_shortcodes($post->post_content);
                        $text = apply_filters( 'the_content', $text );
                        $text = str_replace(']]>', ']]&gt;', $text);
                        $excerpt_length = apply_filters( 'excerpt_length', 40 );
                        $text = wp_trim_words( $text, $excerpt_length, ' ...' );
                        $categories = get_the_terms( $id, 'ld_course_category' );
                        $cat ="";
                        foreach( $categories as $category ) { $cat .= " ".$category->slug; };
                        ?>
               <div class="element-item <?php echo $cat; ?> " data-category="<?php echo $cat; ?>">
            
                    <article id="post-<?php echo $id; ?>" class="post post-<?php echo $id; ?> sfwd-courses type-sfwd-courses status-publish has-post-thumbnail hentry ld_course_tag-online">
                            <div class="thumbnail"><div class="ribbon"><?php echo get_post_meta( $id, '_learndash_course_grid_custom_ribbon_text', true);?></div>
                                    <div class="image">
                                        <a href="<?php echo $link; ?>" rel="bookmark">
                                                <?php echo get_the_post_thumbnail($id, 'full' ); ?>                     
                                        </a>
                                    </div>
                            </div>
                            <div class="content">
                            <h3 class="entry-title"><a href="<?php echo $link; ?>"><?php echo $post->post_title; ?></a></h3>
                                <div class="entry-content">
                                    <p><?php echo $text; ?></p>
                                </div>
                                <div class="button"><a role="button" href="<?php echo $link; ?>" rel="bookmark"><?php echo get_post_meta( $id, '_learndash_course_grid_custom_button_text', true);?></a></div>
                            </div>
                    </article>
                </div>        
                <?php endwhile; ?>
            </div>  
    <?php endif; ?>
 <?php wp_reset_query(); ?>
<?php $output = ob_get_clean(); ?>
    <style>
 .thumbnail{
       line-height:1.428571429;
       background-color:#ffffff;
       border:1px solid #dddddd;
       border-radius:4px;
       -webkit-transition:all 0.2s ease-in-out;
       transition:all 0.2s ease-in-out;
       display:inline-block;
       max-width:100%;
       height:auto;
       display:block;
       position:relative;
       padding:0;
       margin:0;
   }
 .thumbnail .ribbon{
       background:#5cb85c;
       box-shadow:0 1px rgba(0,0,0,0.2);
       -moz-box-shadow:0 1px rgba(0,0,0,0.2);
       -webkit-box-shadow:0 1px rgba(0,0,0,0.2);
       color:#fff;
       text-shadow:0 1px rgba(0,0,0,0.3);
       position:absolute;
       font-size:14px;
       left:-8px;
       right: unset;
       top:10px;
       padding:3px 10px;
       z-index:2;
  border-radius: 0px;
       font-weight:bold;
   }
 .thumbnail .ribbon.enrolled{
       background:#428bca;
   }
 .thumbnail .ribbon:before{
       border:4px solid transparent;
       border-top:4px solid #348c34;
       border-right:4px solid #348c34;
       content:"";
       position:absolute;
       left:0;
       right: unset;
       border-radius: 0px;
       bottom:-8px;
   }
 .thumbnail .ribbon.enrolled:before{
       border-top:4px solid #357ebd;
       border-right:4px solid #357ebd;
   }
 .entry-title{
       margin:0!important;
   }
 .entry-content{
       margin-bottom:10px;
       padding:0;
   }
 .items-wrapper_button{
       margin:5px 0!important;
       width:100%;
   }
 .items-wrapper_button a{
       text-decoration:none!important;
       width:100%;
   }
 .thumbnail a.btn-primary{
       color:white;
   }
 .btn{
       display:inline-block;
       padding:6px 12px;
       margin-bottom:0;
       font-size:14px;
       font-weight:normal;
       line-height:1.428571429;
       text-align:center;
       vertical-align:middle;
       cursor:pointer;
       border:1px solid transparent;
       border-radius:4px;
       white-space:nowrap;
       -webkit-user-select:none;
       -moz-user-select:none;
       -ms-user-select:none;
       -o-user-select:none;
       user-select:none;
   }
 .btn:focus{
       outline:thin dotted #333;
       outline:5px auto -webkit-focus-ring-color;
       outline-offset:-2px;
   }
 .btn:hover,.learndash-course-grid .btn:focus{
       color:#333333;
       text-decoration:none;
   }
 .btn:active{
       outline:0;
       background-image:none;
       -webkit-box-shadow:inset 0 3px 5px rgba(0, 0, 0, 0.125);
       box-shadow:inset 0 3px 5px rgba(0, 0, 0, 0.125);
   }
 .btn-primary{
       color:#ffffff;
       background-color:#428bca;
       border-color:#357ebd;
   }
 .btn-primary:hover,.learndash-course-grid .btn-primary:focus,.learndash-course-grid .btn-primary:active{
       color:#ffffff;
       background-color:#3276b1;
       border-color:#285e8e;
   }
 .btn-primary:active{
       background-image:none;
   }
 .btn-primary{
       color:white;
       text-decoration:none;
   }
 .btn-primary:hover{
       color:white;
   }
 .thumbnail img{
       display:block;
       max-width:100%;
       width:100%;
       height:auto;
       margin-left:auto;
       margin-right:auto;
       box-shadow:none;
       max-height: 400px;
   }
 .thumbnail a,.learndash-course-grid .thumbnail a:hover{
       box-shadow:none;
   }
 .thumbnail .caption{
       padding:9px;
       color:#333333;
   }
 .thumbnail .caption a{
       text-decoration:none!important;
   }
 .thumbnail .caption p{
       float:none!important;
       margin:15px 0 0!important;
       width:100%!important;
   }

   .element-item {
  position: relative;
  float: left;
  width: calc(33% - 30px);
  height: 600px;
  margin: 5px;
  padding: 10px;

}

.element-item > * {
  margin: 0;
  padding: 0;
}
#load-more{
  float:right;
  margin:5px;
}
.hidden{visibility:hidden;
  width:0px!important;
  height:0px!important;
  margin:0px!important;
  padding:0px!important;
  }
</style>     
  <?php  return $output;
}


add_shortcode('course-list', 'course_list');