Advertisement
darrenbachan

Untitled

Jun 4th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.85 KB | None | 0 0
  1. FUNCTIONS.PHP
  2.  
  3. function awesome_excerpt($text, $raw_excerpt) {
  4.         if( ! $raw_excerpt ) {
  5.             $content = apply_filters( 'the_content', get_the_content() );
  6.             $text = substr( $content, 0, strpos( $content, '</p>' ) + 4 );
  7.         }
  8.         $text = preg_replace("/<img[^>]+\>/i", "", $text);
  9.         return $text;
  10.     }
  11.     add_filter( 'wp_trim_excerpt', 'awesome_excerpt', 10, 2 );
  12.  
  13. -------------------------------------------------------------------------------------------------------
  14.  
  15. CONTENT-RECENT-POSTS.PHP, using get_template to pull it into two template files SINGLE.PHP and FRONT-PAGE.PHP
  16.  
  17. <?php
  18.     if ( is_single()) {
  19.         $categories = get_the_category();
  20.         if ($categories) {
  21.         foreach ($categories as $category) {
  22.             $cat = $category->cat_ID;
  23.             $args=array(
  24.             'cat' => $cat,
  25.             'order' => 'DESC',
  26.             'post__not_in' => array($post->ID),
  27.             'posts_per_page'=>2,
  28.             'caller_get_posts'=>1
  29.         );
  30.             $my_query = null;
  31.             $my_query = new WP_Query($args);
  32.                 if( $my_query->have_posts() ) {
  33.  
  34.         while ($my_query->have_posts()) : $my_query->the_post();
  35.     ?>
  36.    
  37.         <div class="col-md-6">
  38.             <div class="recent-blog-post-item">
  39.                 <?php if(has_post_thumbnail()) : ?>
  40.                     <div class="blog-post-featured-img">
  41.                         <a href="<?php the_permalink(); ?>">
  42.                             <?php the_post_thumbnail(); ?>
  43.                         </a>
  44.                     </div>
  45.                 <?php endif; ?>
  46.                
  47.                 <div class="blog-post-content recent-meta-text">
  48.                     <div class="recent-meta-title">
  49.                         <a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>">
  50.                             <h4><?php the_title(); ?></h4>
  51.                         </a>
  52.                     </div>
  53.                    
  54.  
  55.                     <div class="recent-meta-excerpt">
  56.                         <?php the_excerpt(); ?>
  57.                         <a class="read-more" href="<?php the_permalink(); ?>">Read More <i class="fa fa-long-arrow-right"></i></a>
  58.                     </div>
  59.                 </div> <!-- end recent meta text -->  
  60.             </div><!-- end recent blog post item -->
  61.         </div>
  62.      <?php
  63.     endwhile;
  64.                 }
  65.             }
  66.         } wp_reset_query();
  67.  
  68.     } else if(is_front_page()) {
  69.    
  70.         $args = array(
  71.             'order' => DESC,
  72.             'orderby' => 'date',
  73.             'posts_per_page'=>3,
  74.             'post_type' => 'post',
  75.             'caller_get_posts'=>1
  76.         );
  77.    
  78.         $my_query = new WP_Query($args);
  79.        
  80.         if( $my_query->have_posts() ) {
  81.      
  82.             while ($my_query->have_posts()) : $my_query->the_post();
  83.             ?>
  84.            
  85.             <div class="col-md-4">
  86.                 <div class="recent-blog-post-item">
  87.                     <?php if(has_post_thumbnail()) : ?>
  88.                         <div class="blog-post-featured-img">
  89.                             <a href="<?php the_permalink(); ?>">
  90.                                 <?php the_post_thumbnail(); ?>
  91.                             </a>
  92.                         </div>
  93.                     <?php endif; ?>
  94.                    
  95.                     <div class="blog-post-content recent-meta-text">
  96.                         <div class="recent-meta-title">
  97.                             <a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>">
  98.                                 <h4><?php the_title(); ?></h4>
  99.                             </a>
  100.                         </div>
  101.  
  102.                         <div class="recent-meta-excerpt">
  103.                             <?php the_excerpt(); ?>
  104.                             <a class="read-more" href="<?php the_permalink(); ?>">Read More <i class="fa fa-long-arrow-right"></i></a>
  105.                         </div>
  106.                     </div> <!-- end recent meta text -->  
  107.                 </div><!-- end recent blog post item -->
  108.             </div>
  109.              <?php
  110.             endwhile;
  111.         }
  112.     }
  113.     wp_reset_query();
  114. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement