Advertisement
Guest User

header.php

a guest
Jan 8th, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.28 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: Rate Wine Form
  4. */
  5. ?>
  6. <?php
  7. if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "new_post") {
  8.  
  9.     // Do some minor form validation to make sure there is content
  10.     if (isset ($_POST['title'])) {
  11.         $title =  $_POST['title'];
  12.     } else {
  13.         echo 'Please enter the wine name';
  14.     }
  15.     if ($_POST['description'] != '') {
  16.         $description = $_POST['description'];
  17.     } else {
  18.         echo 'Please enter some notes';
  19.     }
  20.  
  21.     $tags = $_POST['post_tags'];
  22.     $winerating = $_POST['winerating'];
  23.  
  24.     // ADD THE FORM INPUT TO $new_post ARRAY
  25.     $new_post = array(
  26.     'post_title'    =>  $title,
  27.     'post_content'  =>  $description,
  28.     'post_category' =>  array($_POST['cat']),  // Usable for custom taxonomies too
  29.     'tags_input'    =>  array($tags),
  30.     'post_status'   =>  'publish',           // Choose: publish, preview, future, draft, etc.
  31.     'post_type' =>  'post',  //'post',page' or use a custom post type if you want to
  32.     'winerating'    =>  $winerating
  33.     );
  34.  
  35.     //SAVE THE POST
  36.     $pid = wp_insert_post($new_post);
  37.  
  38.              //KEEPS OUR COMMA SEPARATED TAGS AS INDIVIDUAL
  39.     wp_set_post_tags($pid, $_POST['post_tags']);
  40.  
  41.     //REDIRECT TO THE NEW POST ON SAVE
  42.     $link = get_permalink( $pid );
  43.     wp_redirect( $link );
  44.  
  45.     //ADD OUR CUSTOM FIELDS
  46.     add_post_meta($pid, 'rating', $winerating, true);
  47.  
  48.     //INSERT OUR MEDIA ATTACHMENTS
  49.     if ($_FILES) {
  50.         foreach ($_FILES as $file => $array) {
  51.         $newupload = insert_attachment($file,$pid);
  52.         // $newupload returns the attachment id of the file that
  53.         // was just uploaded. Do whatever you want with that now.
  54.         }
  55.  
  56.     } // END THE IF STATEMENT FOR FILES
  57.  
  58. } // END THE IF STATEMENT THAT STARTED THE WHOLE FORM
  59.  
  60. //POST THE POST YO
  61. do_action('wp_insert_post', 'wp_insert_post');
  62.  
  63. ?>
  64.  
  65. <!DOCTYPE html>
  66. <html <?php language_attributes(); ?>>
  67. <head>
  68.     <title><?php wp_title( '-', true, 'right' ); echo wp_specialchars( get_bloginfo('name'), 1 ) ?></title>
  69.     <meta name="description" content="<?php wp_title(''); echo ' | '; bloginfo( 'description' ); ?>" />
  70.     <meta charset="<?php bloginfo( 'charset' ); ?>" />
  71.     <link rel="profile" href="http://gmpg.org/xfn/11" />
  72.     <meta name="viewport" content="width=device-width; initial-scale=1"/><?php /* Add "maximum-scale=1" to fix the Mobile Safari auto-zoom bug on orientation changes, but keep in mind that it will disable user-zooming completely. Bad for accessibility. */ ?>
  73.     <link rel="icon" href="<?php bloginfo('template_url'); ?>/favicon.ico" type="image/x-icon" />
  74.     <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
  75.     <link rel="alternate" type="application/rss+xml" title="<?php bloginfo( 'name' ); ?>" href="<?php bloginfo( 'rss2_url' ); ?>" />
  76.     <link rel="alternate" type="application/atom+xml" title="<?php bloginfo( 'name' ); ?>" href="<?php bloginfo( 'atom_url' ); ?>" />
  77.     <?php wp_enqueue_script("jquery"); /* Loads jQuery if it hasn't been loaded already */ ?>
  78.    
  79.     <!--[if lt IE 9]>
  80.         <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
  81.     <![endif]-->
  82.    
  83.     <?php wp_head(); ?> <?php /* this is used by many Wordpress features and for plugins to work proporly */ ?>
  84.    
  85.     <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
  86. </head>
  87.  
  88. <body <?php body_class(); ?>>
  89.  
  90. <div id="main">
  91.     <header>
  92.         <h1 id="logo"><a href="<?php bloginfo('url'); ?>/" title="<?php bloginfo('description'); ?>"><?php bloginfo('name'); ?></a></h1>
  93.         <h2 id="tagline"><?php bloginfo('description'); ?></h2>
  94.     </header>
  95.    
  96.         <div class="wpcf7">
  97.         <form id="new_post" name="new_post" method="post" action="" class="wpcf7-form" enctype="multipart/form-data">
  98.             <!-- post name -->
  99.             <fieldset name="name">
  100.                 <label for="title">Wine Name:</label>
  101.                 <input type="text" id="title" value="" tabindex="5" name="title" />
  102.             </fieldset>
  103.  
  104.             <!-- post Category -->
  105.             <fieldset class="category">
  106.                 <label for="cat">Type:</label>
  107.                 <?php wp_dropdown_categories( 'tab_index=10&taxonomy=category&hide_empty=0' ); ?>
  108.             </fieldset>
  109.  
  110.             <!-- post Content -->
  111.             <fieldset class="content">
  112.                 <label for="description">Description and Notes:</label>
  113.                 <textarea id="description" tabindex="15" name="description" cols="80" rows="10"></textarea>
  114.             </fieldset>
  115.  
  116.             <!-- wine Rating -->
  117.             <fieldset class="winerating">
  118.                 <label for="winerating">Your Rating</label>
  119.                 <input type="text" value="" id="winerating" tabindex="20" name="winerating" />
  120.             </fieldset>
  121.  
  122.             <!-- images -->
  123.             <fieldset class="images">
  124.                 <label for="bottle_front">Front of the Bottle</label>
  125.                 <input type="file" name="bottle_front" id="bottle_front" tabindex="25" />
  126.             </fieldset>
  127.  
  128.             <fieldset class="images">
  129.                 <label for="bottle_rear">Back of the Bottle</label>
  130.                 <input type="file" name="bottle_rear" id="bottle_rear" tabindex="30" />
  131.             </fieldset>
  132.  
  133.             <!-- post tags -->
  134.             <fieldset class="tags">
  135.                 <label for="post_tags">Additional Keywords (comma separated):</label>
  136.                 <input type="text" value="" tabindex="35" name="post_tags" id="post_tags" />
  137.             </fieldset>
  138.  
  139.             <fieldset class="submit">
  140.                 <input type="submit" value="Post Review" tabindex="40" id="submit" name="submit" />
  141.             </fieldset>
  142.  
  143.             <input type="hidden" name="action" value="new_post" />
  144.             <?php wp_nonce_field( 'new-post' ); ?>
  145.         </form>
  146.         </div> <!-- END WPCF7 -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement