Displaying custom posts with "read more" in a shortcode
-
I created a custom post type, “Testimonials” so that my client can easily add new testimonials as she receives them from her clients. By using the “post snippets” plugin, I have created a shortcode to display each testimonial by specifying the post ID like this: [testimonial id=”100″] By simply filling in the client’s name in the title, position in the custom fields, and testimonial in the content area, the shortcode then creates a properly styled testimonial box for her. However I am having trouble getting the content to appear the way I would like. I am by no means a PHP expert, but I am having trouble figuring out what I’ve missed here.
The following code does work:
echo "<div class=\"boxbox\">"; echo "<div class=\"box\">"; $title = get_the_title('{id}'); echo "<span style=\"color:#060c59\"><strong>$title</strong></span>"; echo "<br/>"; $position = get_post_meta('{id}', 'position', true); echo "<span style=\"text-decoration: underline\"><em>$position</em></span>"; echo "<br/><br/>"; // This section is a compromise but it works: $post_id = {id}; $queried_post = get_post($post_id); $content = $queried_post->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); echo $content; // End of the section echo "</div>"; echo "</div>";The above displays the testimonial, but if I understand correctly, by using the_content() I should be able to display a “Read More” link on especially long ones. I would like to replace my “compromise” section with something the following:
query_posts( 'p={id}' ); global $more; $more = 0; while (have_posts()) : the_post(); the_content( 'Read more »' ); endwhile; wp_reset_query();But it doesn’t work. Instead, the content doesn’t display at all. I also tried the same method with WP_Query. Is my PHP wrong, or is it something about the plugin? Is there any way I can get this to work? Any help would be greatly appreciated. Thanks.
The topic ‘Displaying custom posts with "read more" in a shortcode’ is closed to new replies.