最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

templates - Display a custom 404 page without a redirect

matteradmin6PV0评论

In a plugin I want to display a specific page without redirecting (and thus without changing the URL) like the plugin / does. I can capture 404s and redirect them, but I want the URL to stay the same when I show a custom page.

// A. this only displays the content and the not the header, footer, or title.
$post = get_page_by_path('/some-page/');
$content = apply_filters('the_content', $post->post_content);
echo $content;

...

// B. This only displays the page template, but doesn't include the content.
$template = get_template_part('page');
echo $template;

...

// C. A combination of the two doesn't include the sidebar or the or the page title.
$template = get_template_part('header', 'custom-404-page');
echo $template;
$post = get_page_by_path('/custom-page/');
$content = apply_filters('the_content', $post->post_content);
echo $content;
$template = get_template_part('footer', 'custom-404-page');
echo $template;

... I also tried:

// D.
global $post;
$post = get_page_by_path('/custom-404-page/');
setup_postdata($post);
$template = get_template_part('page');
echo $template;

but the content of the page still doesn't appear in the basic page template.

thanks

Post a comment

comment list (0)

  1. No comments so far