• I’m using Display Posts Shortcode to, well, display posts for a website I’m building for a client who has specific taxonomies they need content served from.

    I’m wondering how I can make the entire listing-item element a link to the post, rather than just the post tile or the background image. I’m positioning the category, date, and excerpt spans over the background image (as you can see at the bottom of the link above), and I’d like the whole listing-item to function as a link to the blog posts.

    Thanks!

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter bcripps

    (@bcripps)

    I figured out “a” way to do it—though I’m sure there’s likely a better way (I’m still listening!)

    I used the output filter and made some amendments to it, like this:

    /* add link to 'display posts' output items */
    function add_link_to_excerpt( $output, $original_atts, $image, $title, $date, $excerpt, $inner_wrapper, $content, $class, $author, $category_display_text ) {
    
    	$post_link = get_the_permalink();
    
    	// Now let's rebuild the output and add the $post_link to it
    	$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . '<a href="' . $post_link . '" class="date">' . $date . '</a>' . $author . $category_display_text . '<a href="' . $post_link . '" class="excerpt">' . $excerpt . '</a> </' . $inner_wrapper . '>';
    
    	// Finally we'll return the modified output
    	return $output;
    }
    add_filter( 'display_posts_shortcode_output', 'add_link_to_excerpt', 10, 11 );
    • This reply was modified 5 years, 6 months ago by bcripps.

    But @bcripps, you only linked the image a place the rest of the objets over the featured image. In fact, you have 4 links for every listing-item. Not a link linking the whole listing-item.

    Anyone can help with this?
    I want to achieve to wrap the whole listing item in a link.

    Thanks million

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘add link to entire listing-item’ is closed to new replies.