• Resolved sscalifornia

    (@sscalifornia)


    I’d like to display the just the byline in a regular archive page, say under the title (not using the plugin shortcode for testimonials but rather using my theme’s custom archive page). Does anyone know the code for that? I’ve looked in the plugin code but can’t seem to make it work. I’m essentially looking for something like get_by_line(); or something like that. Any help would be great.

    https://www.ads-software.com/plugins/testimonials-by-woothemes/

Viewing 8 replies - 1 through 8 (of 8 total)
  • The plugin doesn’t offer that function but you can create one:

    Add this to your theme’s functions.php:

    /**
     * Display or return HTML-formatted testimonial byline.
     *
     * Copied from /testimonials-by-woothemes/woothemes-testimonials-template.php::woothemes_testimonials()
     * @param	 string/array $args	 Arguments.
     * @since	 1.0.0
     * @return string
     */
    function woothemes_testimonials_get_byline ( $args = '' ) {
    	global $post;
    
    	$defaults = apply_filters( 'woothemes_testimonials_default_args', array(
    		'echo' => true,
    		'size' => 50,
    	) );
    
    	$args = wp_parse_args( $args, $defaults );
    	$html = '';
    
    	// The Query.
    	$query = woothemes_get_testimonials( $args );
    
    	// The Display.
    	if ( ! is_wp_error( $query ) && is_array( $query ) && count( $query ) > 0 ) {
    		foreach ( $query as $post ) {
    			setup_postdata( $post );
    			if ( isset( $post->byline ) && '' != $post->byline ) {
    				$html .= ' <span class="title" itemprop="jobTitle">' . $post->byline . '</span><!--/.title-->' . "\n";
    			}
    		}
    		wp_reset_postdata();
    	}
    
    	if ( $args['echo'] != true ) { return $html; }
    
    	// Should only run is "echo" is set to true.
    	echo $html;
    }

    Then call it in your template file:

    woothemes_testimonials_get_byline();

    Thread Starter sscalifornia

    (@sscalifornia)

    Thank you so much for your response. When I added the elements that you had suggested, I do get the bylines but they are all of the bylines in a row no matter who had posted them. Shouldn’t they be checking the post to see which post returns which byline?

    Thread Starter sscalifornia

    (@sscalifornia)

    If you check out the page here all of the titles are on everyone’s testimonial.

    I forgot it was an archive page. Add the post ID to the defaults like so:

    $defaults = apply_filters( 'woothemes_testimonials_default_args', array(
    		'id' => $post->ID,
    		'echo' => true,
    		'size' => 50,
    	) );

    Thread Starter sscalifornia

    (@sscalifornia)

    Wow man! That’s just what I needed. Thanks again for your help on this issue. I love it when developers can help each other. You rock dude!

    You’re welcome. I dig your site, nice work!

    Thread Starter sscalifornia

    (@sscalifornia)

    Thank you sir, I appreciate you saying that.

    Instead of creating database queries for each testimonial as you loop through the archive posts, why not grab the byline from the post meta along these lines:

    get_post_meta( get_the_ID(), '_byline', true );

    The data is already there in your loop without needing to query each time.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Get Byline’ is closed to new replies.