Advertisement
srikat

Untitled

Feb 3rd, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. add_action( 'genesis_after_entry', 'sk_ad' );
  2. /**
  3. * Insert one random ad after every second post.
  4. *
  5. * Scope: Posts page and all category archives.
  6. *
  7. * @author Sridhar Katakam
  8. * @link http://sridharkatakam.com/display-random-ad-every-second-post-genesis/
  9. */
  10. function sk_ad() {
  11.  
  12. // if we are not on Posts page or category archive, abort.
  13. if ( ! ( is_home() || is_category() ) ) {
  14. return;
  15. }
  16.  
  17. // if Ads by datafeedr.com plugin is not active, abort.
  18. if ( ! function_exists( 'dfads' ) ) {
  19. return;
  20. }
  21.  
  22. // if this is a paginated page, abort.
  23. if ( is_paged() ) {
  24. return;
  25. }
  26.  
  27. global $wp_query;
  28.  
  29. if( $wp_query->current_post == 1 || $wp_query->current_post == 3 ) { // if 2nd or 4th post
  30. echo dfads( 'groups=-1&limit=1&orderby=random' );
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement