【发布时间】:2015-11-04 08:33:13
【问题描述】:
我在我的根目录中创建了一个新的 PHP 模板,旁边是 index.php,名为 'template-insert-posts.php。但是,当我尝试访问以下 URL:http://localhost/wordpress/template-insert-posts.php 时,出现以下错误:
Object not found! The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
我可以通过输入 URL http://localhost/wordpress/index.php 来访问 index.php 模板
现在,index.php 和template-insert-posts.php 都位于同一路径中,即/opt/lampp/htdocs/wordpress/wp-content/themes/twentyfifteen。那么,为什么我的template-insert-posts.php 无法访问?在尝试访问 Wordpress 中的自定义模板之前,我是否遗漏了什么?另外,这里是文件的源代码:
模板插入posts.php
<?php
$postTitleError = '';
if ( isset( $_POST['submitted'] ) && isset( $_POST['post_nonce_field'] ) && wp_verify_nonce( $_POST['post_nonce_field'], 'post_nonce' ) ) {
if ( trim( $_POST['postTitle'] ) === '' ) {
$postTitleError = 'Please enter a title.';
$hasError = true;
}
$post_information = array(
'post_title' => wp_strip_all_tags( $_POST['postTitle'] ),
'post_content' => $_POST['postContent'],
'post_type' => 'post',
'post_status' => 'pending'
);
wp_insert_post( $post_information );
}
$post_id = wp_insert_post( $post_information );
if ( $post_id ) {
wp_redirect( home_url() );
exit;
}
?>
<?php
get_header(); ?>
<form action="" id="primaryPostForm" method="POST">
<fieldset>
<label for="postTitle"><?php _e('Post Title:', 'framework') ?></label>
<input type="text" name="postTitle" id="postTitle" class="required" value="<?php if ( isset( $_POST['postTitle'] ) ) echo $_POST['postTitle']; ?>"/>
</fieldset>
<fieldset>
<label for="postContent"><?php _e('Post Content:', 'framework') ?></label>
<textarea name="postContent" id="postContent" rows="8" cols="30" class="required" <?php if ( isset( $_POST['postContent'] ) ) { if ( function_exists( 'stripslashes' ) ) { echo stripslashes( $_POST['postContent'] ); } else { echo $_POST['postContent']; } } ?>></textarea>
</fieldset>
<fieldset>
<input type="hidden" name="submitted" id="submitted" value="true" />
<?php wp_nonce_field( 'post_nonce', 'post_nonce_field' ); ?>
<button type="submit"><?php _e('Add Post', 'framework') ?></button>
</fieldset>
</form>
<?php get_footer(); ?>
【问题讨论】:
标签: php wordpress templates phpmyadmin