Single product and single page

Up to this point we've done pretty well. We have our main post page or our homepage done, but if I click on one of these and we go to the single product page, it doesn't look too good. We're also missing a bunch of information.

So we'll now create a new file inside the MyShop theme folder and save it as single.php. After creating this file if we go back to the single view and reload, it'll be blank because it's looking at the single file. So what we'll do is copy everything we have in the index page.

So we'll grab all of it, we'll paste it in, and get rid of the showcase part because we don't want that. We want the showcase on the homepage only. We'll put an hr tag in there.

We'll do the same thing as far as checking for posts and looping through the post even though it's a single post as we did in the previous section. But we'll get rid of everything that's in between the while loop:

<?php while(have_posts()) : the_post(); ?>
<div class="row single-product">
<div class="large-5 columns">
<a href="#">Go Back</a>
<br>
<?php if(has_post_thumbnail()) : ?>
<?php the_post_thumbnail(); ?>
<?php endif; ?>
</div>
</div>
<?php endwhile; ?>

We're just going to get that out and then we'll create a new div with a class. Let's create a div with the class of row and also single-product. Inside that, we'll have a 5-column div. Within this div, we'll have our Go Back link, and let's put a line break. Then we'll check for the featured image or the thumbnail. So we'll copy from the index.php file. We just want to check to see if it's there, and if it is then we'll display it. Then that should be it for the 5-column div. So that's just going to be the image.

After that, we'll have a 7-column div. This is going to have the title, which we'll put in an h2. So we'll say php the_title and right under that, we'll put the_content. We'll then put an hr tag. We want the tags and the following code snippet. We're just checking for the tags, see if the function exists, and then spit them out:

<div class="large-7 columns">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<hr>
<?php if(the_tags()): ?>
<?php if(function_exist('the_tags')) { ?>
<strong>Tags: </strong>
<?php the_content_tags('', ',',''); ?><br/><?php } ?>
<?php endif; ?>
</div>

Let's go ahead and save this. We'll go back to our page and reload, and now we have a product page:

As for Go Back, right now it won't do anything. Let's have it go to the home page. We'll say php and we should be able to say echo site_url:

<div class="row single-product">
<div class="large-5 columns">
<a href="<?php echo site_url(); ?>">Go Back</a>
<br>

Click on Go Back, and it brings us back to our homepage. So that looks good.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.217.198