本文整理汇总了PHP中WP_Query::is_attachment方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query::is_attachment方法的具体用法?PHP WP_Query::is_attachment怎么用?PHP WP_Query::is_attachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Query
的用法示例。
在下文中一共展示了WP_Query::is_attachment方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: is_join_filter_active
/**
* @param WP_Query $query
* @param String $pagenow
* @return bool
*/
private function is_join_filter_active($query, $pagenow)
{
global $sitepress_settings;
$is_media_upload = $pagenow === 'media-upload.php';
$is_attachment_and_cant_be_translated = $query->is_attachment() ? !$this->is_media_and_cant_be_translated('attachment') : false;
return !$is_media_upload || !$is_attachment_and_cant_be_translated || isset($query->queried_object) && isset($query->queried_object->ID) && $query->queried_object->ID == $sitepress_settings['urls']['root_page'];
}
示例2: array
/**
* Get the fork's parent post, set up a query, and load correct template.
*
* Duplicates the functionality of /wp-includes/template-loader.php and includes
* a lot of copypasta, but that's only to ensure that it follows the same logic.
*
*/
function choose_template()
{
$p = get_queried_object_id();
if (get_post_type($p) !== 'fork') {
return;
}
$pp = get_post($p)->post_parent;
$parent = get_post($pp);
if ($parent->post_type == 'page') {
$query = array('page_id' => $pp);
} else {
$query = array('p' => $pp);
}
$t = new WP_Query($query);
$template = false;
if ($t->is_404() && ($template = get_404_template())) {
} elseif ($t->is_search() && ($template = get_search_template())) {
} elseif ($t->is_tax() && ($template = get_taxonomy_template())) {
} elseif ($t->is_front_page() && ($template = get_front_page_template())) {
} elseif ($t->is_home() && ($template = get_home_template())) {
} elseif ($t->is_attachment() && ($template = get_attachment_template())) {
remove_filter('the_content', 'prepend_attachment');
} elseif ($t->is_single() && ($template = get_single_template())) {
} elseif ($t->is_page && ($template = get_page_template())) {
} elseif ($t->is_category() && ($template = get_category_template())) {
} elseif ($t->is_tag() && ($template = get_tag_template())) {
} elseif ($t->is_author() && ($template = get_author_template())) {
} elseif ($t->is_date() && ($template = get_date_template())) {
} elseif ($t->is_archive() && ($template = get_archive_template())) {
} elseif ($t->is_comments_popup() && ($template = get_comments_popup_template())) {
} elseif ($t->is_paged() && ($template = get_paged_template())) {
} else {
$template = get_index_template();
}
if ($template = apply_filters('template_include', $template)) {
include $template;
}
return;
}
示例3: foreach
/**
* @param string $where
* @param WP_Query $query
*
* @return string
*/
function posts_where_filter($where, $query)
{
global $pagenow, $wp_taxonomies, $sitepress, $sitepress_settings;
//exceptions
$post_type = false;
if (isset($query->queried_object) && isset($query->queried_object->ID) && $query->queried_object->ID == $sitepress_settings['urls']['root_page']) {
return $where;
}
// determine post type
$debug_backtrace = $this->get_backtrace(0, true, false);
//Limit to a maximum level?
foreach ($debug_backtrace as $o) {
if ($o['function'] == 'apply_filters_ref_array' && $o['args'][0] == 'posts_where') {
$post_type = $o['args'][1][1]->query_vars['post_type'];
break;
}
}
// case of taxonomy archive
if (empty($post_type) && $query->is_tax()) {
$tax = $query->get('taxonomy');
$post_type = $wp_taxonomies[$tax]->object_type;
foreach ($post_type as $k => $v) {
if (!$this->is_translated_post_type($v)) {
unset($post_type[$k]);
}
}
if (empty($post_type)) {
return $where;
}
// don't filter
}
if (!$post_type) {
$post_type = 'post';
}
if (is_array($post_type) && !empty($post_type)) {
$none_translated = true;
foreach ($post_type as $ptype) {
if ($this->is_translated_post_type($ptype)) {
$none_translated = false;
}
}
if ($none_translated) {
return $where;
}
} else {
if (!$this->is_translated_post_type($post_type) && 'any' != $post_type) {
return $where;
}
}
$attachment_is_translatable = $sitepress->is_translated_post_type('attachment');
if (($pagenow == 'upload.php' || $pagenow == 'media-upload.php' || $query->is_attachment()) && !$attachment_is_translatable) {
return $where;
}
$current_language = $sitepress->get_current_language();
$requested_id = false;
// Fix for when $sitepress->get_current_language() does not return the correct value (e.g. when request is made for an attachment, an iframe or an ajax call)
if (isset($_REQUEST['attachment_id']) && $_REQUEST['attachment_id']) {
$requested_id = $_REQUEST['attachment_id'];
}
if (isset($_REQUEST['post_id']) && $_REQUEST['post_id']) {
$requested_id = $_REQUEST['post_id'];
}
if ($requested_id) {
$post_type = get_post_type($requested_id);
$current_language = $sitepress->get_language_for_element($requested_id, 'post_' . $post_type);
if (!$current_language) {
$current_language = $sitepress->get_current_language();
}
}
if ('all' != $this->this_lang) {
if ('any' == $post_type) {
$condition = " AND (t.language_code='" . esc_sql($current_language) . "' OR t.language_code IS NULL )";
} else {
$condition = " AND t.language_code='" . esc_sql($current_language) . "'";
}
} else {
$condition = '';
}
$where .= $condition;
return $where;
}
示例4: is_join_filter_active
/**
* @param WP_Query $query
* @param String $pagenow
*
* @return bool
*/
private function is_join_filter_active($query, $pagenow)
{
$is_attachment_and_cant_be_translated = $query->is_attachment() ? $this->is_media_and_cant_be_translated('attachment') : false;
return $pagenow !== 'media-upload.php' && !$is_attachment_and_cant_be_translated && !$this->is_queried_object_root($query);
}
示例5: defineLookupOrder
//.........这里部分代码省略.........
// taxonomy-[taxonomy]-[term-slug]
// taxonomy-[taxonomy]
// taxonomy-[post-type]
// taxonomy
// archive-[post-type]
// [post-type]
// archive
$term = get_queried_object();
if (!empty($term->slug)) {
$result[] = 'taxonomy-' . $term->taxonomy . '-' . $term->slug;
$result[] = 'taxonomy-' . $term->taxonomy;
}
if ($query_post_type) {
$result[] = 'taxonomy-' . $query_post_type;
}
$result[] = 'taxonomy';
if ($query_post_type) {
$result[] = 'archive-' . $query_post_type;
$result[] = $query_post_type;
}
$result[] = 'archive';
} elseif ($wp_query->is_date()) {
// date-[post-type]
// date
// archive-[post-type]
// [post-type]
// archive
if ($query_post_type) {
$result[] = 'date-' . $query_post_type;
}
$result[] = 'date';
if ($query_post_type) {
$result[] = 'archive-' . $query_post_type;
$result[] = $query_post_type;
}
$result[] = 'archive';
} elseif ($wp_query->is_archive()) {
// archive-[post-type]
// [post-type]
// archive
if ($query_post_type) {
$result[] = 'archive-' . $query_post_type;
$result[] = $query_post_type;
}
$result[] = 'archive';
} elseif ($wp_query->is_page()) {
// page-[parent-slug]-[post-slug]
// page-[post-slug]
// [page-template-name]
// page
// singular
if ($post->post_parent) {
if ($parent_slug = get_slug($post->post_parent)) {
$result[] = 'page-' . $parent_slug . '-' . $post_slug;
}
}
$result[] = 'page-' . $post_slug;
// page templates can have their unique names, let's add them before the fallback
if ($page_template_name = get_page_template_name($post->ID)) {
$result[] = $page_template_name;
}
$result[] = 'page';
$result[] = 'singular';
} elseif ($wp_query->is_attachment()) {
// single-attachment-[slugfied-long-mime-type]
// single-attachment-[slugfied-short-mime-type]
// single-attachment
// attachment
// single
// singular
// slugfied-long-mime-type = image-jpeg
// slugfied-short-mime-type = jpeg
if (!empty($post->post_mime_type)) {
$result[] = 'single-attachment-' . \Bond\to_slug($post->post_mime_type);
$mime = explode('/', $post->post_mime_type);
if (count($mime) > 1) {
$result[] = 'single-attachment-' . \Bond\to_slug($mime[1]);
}
$result[] = 'single-attachment-' . $mime[0];
}
$result[] = 'single-attachment';
$result[] = 'attachment';
$result[] = 'single';
$result[] = 'singular';
} elseif ($wp_query->is_single()) {
// single-[post-type]-[post-slug]
// single-[post-type]
// [post-type]
// single
// singular
$result[] = 'single-' . $post_type . '-' . $post_slug;
$result[] = 'single-' . $post_type;
$result[] = $post_type;
$result[] = 'single';
$result[] = 'singular';
}
// everything is handled, allow a filter and go
$result = apply_filters($this->hooks_prefix . '/lookup_order', $result);
return $result;
}