• Hey all,

    Hoping to get some help, I’m sure what I am trying to do is extremely easy however I have only been using WordPress for 3 days so bare with me.

    I have created a template to display a custom post type, the code below is what I have so far:

    <?php
    /**
     * Template Name: Kudos Template
     *
     * Selectable from a dropdown menu on the edit page screen.
     */
    ?>
    
    <?php get_header(); ?>
    
        <div id="container">
            <div id="content">
    
            <!-- Displays page title using <h1> tags for formating -->
            <?php the_title('<h1>', '</h1>'); ?>
    
            <!-- Pull posts from testimonails (This is a custom post type) -->
            <?php
                $type = 'testimonails';
                $args=array(
                  'post_type' => $type,
                  'post_status' => 'publish',
                  'paged' => $paged,
                   'posts_per_page' => 10,
                   'caller_get_posts'=> 1
                );
                $temp = $wp_query;  // assign orginal query to temp variable for later use
                $wp_query = null;
                $wp_query = new WP_Query($args);
            ?>        
    
            <!-- Load template part to encourage code reuse -->
            <?php get_template_part( 'loop', 'index' );?>     
    
            </div><!-- #content -->
        </div><!-- #container -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    For each post I am hoping to hoping to add a featured image which is aligned to the left of the post. Is it possible to wrap a <div> around each post so I can style how each post looks? Ideally I would like the featured image to automatically get inserted into a <div> which is aligned to the left.

    Essentially I would like to wrap a main <div> around each post, with a further two <div>’s inside, one for the content and one for the image.

    Thanks in advance for all of your help!

    Lewis.

Viewing 1 replies (of 1 total)
  • //First you need to enable featured images:
    add_theme_support( 'post-thumbnails' );
    
    // Then define featured image size.
    //By the way you can have multiple sizes.
    //Just name them differently
    // and call them by name to display
    add_image_size('testimonails-photo', 240, 160, true);
    // Testimonial Image size

    //BELOW WOULD NEED TO GO INSIDE YOUR LOOP / QUERY

    // Grab the featured images and strip out the title
    $testimonails_image = get_the_post_thumbnail($post->ID, 'testimonails-photo');
    $testimonails_image_format = preg_replace('/title=\"(.*?)\"/','',$testimonails_image);
    
    { ?>
    <div id="testimonialContainer">
    <?php
    if (!(empty($testimonails_image))) { ?>
    <div id="testimonialImage">
    <?php echo $portfolio_image_format; ?>
    </div><!-- //testimonialImage -->
    <?php }
    ?>
    <div id="testimonialText">
    <?php
    // your content to display text here.
    ?>
    </div><!-- //testimonialText -->
    </div><!-- //testimonialContainer -->
    
    //FINALLY Always include a reset at the end of a loop
    //This prevents conflict with other loops
    wp_reset_query(); ?>

    //don’t forget to actually click the “featured image” and add an image or it won’t display.

Viewing 1 replies (of 1 total)
  • The topic ‘Please help: formatting a custom post type on a page template’ is closed to new replies.