Guest User

Functions Code

a guest
Mar 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.62 KB | None | 0 0
  1. <?php
  2.  
  3. // =============================================================================
  4. // FUNCTIONS.PHP
  5. // -----------------------------------------------------------------------------
  6. // Overwrite or add your own custom functions to X in this file.
  7. // =============================================================================
  8.  
  9. // =============================================================================
  10. // TABLE OF CONTENTS
  11. // -----------------------------------------------------------------------------
  12. //   01. Enqueue Parent Stylesheet
  13. //   02. Additional Functions
  14. // =============================================================================
  15.  
  16. // Enqueue Parent Stylesheet
  17. // =============================================================================
  18.  
  19. add_filter( 'x_enqueue_parent_stylesheet', '__return_true' );
  20.  
  21.  
  22.  
  23. // Additional Functions
  24. // =============================================================================
  25.  
  26. // show portfolio items:
  27.  
  28. function x_shortcode_recent_posts2( $atts ) {
  29.   extract( shortcode_atts( array(
  30.     'id'          => '',
  31.     'class'       => '',
  32.     'style'       => '',
  33.     'type'        => '',
  34.     'count'       => '',
  35.     'category'    => '',
  36.     'offset'      => '',
  37.     'orientation' => '',
  38.     'no_image'    => '',
  39.     'fade'        => '',
  40.     'all_posts'   => ''
  41.   ), $atts, 'recent_posts' ) );
  42.  
  43.   $id            = ( $id          != ''          ) ? 'id="' . esc_attr( $id ) . '"' : '';
  44.   $class         = ( $class       != ''          ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf';
  45.   $style         = ( $style       != ''          ) ? 'style="' . $style . '"' : '';
  46.   $type          = ( $type        == 'portfolio' ) ? 'x-portfolio' : 'post';
  47.   $count         = ( $count       != ''          ) ? $count : 3;
  48.   $category      = ( $category    != ''          ) ? $category : '';
  49.   $category_type = ( $type        == 'post'      ) ? 'category_name' : 'portfolio-category';
  50.   $offset        = ( $offset      != ''          ) ? $offset : 0;
  51.   $orientation   = ( $orientation != ''          ) ? ' ' . $orientation : ' horizontal';
  52.   $no_image      = ( $no_image    == 'true'      ) ? $no_image : '';
  53.   $fade          = ( $fade        == 'true'      ) ? $fade : 'false';
  54.  
  55.   $js_params = array(
  56.     'fade' => ( $fade == 'true' )
  57.   );
  58.  
  59.   $data = x_generate_data_attributes( 'recent_posts', $js_params );
  60.  
  61.   $all_posts_class     = ( $all_posts   == 'true'      ) ? $all_posts_class .= ' all_posts' : '';
  62.  
  63.  
  64.   $output = "<div {$id} class=\"{$class}{$orientation}\" {$style} data-fade=\"{$fade}\">";
  65.  
  66.     if ( $all_posts   == 'true' ) {
  67.       $q = new WP_Query( array(
  68.             'orderby'          => 'date',
  69.             'post_type'        => "{$type}",
  70.             'posts_per_page'   => -1,
  71.             'offset'           => "{$offset}",
  72.             "{$category_type}" => "{$category}"
  73.           ) );
  74.     } else {
  75.       $q = new WP_Query( array(
  76.         'orderby'          => 'date',
  77.         'post_type'        => "{$type}",
  78.         'posts_per_page'   => "{$count}",
  79.         'offset'           => "{$offset}",
  80.         "{$category_type}" => "{$category}"
  81.       ) );
  82.     }
  83.  
  84.     if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();
  85.  
  86.       if ( $no_image == 'true' ) {
  87.         $image_output       = '';
  88.         $image_output_class = 'no-image';
  89.       } else {
  90.         $image_output       = '<div class="x-recent-posts-img">' . get_the_post_thumbnail( get_the_ID(), 'entry-cropped', NULL ) . '</div>';
  91.         $image_output_class = 'with-image';
  92.       }
  93.  
  94.       $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . $all_posts_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ) . '">'
  95.                  . '<article id="post-' . get_the_ID() . '" class="' . implode( ' ', get_post_class() ) . '">'
  96.                    . '<div class="entry-wrap">'
  97.                      . $image_output
  98.                      . '<div class="x-recent-posts-content">'
  99.                        . '<h3 class="h-recent-posts">' . get_the_title() . '</h3>'
  100.                        . '<span class="x-recent-posts-date">' . get_the_date() . '</span>'
  101.                      . '</div>'
  102.                    . '</div>'
  103.                  . '</article>'
  104.                . '</a>';
  105.  
  106.     endwhile; endif; wp_reset_postdata();
  107.  
  108.   $output .= '</div>';
  109.  
  110.   return $output;
  111. }
  112.  
  113. add_filter('init', function() {
  114.    remove_shortcode( 'recent_posts' );
  115.  
  116.    add_shortcode( 'recent_posts', 'x_shortcode_recent_posts2' );
  117. });
  118.  
  119. //end show portfolio items
Add Comment
Please, Sign In to add comment