Skip to content

Instantly share code, notes, and snippets.

@lizkaraffa
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lizkaraffa/9076599 to your computer and use it in GitHub Desktop.
Save lizkaraffa/9076599 to your computer and use it in GitHub Desktop.
So originally this was styled all in normal HTML. Then we put it in the following code so that we could use this get_list_view_html function in a few places so we weren't duplicating code. The instructions for the extra credit are: Users might like to add a shirt to the cart directly from the home page or the Shirts Listing page. Add to the func…
/* header include file */
<html>
<head>
<title><?php echo $page_title; ?></title>
<link rel="stylesheet" href="css/style.css" type="text/css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:400,700" type="text/css">
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<div class="header">
<div class="wrapper">
<h1 class="branding-title"><a href="./">Shirts 4 Mike</a></h1>
<ul class="nav">
<li class="shirts <?php if($section == "shirts") {echo "on";} ?>"><a href="shirts.php">Shirts</a></li>
<li class="contact <?php if($section == "contact") {echo "on";} ?>"><a href="contact.php">Contact</a></li>
<li class="company_info <?php if($section == "company_info") {echo "on";} ?>"><a href="company_info.php">Company Info</a></li>
<li class="cart"><a href="#">Shopping Cart</a></li>
</ul>
</div>
</div>
<?php
/* Home Page which is what the screen shot is of */
$page_title = "Shirts 4 Mike";
$section = "home";
include("/inc/products.php");
$products = get_products_all();
include("/inc/header.php"); ?>
<div id="content">
<div class="section banner">
<div class="wrapper">
<img class="hero" src="img/mike-the-frog.png" alt="Mike the Frog says:">
<div class="button">
<a href="shirts.php">
<h2>Hey, I&rsquo;m Mike!</h2>
<p>Check Out My Shirts</p>
</a>
</div>
</div>
</div>
<div class="section shirts latest">
<div class="wrapper">
<h2>Mike&rsquo;s Latest Shirts</h2>
<ul class="products">
<?php
get_products_recent();
?>
</ul>
</div>
</div>
</div>
<?php include("/inc/footer.php"); ?>
/* Products include file */
<?php
function get_list_view_html($product_id, $product){
$products = get_products_all();
$output = "";
$output = $output . "<li>";
$output = $output . '<a href="shirt.php?id=' . $product_id . '">';
$output = $output . '<img src="' . $product["img"] . '" alt="' . $product["name"] . '">';
$output = $output . "<p>View Details</p>";
$output = $output . "</a>";
$output = $output . '<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">';
$output = $output . '<input type="hidden" name="cmd" value="_s-xclick">';
$output = $output . '<input type="hidden" name="hosted_button_id" value="' . $product["paypal"] . '">';
$output = $output . '<input type="hidden" name="item_name" value="' . $product["name"] . '">';
$output = $output . '<input type="hidden" name="on0" value="Size">';
$output = $output . "<div>";
$output = $output . '<label for="os0">Size</label>';
$output = $output . "</div>";
$output = $output . "<div>";
$output = $output . '<select name="os0" id="os0">';
foreach($product["sizes"] as $size) {
$output = $output . '<option value="' . $size .'">' . $size . '</option>';
}
$output = $output . '</select>';
$output = $output . "</div>";
$output = $output . "<div>";
$output = $output . '<input type="submit" value="Add to Cart" name="submit" id="small_submit">';
$output = $output . "</div>";
$output = $output . '</form>';
$output = $output . "</li>";
return $output;
}
function get_products_recent(){
$products = get_products_all();
$position = 0;
$total_products = count($products);
$list_view_html ="";
foreach($products as $product_id => $product){
$position= $position + 1;
if($total_products - $position < 4){
$list_view_html = get_list_view_html($product_id, $product) . $list_view_html;
}
}
echo $list_view_html;
}
function get_products_all(){
$products = array();
$products[101] = array(
"name" => "Logo Shirt, Red",
"img" => "img/shirts/shirt-101.jpg",
"price" => 18,
"paypal" => "9P7DLECFD4LKE",
"sizes" => array("Small","Medium","Large","X-Large"),
"sleeves" => array("Short","Long")
);
$products[102] = array(
"name" => "Mike the Frog Shirt, Black",
"img" => "img/shirts/shirt-102.jpg",
"price" => 20,
"paypal" => "SXKPTHN2EES3J",
"sizes" => array("Small","Medium","Large","X-Large"),
"sleeves" => array("Short")
);
$products[103] = array(
"name" => "Mike the Frog Shirt, Blue",
"img" => "img/shirts/shirt-103.jpg",
"price" => 20,
"paypal" => "7T8LK5WXT5Q9J",
"sizes" => array("Small","Medium","Large","X-Large"),
"sleeves" => array("Short")
);
$products[104] = array(
"name" => "Logo Shirt, Green",
"img" => "img/shirts/shirt-104.jpg",
"price" => 18,
"paypal" => "YKVL5F87E8PCS",
"sizes" => array("Small","Medium","Large","X-Large"),
"sleeves" => array("Short","Long")
);
$products[105] = array(
"name" => "Mike the Frog Shirt, Yellow",
"img" => "img/shirts/shirt-105.jpg",
"price" => 25,
"paypal" => "4CLP2SCVYM288",
"sizes" => array("Small","Medium","Large","X-Large"),
"sleeves" => array("Short")
);
$products[106] = array(
"name" => "Logo Shirt, Gray",
"img" => "img/shirts/shirt-106.jpg",
"price" => 20,
"paypal" => "TNAZ2RGYYJ396",
"sizes" => array("Small","Medium","Large","X-Large"),
"sleeves" => array("Short","Long")
);
$products[107] = array(
"name" => "Logo Shirt, Teal",
"img" => "img/shirts/shirt-107.jpg",
"price" => 20,
"paypal" => "S5FMPJN6Y2C32",
"sizes" => array("Small","Medium","Large","X-Large"),
"sleeves" => array("Short","Long")
);
$products[108] = array(
"name" => "Mike the Frog Shirt, Orange",
"img" => "img/shirts/shirt-108.jpg",
"price" => 25,
"paypal" => "JMFK7P7VEHS44",
"sizes" => array("Large","X-Large"),
"sleeves" => array("Short")
);
return $products;
}
?>
/* footer include file */
<div class="footer">
<div class="wrapper">
<ul>
<li><a href="http://twitter.com/treehouse">Twitter</a></li>
<li><a href="https://www.facebook.com/TeamTreehouse">Facebook</a></li>
</ul>
<p>&copy; <?php echo date('Y'); ?> Shirts 4 Mike</p>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment