• Resolved broraxel

    (@broraxel)


    Hi,

    I’m using the shortcode to display a number of pages in a card-like layout. The shortcode displays title of page, featured image, a custom field and an excerpt from the page. Is it possible to make the custom field and excerpt into links to the page as well? Right now, only the featured image and title of page links to the page.

    Cheers,
    Axel

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Bill Erickson

    (@billerickson)

    I assume you’re using the output filter to add your custom field, correct? Inside that customization, simply wrap the custom field and excerpt in a link.

    If you share the code you’re using to add the custom field, I’ll show you what changes are required to make the custom field and excerpt clickable.

    Alternatively, you may consider using a template part within your theme to manage the shortcode’s output. Here’s an article I wrote recently on this topic: https://www.billerickson.net/template-parts-with-display-posts-shortcode/

    Thread Starter broraxel

    (@broraxel)

    Hi,

    Thank you for your quick response.

    You’re right, I’m using one of your snippets to filter the output and add the custom field. Although, i recently changed it to show the title of the parent page instead of the custom field, but it mainly the same snippet.

    add_filter( 'display_posts_shortcode_output', 'be_display_posts_custom_fields', 10, 6 );
    function be_display_posts_custom_fields( $output, $atts, $image, $title, $date, $excerpt ) {
    	// Get our custom fields
    	global $post;
    	//H?r h?mtade den custom fields fr?n posten, den ?ndrade jag s? den h?mtar parent page title...
    	/*$adress = esc_attr( get_post_meta( $post->ID, 'adress', true ) );*/
    	$parent = get_post($post->post_parent);
    	$adress = $parent->post_title;
    	
    	// If there's a value for the custom field, let's wrap them with <span>'s so you can control them with CSS
    	if( isset( $adress ) ) $adress = '<span class="vara-fastigheter-adress">' . $adress . '</span> ';
    	
    	// Now let's rebuild the output. 
    	$output = '<li class="vara-fastigheter-container"><div class="vara-fastigheter-left"><div class="vara-fastigheter-image">' . $image . '</div><div class="vara-fastigheter-title-area">' . $title . '</div><div class="vara-fastigheter-ort">' . $adress . '</div><div class="vara-fastigheter-utdrag">' . $excerpt . '</div>';
    	// Finally we'll return the modified output
    	return $output;
    }

    Thank you!

    Thread Starter broraxel

    (@broraxel)

    Hi again,

    Just noticed this post was marked as resolved, but I would still very much appreciate if you could help me out making the excerpt clickable.

    BR,
    Axel

    Plugin Author Bill Erickson

    (@billerickson)

    Right before “Let’s build the output” line, add this:

    $excerpt = '<a href="' . get_permalink() . '">' . $excerpt . '</a>';

    • This reply was modified 6 years, 7 months ago by Bill Erickson.
    Thread Starter broraxel

    (@broraxel)

    Wonderful. Thanks a million!

    Cheers,
    Axel

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Make custom field & excerpt link to page’ is closed to new replies.