0

I'm looking everywhere but I can't seem to be able to find How I can create a post with a specific template where I decide where the images to be displayed, so wordpress will know that this is where to display images in this post So A user will insert his text and attach all his images and he doesn't have to worry about displaying them I found out about custom post types and taxonomies and I created it but how to create such template.

Update: I want the post to be displayed in a specific design. so assuming you have a product page in amazon. I want in all mages to be inserted in the left side and text in the right side. in ASP the user can insert image then it will be uploaded in a specific predefined position in the layout this is what i'm trying to do. So i want to make an image container for the product post page and text next to it. and when a user upload image/s it will be displayed there.

0

If you want many posts to be displayed differently than the rest you can add to them a specific category or a tag and have a conditional rule in your single.php file:

if ( have_posts() ) {
    while ( have_posts() ) { the_post();
        if ( in_category('houses') ) {

            get_template_part( 'single', 'house' );

        } else {
            get_template_part( 'single', 'post' );
        }
    }
} else {
    // No posts
}

For every post in category houses template from single-house.php file will be used and for all other posts single-post.php will be used.


If you want one post to have a different layout you should use a page instead. Posts are content entries listed in reverse chronological order, pages are meant to be static content type i.e. "About page", you can learn more about that difference here.

Using a unique layout for a page is easy, you need to create a new page template and choose it for desired page. To create a post template you just need to place:

<?php /* Template Name: Example Template */ ?>

at the top of a new file and add all the necessary code below. For more information about page templates go here.


To learn more on with template file will be used read more about template hierarchy.

4
  • Then you are talking about the very basics of coding a template. Without the knowledge of HTML, CSS and some PHP you will not be able to easily achieve that. To do that without coding anything you could use some of "page building" plugins - wordpress.org/plugins/search/page+builder
    – Greg36
    May 4 '17 at 19:58
  • so i should make it a page instead of post but how can i specify in the layout that this is where i want to display images. I know basic php but my main web development experience in C# so i just don't understand how images is passed to the front end in wordpress
    – ma1169
    May 4 '17 at 19:59
  • You do that in the code by using template tags that require some PHP knowledge or using "page building" plugins that allow creating custom pages layouts without any coding.
    – Greg36
    May 4 '17 at 20:02
  • Post's or page's featured image can be displayed with get_the_post_thumbnail() function. If you want to display images that are in the content of the post or page somewhere else on the page, it will be more difficult.
    – Greg36
    May 4 '17 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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