Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Forked from katmoody/Custom-Grid-Loop-Excerpt
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save GaryJones/2cf5e711bee56f11f3f8 to your computer and use it in GitHub Desktop.

Select an option

Save GaryJones/2cf5e711bee56f11f3f8 to your computer and use it in GitHub Desktop.

Revisions

  1. GaryJones revised this gist May 19, 2015. 2 changed files with 32 additions and 24 deletions.
    24 changes: 0 additions & 24 deletions Custom-Grid-Loop-Excerpt
    Original file line number Diff line number Diff line change
    @@ -1,24 +0,0 @@
    /**
    * Change the number of words in excerpt if in the grid loop and customize READ MORE, add accessibility
    */
    function kat_grid_content() {

    // First, we make sure we're in the grid loop.
    if( ! apply_filters( 'is_genesis_grid_loop', false ) )
    return;

    // Change length if teaser
    if( in_array( 'teaser', get_post_class() ) )
    $length = 25;
    else
    $length = 55;

    echo '<p>' . wp_trim_words( get_the_excerpt(), $length ) . '</p>';

    // Display more link
    // echo '<a rel="nofollow" class="more-link" href="' . get_permalink() . '">Continue Reading</a>';
    echo '<p class="more-link"><a href="'. get_permalink() .'">' . __( 'Read more', 'genesis' ) . '<span class="screen-reader-text"> ' . __( 'about' ) . " " . get_the_title() . "</span></a></p>";
    // Remove default content so we don't get both
    remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
    }
    add_action( 'genesis_entry_content', 'kat_grid_content', 9 );
    32 changes: 32 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    <?php

    add_action( 'genesis_entry_content', 'kat_grid_content', 9 );
    /**
    * Change the number of words in excerpt if in the grid loop and customize READ MORE, add accessibility.
    */
    function kat_grid_content() {
    // Make sure we're in the grid loop.
    if ( ! apply_filters( 'is_genesis_grid_loop', false ) ) {
    return;
    }

    // Change length of teaser.
    $length = 55;
    if ( in_array( 'teaser', get_post_class() ) ) {
    $length = 25;
    }

    echo '<p>' . wp_trim_words( get_the_excerpt(), $length ) . '</p>';

    // Display more link.
    printf(
    '<p class="more-link"><a href="%1$s">%2$s<span class="screen-reader-text"> %3$s %4$s</span></a></p>',
    esc_url( get_permalink() ),
    esc_html__( 'Read more', 'your-text-domain' ),
    esc_html_x( 'about', 'i.e. Read more about A Post Title', 'your-text-domain' ),
    esc_html( get_the_title() )
    );

    // Remove default content so we don't get both.
    remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
    }
  2. @katmoody katmoody created this gist May 17, 2015.
    24 changes: 24 additions & 0 deletions Custom-Grid-Loop-Excerpt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    /**
    * Change the number of words in excerpt if in the grid loop and customize READ MORE, add accessibility
    */
    function kat_grid_content() {

    // First, we make sure we're in the grid loop.
    if( ! apply_filters( 'is_genesis_grid_loop', false ) )
    return;

    // Change length if teaser
    if( in_array( 'teaser', get_post_class() ) )
    $length = 25;
    else
    $length = 55;

    echo '<p>' . wp_trim_words( get_the_excerpt(), $length ) . '</p>';

    // Display more link
    // echo '<a rel="nofollow" class="more-link" href="' . get_permalink() . '">Continue Reading</a>';
    echo '<p class="more-link"><a href="'. get_permalink() .'">' . __( 'Read more', 'genesis' ) . '<span class="screen-reader-text"> ' . __( 'about' ) . " " . get_the_title() . "</span></a></p>";
    // Remove default content so we don't get both
    remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
    }
    add_action( 'genesis_entry_content', 'kat_grid_content', 9 );