Advertisement
srikat

Untitled

Jun 9th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. add_action( 'genesis_after_entry', 'sk_insert_post' );
  2. function sk_insert_post() {
  3.  
  4. global $wp_query;
  5.  
  6. if ( is_main_query() && is_home() && 0 == get_query_var( 'paged' ) && 0 == $wp_query->current_post ) {
  7. echo "string";
  8. }
  9.  
  10. }
  11.  
  12. add_action( 'pre_get_posts', 'myprefix_query_offset', 1 );
  13. function myprefix_query_offset( &$query ) {
  14.  
  15. // Before anything else, make sure this is the right query...
  16. if ( ! $query->is_home() ) {
  17. return;
  18. }
  19.  
  20. // First, define your desired offset...
  21. $offset = -1;
  22.  
  23. // Next, determine how many posts per page you want (we'll use WordPress's settings)
  24. $ppp = get_option( 'posts_per_page' );
  25.  
  26. // Next, detect and handle pagination...
  27. if ( $query->is_paged ) {
  28.  
  29. // Manually determine page query offset (offset + current page (minus one) x posts per page)
  30. $page_offset = $offset + ( ($query->query_vars['paged']-1) * $ppp );
  31.  
  32. // Apply adjust page offset
  33. $query->set( 'offset', $page_offset );
  34.  
  35. }
  36. else {
  37.  
  38. // This is the first page. Set a different number for posts per page
  39. $query->set( 'posts_per_page', $offset + $ppp );
  40.  
  41. }
  42. }
  43.  
  44. add_filter( 'found_posts', 'myprefix_adjust_offset_pagination', 1, 2 );
  45. function myprefix_adjust_offset_pagination( $found_posts, $query ) {
  46.  
  47. // Define our offset again...
  48. $offset = -1;
  49.  
  50. // Ensure we're modifying the right query object...
  51. if ( $query->is_home() ) {
  52. // Reduce WordPress's found_posts count by the offset...
  53. return $found_posts - $offset;
  54. }
  55. return $found_posts;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement