Skip to content

Instantly share code, notes, and snippets.

@davidperezgar
Forked from billerickson/functions.php
Created October 21, 2016 10:47
Show Gist options
  • Select an option

  • Save davidperezgar/acaee153e592fe09d27adfa2229a764a to your computer and use it in GitHub Desktop.

Select an option

Save davidperezgar/acaee153e592fe09d27adfa2229a764a to your computer and use it in GitHub Desktop.

Revisions

  1. @billerickson billerickson revised this gist Jan 30, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@
    * Display ad after third post
    *
    * @author Bill Erickson
    * @link https://gist.github.com/4675266
    * @link http://www.billerickson.net/code/use-the-built-in-post-counter/
    */
    function be_ad_after_third_post() {
    global $wp_query;
    @@ -29,7 +29,7 @@ function be_ad_after_third_post() {
    * Add class to first post
    *
    * @author Bill Erickson
    * @link https://gist.github.com/4675266
    * @link http://www.billerickson.net/code/use-the-built-in-post-counter/
    *
    * @param array $classes
    * @return array
  2. @billerickson billerickson revised this gist Jan 30, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@
    * Display ad after third post
    *
    * @author Bill Erickson
    * @link
    * @link https://gist.github.com/4675266
    */
    function be_ad_after_third_post() {
    global $wp_query;
    @@ -29,7 +29,7 @@ function be_ad_after_third_post() {
    * Add class to first post
    *
    * @author Bill Erickson
    * @link
    * @link https://gist.github.com/4675266
    *
    * @param array $classes
    * @return array
  3. @billerickson billerickson created this gist Jan 30, 2013.
    44 changes: 44 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    <?php
    /**
    * Use the built-in post counter
    *
    * Sometimes you'll want to keep track of which post you're on in a loop.
    * Some people create their own $loop_counter (ex: Genesis, https://gist.github.com/4675237 ).
    * There's a better way! A loop counter is built into $wp_query. Ex:
    *
    * global $wp_query;
    * echo $wp_query->current_post
    *
    * Count starts at 0 (first post is 0, second post is 1 )
    */

    /**
    * Display ad after third post
    *
    * @author Bill Erickson
    * @link
    */
    function be_ad_after_third_post() {
    global $wp_query;
    if( 2 == $wp_query->current_post )
    echo 'This is an ad!'
    }
    add_action( 'genesis_after_post', 'be_ad_after_third_post' );

    /**
    * Add class to first post
    *
    * @author Bill Erickson
    * @link
    *
    * @param array $classes
    * @return array
    */
    function be_class_on_first_post( $classes ) {
    global $wp_query;
    if( 0 == $wp_query->current_post )
    $classes[] = 'first-post';

    return $classes;
    }
    add_filter( 'post_class', 'be_class_on_first_post' );