本文整理汇总了PHP中is_404函数的典型用法代码示例。如果您正苦于以下问题:PHP is_404函数的具体用法?PHP is_404怎么用?PHP is_404使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_404函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: title
function title()
{
if (is_category()) {
echo 'Category Archive for "';
single_cat_title();
echo '" | ';
bloginfo('name');
} elseif (is_tag()) {
echo 'Tag Archive for "';
single_tag_title();
echo '" | ';
bloginfo('name');
} elseif (is_archive()) {
wp_title('');
echo ' Archive | ';
bloginfo('name');
} elseif (is_search()) {
echo 'Search for "' . wp_specialchars($s) . '" | ';
bloginfo('name');
} elseif (is_home() || is_front_page()) {
bloginfo('name');
echo ' | ';
bloginfo('description');
} elseif (is_404()) {
echo 'Error 404 Not Found | ';
bloginfo('name');
} elseif (is_single()) {
wp_title('');
} else {
echo wp_title(' | ', false, right);
bloginfo('name');
}
}
示例2: base_getBreadcrumbs
function base_getBreadcrumbs()
{
if (is_404()) {
return false;
}
// Hack to fix breadcrumbs when you're viewing the news home
if (is_home()) {
$post = new \Timber\Post(get_option('page_for_posts'));
} else {
global $post;
}
$breadcrumbs = [];
if ($post->post_parent) {
$parent_id = $post->post_parent;
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = new \Timber\Post($page->ID);
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
}
// Add 'Blog Home' to breadcrumbs if you're on a news post or archive
if ((is_single() || is_archive()) && !is_search()) {
$breadcrumbs[] = new \Timber\Post(get_option('page_for_posts'));
}
return $breadcrumbs;
}
示例3: perfect_title
/**
* Prints better page title
*/
function perfect_title()
{
echo '<title>';
if (function_exists('is_tag') && is_tag()) {
single_tag_title(__('Tag Archive for') . '"');
$output .= '" - ';
} elseif (is_archive()) {
wp_title('');
echo __('Archive') . ' - ';
} elseif (is_search()) {
echo __('Search for') . '"' . esc_html($s) . '" - ';
} elseif (!is_404() && is_single() || is_page()) {
wp_title('');
echo ' - ';
} elseif (is_404()) {
echo __('Not Found') . '-';
}
if (is_home()) {
bloginfo('name');
echo ' - ';
bloginfo('description');
} else {
bloginfo('name');
}
if ($paged > 1) {
echo ' - ' . __('page') . ' ' . $paged;
}
echo '</title>';
}
示例4: qtranxf_wp_head
function qtranxf_wp_head()
{
global $q_config;
if ($q_config['header_css_on']) {
echo '<style type="text/css">' . PHP_EOL . $q_config['header_css'] . '</style>' . PHP_EOL;
}
do_action('qtranslate_head_add_css');
//not really needed?
// skip the rest if 404
if (is_404()) {
return;
}
// set links to translations of current page
foreach ($q_config['enabled_languages'] as $lang) {
if (!empty($q_config['locale_html'][$lang])) {
$hreflang = $q_config['locale_html'][$lang];
} else {
$hreflang = $lang;
}
//if($language != qtranxf_getLanguage())//standard requires them all
echo '<link hreflang="' . $hreflang . '" href="' . qtranxf_convertURL('', $lang, false, true) . '" rel="alternate" />' . PHP_EOL;
}
//https://support.google.com/webmasters/answer/189077
echo '<link hreflang="x-default" href="' . qtranxf_convertURL('', $q_config['default_language']) . '" rel="alternate" />' . PHP_EOL;
//qtranxf_add_css();// since 3.2.5 no longer needed
}
示例5: get_language_from_content
/**
* returns the language based on the queried content
*
* @since 1.2
*
* @return object|bool detected language, false if none was found
*/
protected function get_language_from_content()
{
// no language set for 404
if (is_404() || is_attachment() && !$this->options['media_support']) {
return $this->get_preferred_language();
}
if ($var = get_query_var('lang')) {
$lang = explode(',', $var);
$lang = $this->model->get_language(reset($lang));
// choose the first queried language
} elseif ((is_single() || is_page() || is_attachment() && $this->options['media_support']) && (($var = get_queried_object_id()) || ($var = get_query_var('p')) || ($var = get_query_var('page_id')) || ($var = get_query_var('attachment_id')))) {
$lang = $this->model->post->get_language($var);
} else {
foreach ($this->model->get_translated_taxonomies() as $taxonomy) {
if ($var = get_query_var(get_taxonomy($taxonomy)->query_var)) {
$lang = $this->model->term->get_language($var, $taxonomy);
}
}
}
/**
* Filter the language before it is set from the content
*
* @since 0.9
*
* @param bool|object $lang language object or false if none was found
*/
return apply_filters('pll_get_current_language', isset($lang) ? $lang : false);
}
示例6: featureText
function featureText()
{
if (is_front_page()) {
the_field('feature_text');
} elseif (is_home() || is_single()) {
_e('Rock Theme Official Blog');
} elseif (is_archive()) {
_e('Rock Theme Official Blog');
_e('<br>');
single_term_title('Browsing: ');
if (is_month()) {
$monthNum = get_query_var('monthnum');
$month = date('F', mktime(0, 0, 0, $monthNum));
$year = get_query_var('year');
echo 'Posts from ' . $month . ' ' . $year;
}
} elseif (is_page_template('page-news.php') || is_page_template('page-about.php') || is_page_template('page-contact.php')) {
bloginfo('name');
_e('<br>');
the_title();
} elseif (is_404()) {
_e('Whoops, were a little lost.');
} elseif (is_search()) {
_e('Rock Theme Official Blog');
_e('<br>');
printf('Search results for: %s', get_search_query());
}
}
示例7: bavota_breadcrumbs
function bavota_breadcrumbs()
{
if (!is_front_page()) {
echo '<a href="' . home_url('/') . 'blog">Blog</a><span class="divider"> <i class="icon-angle-right"></i> </span>';
}
if (is_category() || is_single()) {
$category = get_the_category();
$ID = $category[0]->cat_ID;
// echo get_category_parents($ID, TRUE, ' ', FALSE ); // was causing errors in the error_log
echo is_wp_error($cat_parents = get_category_parents($ID, TRUE, ' ', FALSE)) ? '' : $cat_parents;
}
$mytitle = get_the_title();
if (strlen($mytitle) > 22) {
$mytitle = substr($mytitle, 0, 38) . "...";
}
if (is_single() || is_page()) {
echo ' <span class="divider"> <i class="icon-angle-right"></i> </span> ';
echo $mytitle;
}
if (is_tag()) {
echo "Tag: " . single_tag_title('', FALSE);
}
if (is_404()) {
echo "404 - Page not Found";
}
if (is_search()) {
echo "Search";
}
if (is_year()) {
echo get_the_time('Y');
}
}
示例8: dbdb_body_classes
/**
* Custom class for the WP 'body_class()' function
* updated: 4/15/10
*/
function dbdb_body_classes($classes)
{
// source http://darrinb.com/notes/2010/customizing-the-wordpress-body_class-function/
global $post;
global $wp_query;
// if there is no parent ID and it's not a single post page, category page, or 404 page, give it
// a class of "parent-page"
if ($post->post_parent < 1 && !is_single() && !is_archive() && !is_404()) {
$classes[] = 'parent-page';
}
// if the page/post has a parent, it's a child, give it a class of its parent name
if ($post->post_parent > 0) {
/* $parent_title = get_the_title($wp_query->post->post_parent);
$parent_title = preg_replace('#\s#','-', $parent_title);
$parent_title = strtolower($parent_title);
$classes[] = 'parent-pagename-'.$parent_title; */
$parent_id = wp_get_post_parent_id($wp_query->post);
// $parent_id = get_the_ID($wp_query->post->post_parent);
echo "PARENT ID : " . $parent_id;
// $parent_id = preg_replace('#\s#','-', $parent_id);
$parent_id = strtolower($parent_id);
$classes[] = 'parent-id-' . $parent_id;
}
// add a class = to the name of post or page
$classes[] = $wp_query->queried_object->post_name;
return array_unique($classes);
}
示例9: cinnamon_wp_title
/**
* Filters wp_title to print a neat <title> tag based on what is being viewed.
*
* @param string $title Default title text for current view.
* @param string $sep Optional separator.
* @return string The filtered title.
*/
function cinnamon_wp_title($title, $sep)
{
/**
* If this is version 4.1, directly stop the manual title modification. Let WordPress does that through add_theme_support( 'title-tag' );
*/
if (function_exists('_wp_render_title_tag')) {
return $title;
}
if (is_feed()) {
return $title;
}
global $page, $paged;
// Add the blog name
$title .= get_bloginfo('name', 'display');
// Add the blog description for the home/front page.
$site_description = get_bloginfo('description', 'display');
if ($site_description && (is_home() || is_front_page())) {
$title .= " {$sep} {$site_description}";
}
// Add a page number if necessary:
if (($paged >= 2 || $page >= 2) && !is_404()) {
$title .= " {$sep} " . sprintf(__('Page %s', 'cinnamon'), max($paged, $page));
}
return $title;
}
示例10: get_the_ID
/**
* Get the ID for the current post
*/
private function get_the_ID()
{
if (is_404()) {
return '';
}
return get_the_ID();
}
示例11: display
function display($args = array())
{
/* Use the generic_content action if it's set. See http://core.trac.wordpress.org/ticket/20509 */
if ($this->get_setting('mode', 'default') == 'default' && has_action('generic_content') && !did_action('generic_content')) {
return do_action('generic_content');
}
/* Since it's impossible to get the $wp_query in its correct form when loading the content from admin-ajax.php, we will display this notice. */
if (headway_get('ve-live-content-query', $this->block, false) && $this->get_setting('mode', 'default') == 'default') {
echo '<div class="alert alert-yellow" style="margin: 5px;"><p><strong>Please note:</strong> What\'s being displayed here in the Content Block may not be correct. When viewing the site outside of the Visual Editor, you will see the correct content.</p></div>';
}
/* If LoopBuddy is activated, we'll strictly rely on it for the query setup and how the content is displayed. */
if (class_exists('pluginbuddy_loopbuddy')) {
global $pluginbuddy_loopbuddy;
$loopbuddy_query = $this->get_setting('loopbuddy-query', -1);
$loopbuddy_layout = $this->get_setting('loopbuddy-layout', -1);
if (isset($pluginbuddy_loopbuddy) && $loopbuddy_query !== -1) {
echo $pluginbuddy_loopbuddy->render_loop($loopbuddy_query, $loopbuddy_layout);
$this->remove_hooks();
return;
}
}
/* Display the 404 text if it's a 404 (has to be default behavior) */
if (is_404() && $this->get_setting('mode', 'default') == 'default' && !headway_get('ve-live-content-query', $this->block, false)) {
$this->remove_hooks();
return $this->display_404();
}
/* Display loop like normal if nothing else fires first */
$this->loop($args);
$this->remove_hooks();
wp_reset_query();
}
示例12: mh_page_title
function mh_page_title()
{
if (is_home()) {
echo get_the_title(get_option('page_for_posts', true));
} elseif (is_author()) {
global $author;
$user_info = get_userdata($author);
echo __('Articles by ', 'mh') . esc_attr($user_info->display_name);
} elseif (is_category() || is_tax()) {
echo single_cat_title("", false);
} elseif (is_tag()) {
echo single_tag_title("", false);
} elseif (is_search()) {
echo __('Search Results for ', 'mh') . get_search_query();
} elseif (is_day()) {
echo get_the_date();
} elseif (is_month()) {
echo get_the_date('F Y');
} elseif (is_year()) {
echo get_the_date('Y');
} elseif (is_404()) {
echo __('Page not found (404)', 'mh');
} else {
echo get_the_title();
}
}
示例13: ubik_seo_meta_description
function ubik_seo_meta_description($desc = '')
{
// Generate a meta description
if (empty($desc)) {
// Single posts, pages, and attachments
if (is_singular()) {
$post = get_post();
if (empty($post)) {
$desc = '';
}
$desc = wptexturize($post->post_content);
// Get the entire contents, not the excerpt, so as to not duplicate Ubik Excerpt
}
// Check to see if we have a description for this category, tag, or taxonomy
if (is_category() || is_tag() || is_tax()) {
$desc = term_description();
}
// Now match other possibilities...
if (is_author()) {
$desc = get_the_author_meta('description');
}
// Front or home page
if (is_front_page() || is_home()) {
$desc = get_bloginfo('description');
}
// No excerpt to return
if (is_404() || is_search()) {
$desc = '';
}
$desc = ubik_seo_meta_description_sanitize($desc);
}
return apply_filters('ubik_seo_meta_description', $desc);
}
示例14: so_body_classes
/**
* Add our own classes to the body_class function
* adapted from: http://www.mimoymima.com/2013/01/lab/better-body-class-function-wordpress/
*
* @20131220: This in an update to the earlier code, where it was needed to change the call to the body_class.
* with the snippet below however that is no longer necessary and as an additional advantage it also keeps the
* original WordPress body class which may (or may not) come in handy one day.
*
* @20140423 adjusted the code to make it more useful
*/
function so_body_classes($classes)
{
global $post;
// return some of these things
if (is_category()) {
$classes[] = 'cat-archive';
} elseif (is_search()) {
$classes[] = 'search-page';
} elseif (is_tag()) {
$classes[] = 'tag-archive';
} elseif (is_home()) {
$classes[] = 'home-page';
} elseif (is_404()) {
$classes[] = 'error-page';
}
// return page-(page name)
if (is_page()) {
$pn = $post->post_name;
$classes[] = 'page-' . $pn;
}
if (is_page() && $post->post_parent) {
$classes[] = 'child-of-' . $parentSlug;
}
// if WPML has been installed return the language code
if (in_array('sitepress-multilingual-cms/sitepress.php', apply_filters('active_plugins', get_option('active_plugins')))) {
if (defined('ICL_LANGUAGE_CODE')) {
$lang = 'lang-' . ICL_LANGUAGE_CODE;
$classes[] = $lang;
}
}
return $classes;
}
示例15: getBodyClasses
/**
*
* Returns the list of classes
*
* @param $post
* @return array
* @author Tim Perry
*/
protected function getBodyClasses($post)
{
$classes = array();
if (is_single()) {
$classes[] = "single";
} else {
$classes[] = "page";
}
if (is_page()) {
$classes[] = 'page--' . $post->post_name;
}
if (is_404()) {
$classes[] = 'page--404';
} elseif (is_front_page()) {
$classes[] = 'page--front';
} elseif (is_home()) {
$classes[] = 'page--news';
} elseif (is_search()) {
$classes[] = 'page--search';
} elseif (is_single() && ($postType = strtolower(str_replace("_", "-", $post->post_type)))) {
$classes[] = "single--" . $postType;
}
if (is_user_logged_in()) {
$classes[] = 'has-admin-bar';
}
return $classes;
}