I currently have a page on a site that I am developing and that contains a loop which loops through 4 posts contained in a custom post type called Treatments. http://wptest.lancscps.co.uk/treatment-approaches/ As you can see there is a post_excerpt and I would like the user to be able to click through to a single custom post which contains the entire information.

                    // Custom loop that adds a clearing class to the first item in each row
                    $args = array('numberposts' => -1, 'order' => 'ASC', 'post_type' =>  'treatments' ); //For this example I am setting the arguments to return all posts in reverse chronological order. Odds are this will be a different query for your project
                    $allposts = get_posts($args);
                    $numCol = 2; // Set number of columns

                    // Start Counter
                    $counter = 0;
                    foreach ($allposts as $post) {
                        $content = '<div class="six columns margin-main-content'.' '.($counter   % $numCol == 0 ? 'alpha' : 'omega').'">'; // Add class to the columns depending on if it is odd or even
                        $content .= '<section class="treatments lightgrey-background">';
                        $content .= '<figure>'.get_the_post_thumbnail( $post->ID, 'post-two-column' ).'</figure>';
                        //we need to provide a fallback image in the form of an if else statement?
                        $content .= '<h4>'.$post->post_title.'</h4>';
                        $content .= '<p>'.$post->post_excerpt.'</p>';
                        $content .= '<a href="'.get_permalink( $post->ID ).'"class="button">Find Out More</a>';
                        $content .= '</section>';
                        $content .= '</div>';
                        echo $content;
                        $counter ++;

Is it straightforward to pass the post id when the user clicks on the read more button using something like a hidden form field through to a single page template. This is so that the entire contents of that post could be spit out using a loop that can output the content based on the id that was passed in. I don't know how to code something like that?

  • why do you not just use the permalink to link to the single custom post type page?
    – Milo
    Mar 18, 2013 at 23:08
  • 2
    @milo Sorry yes it is straightforward to achieve if you know how. Create a file named, single-treatments.php page, treatments being the name of this particular custom post type so just substitute your own, add the standard loop in that file. Make sure you visit the permalinks settings page in the WordPress admin area so that the single page will work in the front end and you are good to go. Mar 18, 2013 at 23:34
  • 1
    ^^ Is this an answer ? ^^ IF so it should be posted as such.
    – s_ha_dum
    Mar 19, 2013 at 3:50
  • Ok I shall do so below Mar 19, 2013 at 10:54

1 Answer 1


After some research, my challenge has been solved

In my case I created a file named, single-treatments.php page

treatments is the name of the particular custom post type I'm using so be sure to just substitute your own, WordPress will recognise this as the single page template to use when a permalink that is related to that custom post type, in my case the treatments custom post type is clicked on by the end user.

Next I added the standard loop into that single page file. Make sure you visit the permalinks settings page in the WordPress admin area. This is a strange process but seems to enable the custom post single page template to work in the front end.

After this you are good to go. Custom Posts with excerpts and buttons that can link to another template which shows the post in more detail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.