这可能吗?如果是,如何?
我正在链接到一个不存在的帖子/页面404 error
. 我想让它获取non-existing post
并将其作为404页面上的链接,但我不希望它抛出错误(所以没有404页面,只是一个简单的页面)。当我单击此按钮时,我希望它转到我可以添加帖子的页面(从前端使用名为User Submitted Posts
). 这可能吗?
顺便说一句:通过获取链接来显示相关帖子也很好。但我认为这是不可能的。
这可能吗?如果是,如何?
我正在链接到一个不存在的帖子/页面404 error
. 我想让它获取non-existing post
并将其作为404页面上的链接,但我不希望它抛出错误(所以没有404页面,只是一个简单的页面)。当我单击此按钮时,我希望它转到我可以添加帖子的页面(从前端使用名为User Submitted Posts
). 这可能吗?
顺便说一句:通过获取链接来显示相关帖子也很好。但我认为这是不可能的。
如果在模板中创建404.php
all not-found requests will be handled by this template file, 在那里你可以放你想要的任何东西。
例如404.php
文件可以使用以下内容(只是草稿):
<?php get_header(); ?>
<h3>
<?php
$slug = get_query_var(\'name\');
if ( $slug ) {
$name = ucwords(str_replace(\'-\', \' \', $slug));
printf( __(\'Searching for post "%s"?\') . \' \', $name );
_e(\'It does not exists, maybe you can create it.\');
} else {
$name = \'\';
_e(\'Content you required not exists, maybe you can create it.\');
}
?>
<h3>
<div id="user-submitted-posts-wrapper" data-name="<?php echo $name; ?>">
<?php echo do_shortcode(\'[user-submitted-posts]\'); ?>
</div>
<script>
jQuery().ready(function($) {
var name = $(\'#user-submitted-posts-wrapper\').data(\'name\');
if ( name != \'\') $(\'.usp-title input\').eq(0).value(name);
});
</script>
<?php get_footer(); ?>
插件donot 支持预编译帖子标题,但可以用jquery填充。我将脚本直接插入页脚,以获得答案semplicity,但使用wp_register_script 和wp_equeue_script. 您还必须确保jquery包含在页面中,如果您使用wp_register_script
您可以将jquery放在脚本依赖项中。template_include
滤器E、 g.如果您想在所需的职位类型为“产品”时显示不同的404,您可以使用:add_filter(\'template_include\', \'change_404_template\');
function change_404_template($template) {
if ( is_404() && ( get_query_var(\'post_type\') == \'product\' ) ) {
return get_stylesheet_directory() . \'/my-custom-template-for-not-found.php\' ;
}
return $template;
}
不同的方法是在404上进行完全重定向。这会降低性能,因为向服务器发送了两个请求(一个导致404,另一个是重定向),但在某些情况下,此方法可能很有用。如果你想走这条路template_redirect
措施:add_action(\'template_redirect\', \'redirect_404\');
function redirect_404() {
if ( is_404() && ( get_query_var(\'post_type\') == \'product\') ) ) {
wp_redirect( home_url() ); // I redirect to home, you can redirect wherever you want
exit();
}
}
我正在将WordPress博客集成到我现有的公文包test中。我的网站。com。测试时会出现WordPress默认的二十一博客。我的网站。com/blog/。我想将WordPress功能集成到我现有的公文包中,所以我在测试时创建了一个页面。我的网站。com/blog。php。我刚刚在博客页面中添加了下一页/上一页功能。My problem is that the next_posts_link() function does not return the correct URL. 使用我的公文包布局的博客