Advertisement
srikat

functions.php

May 8th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.34 KB | None | 0 0
  1. // Conditionally break posts into 2 columns with featured posts on first page
  2. add_filter( 'post_class', 'be_archive_post_class' );
  3. function be_archive_post_class( $classes ) {
  4.  
  5.     if ( is_home() ) {
  6.         global $wp_query;
  7.         $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  8.  
  9.  
  10.         // Check if on first page of pagination
  11.         if ( 1 == $paged )  {
  12.  
  13.             if ( 1 >= $wp_query->current_post ) {
  14.                 // Don't add a class to first and second posts
  15.                 $classes[] = '';
  16.             } else {
  17.                 // Add .one-half to all posts besides first and second
  18.                 $classes[] = 'one-half';
  19.             }
  20.             // Skip the first and second posts and add .first to every other
  21.             if ( 0 == $wp_query->current_post % 2 ) {
  22.                 $classes[] = 'first';
  23.             }
  24.         } else {
  25.             // On all other pages add .one-half to all posts
  26.             $classes[] = 'one-half';
  27.  
  28.             // Add .first to every other post
  29.             if ( 0 == $wp_query->current_post % 2 ) {
  30.                 $classes[] = 'first';
  31.             }
  32.         }
  33.     }
  34.     return $classes;
  35.  
  36. }
  37.  
  38. add_action( 'genesis_before_loop', 'sk_custom_content_display' );
  39. /**
  40.  * Show full content for first 2 posts on first page
  41.  * and exerpts/content per Content Archives settings on paginated pages (second, third and so on..).
  42.  *
  43.  * Scope: Posts page and all archives.
  44.  *
  45.  * @author Sridhar Katakam
  46.  * @link   http://sridharkatakam.com/show-full-content-first-2-posts-first-page-posts-page-archives-genesis/
  47.  */
  48. function sk_custom_content_display() {
  49.     if ( is_home() && ! is_paged() ) {
  50.         add_filter( 'genesis_pre_get_option_content_archive_thumbnail', 'sk_return_zero' );
  51.         add_filter( 'genesis_pre_get_option_content_archive', 'sk_return_full' );
  52.         add_filter( 'genesis_pre_get_option_content_archive_limit', 'sk_return_zero' );
  53.     }
  54. }
  55.  
  56. function sk_return_zero() {
  57.     global $wp_query;
  58.  
  59.     if ( ( $wp_query->current_post <= 1 ) ) {
  60.         return '0';
  61.     }
  62. }
  63.  
  64. function sk_return_full() {
  65.     global $wp_query;
  66.  
  67.     if ( ( $wp_query->current_post <= 1 ) ) {
  68.         return 'full';
  69.     }
  70. }
  71.  
  72. add_action( 'pre_get_posts', 'be_change_event_posts_per_page' );
  73. /**
  74.  * Change Posts Per Page for Event Archive
  75.  *
  76.  * @author Bill Erickson
  77.  * @link http://www.billerickson.net/customize-the-wordpress-query/
  78.  * @param object $query data
  79.  *
  80.  */
  81. function be_change_event_posts_per_page( $query ) {
  82.  
  83.     if( $query->is_main_query() && !is_admin() && is_home() ) {
  84.         $query->set( 'posts_per_page', '8' );
  85.     }
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement