cherryprodesign

WP cikkajánló

Jul 1st, 2016
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. function wpdocs_custom_excerpt_length( $length ) {
  2.     return 25;
  3. }
  4. add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 );
  5.  
  6. add_image_size( 'featured-post-image', 500 );
  7.  
  8. function wp_featuredposts($catID, $numberOfPost){
  9.     $args = array( 'posts_per_page' => $numberOfPost, 'offset'=> 0, 'category' => $catID, 'post_status' => 'publish' );
  10.     global $post;
  11.     $myposts = get_posts( $args );
  12.     ?>
  13.     <div class="featured-container">
  14.     <?php
  15.     foreach ( $myposts as $post ) : setup_postdata( $post )
  16.     ?>
  17.         <?php
  18.         $src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'featured-post-image' );
  19.         ?>
  20.         <div class="featured outer" style="background-image: url(<?php echo $src[0]; ?>); background-size: cover;">
  21.             <div class="featured inner">
  22.             <?php //var_dump($post); ?>
  23.                 <div class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
  24.                 <div class="excerpt">
  25.                 <?php the_excerpt(); ?>
  26.                 </div>
  27.             </div>
  28.         </div>
  29.     <?php endforeach;
  30.     wp_reset_postdata();
  31.     ?>
  32.     </div>
  33.     <?php
  34. }
  35.  
  36. add_filter( 'featuredposts', 'wp_featuredposts' );
  37. ?>
Add Comment
Please, Sign In to add comment