Advertisement
Guest User

Untitled

a guest
Oct 21st, 2010
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.56 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Template Name: Submit
  4.  *
  5.  * A custom page template to submit.
  6.  */
  7.  
  8.  get_header(); ?>
  9.  
  10.  <div id="container">
  11.             <div id="content" role="main">
  12.  
  13. <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
  14.  
  15.                 <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  16.                     <?php if ( is_front_page() ) { ?>
  17.                         <h2 class="entry-title"><?php the_title(); ?></h2>
  18.                     <?php } else { ?>
  19.                         <h1 class="entry-title"><?php the_title(); ?></h1>
  20.                     <?php } ?>
  21.  
  22.                     <div class="entry-content">
  23.                    
  24.                     <!-- *************************************************** -->
  25.                     <?php
  26. /**
  27.  *
  28.  * New Post Form for Custom Post Types for the Frontend of Your Site
  29.  * By Jared Williams - http://new2wp.com
  30.  *
  31.  * Last Updated: 8/30/2010
  32.  */
  33.  
  34. // Check if the form was submitted
  35. if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] )) {
  36.    
  37.     // Do some minor form validation to make sure there is content
  38.     if (isset ($_POST['title'])) {
  39.         $title =  $_POST['title'];
  40.     } else {
  41.         echo 'Please enter a title';
  42.     }
  43.     if (isset ($_POST['description'])) {
  44.         $description = $_POST['description'];
  45.     } else {
  46.         echo 'Please enter the content';
  47.     }
  48.     $tags = $_POST['post_tags'];
  49.    
  50.     $arr_Cats = array(); //set all categories here
  51.  
  52.     // Add the content of the form to $post as an array
  53.     $post = array(
  54.         'post_title'    => $title,
  55.         'post_content'  => $description,
  56.         'post_category' => $arr_Cats, // Usable for custom taxonomies too
  57.         //'post_category'   => $_POST['cat'],  // Usable for custom taxonomies too
  58.         'tags_input'    => $tags,
  59.         'post_status'   => 'publish',           // Choose: publish, preview, future, etc.
  60.         'post_type'     => $_POST['post_type']  // Use a custom post type if you want to
  61.     );
  62.     wp_insert_post($post);  // Pass  the value of $post to WordPress the insert function
  63.                             // http://codex.wordpress.org/Function_Reference/wp_insert_post
  64.     wp_redirect( home_url() ); // redirect to home page after submit
  65.  
  66. } // end IF
  67. // Do the wp_insert_post action to insert it
  68. do_action('wp_insert_post', 'wp_insert_post');
  69. ?>
  70.  
  71. <!-- New Post Form -->
  72. <div id="postbox">
  73.     <form id="new_post" name="new_post" method="post" action="">
  74.         <p><label for="title">Title</label><br />
  75.         <input type="text" id="title" value="" tabindex="1" size="20" name="title" />
  76.         </p>
  77.         <p><label for="description">Description</label><br />
  78.         <textarea id="description" tabindex="3" name="description" cols="50" rows="6"></textarea>
  79.         </p>
  80.         <p><?php wp_dropdown_categories( 'show_option_none=Category&tab_index=4&taxonomy=category' ); ?></p>
  81.         <p><label for="post_tags">Tags</label>
  82.             <input type="text" value="" tabindex="5" size="16" name="post_tags" id="post_tags" /></p>
  83.         <p align="right"><input type="submit" value="Publish" tabindex="6" id="submit" name="submit" /></p>
  84.        
  85.         <!--<input type="hidden" name="post_type" id="post_type" value="post" />-->
  86.         <input type="hidden" name="action" value="post" />
  87.         <?php wp_nonce_field( 'new-post' ); ?>
  88.     </form>
  89. </div>
  90. <!--// New Post Form -->
  91.                     <!-- *************************************************** -->
  92.  
  93.                         <?php the_content(); ?>
  94.                         <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
  95.                         <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
  96.                     </div><!-- .entry-content -->
  97.                 </div><!-- #post-## -->
  98.  
  99.                 <?php comments_template( '', true ); ?>
  100.  
  101. <?php endwhile; ?>
  102.  
  103.             </div><!-- #content -->
  104.         </div><!-- #container -->
  105.  
  106.  
  107. <?php get_sidebar(); ?>
  108. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement