Creating a gallery custom post type?

Can I show different text for linking to gallery posts ?

YES, Here’s how to do it, put this where you want to output text as – readmore/view photos, depending on theme or way you’re generating these text we can use filter to change it as per custom post type.

<?php 
echo '<a href="'.the_permalink().'">';
if ( 'gallery' == get_post_type() ) {
    echo 'View Photos';
} else {
    echo 'Read More';
}
echo '</a>';
?>

Custom template for Custome post type

You can configure your blog to use different template for custom post type by creating a template with slug single-gallery.php where gallery is custom post type slug.

Update– To show images as gallery on single post (from this answer)

Add the following code to your themes single.php to show the attached images(full) beneath the post content, And the condition will check for custom post type – gallery.

<?php

if ( 'gallery' == get_post_type() ) { //condition to show gallery on post type - gallery

    if ( $attachments = get_children( array(
        'post_type' => 'attachment',
        'post_mime_type'=>'image',   //return all image attachment only
        'numberposts' => -1,   //get all the attachments
        'post_parent' => $post->ID
    )));

    foreach ($attachments as $attachment) {
        // you can customize the oputput
        echo wp_get_attachment_link( $attachment->ID, 'full' , false, false, '' );
        echo '<span class="img_cap">'.$attachment->post_excerpt.'</span>';

    }
}

?>

Read the codex page for more information – wp_get_attachment_link#Parameters

Leave a Comment