get_queried_object_id()是一个WordPress函数,它用于获取当前WordPress网站上的分类、标签、文章、分类法(taxonomy)或文章类型(post type)的ID,具体取决于当前页面的上下文。这个函数通常在WordPress主题或插件开发中用于获取当前页面的相关信息。 例如,如果你在某个分类页面上使用get_queried_object_id(),它将返回当前...
在调取置顶文章时,排除当前页面已经显示的置顶文章,只要置顶文章,其他与置顶文章一样的文章全部排除。代码如下:<?php $current_category = get_queried_object(); // 获取当前栏目对象 $current_category_id = $current_category->term_id; // 获取当前栏目的ID // 获取当前页面已经显示的置顶文章ID $sticky...
$current_term = get_queried_object();// 确保当前页面是属于您的自定义文章类型if ($current_term instanceof WP_Term && 'my_custom_post_type' === $current_term>taxonomy) {$term_id = $current_term>term_id; // 分类ID$term_name = $current_term>name; // 分类名称$...
95.get_queried_object_id() 检索当前查询对象的 ID。 get_queried_object_id() 获取查询对象 WordPress – Nero Dev – WordPress 开发 96. esc_url_raw() 为数据库使用执行 esc_url()。 esc_url_raw() 在2 分钟内编写一个 WP REST API 端点 97.the_archive_title() 根据查询的对象显示归档标题。 t...
If you're using pretty permalinks,get_query_var('page_id')won't work. Instead, get the queried object ID from the global$wp_query: // Since 3.1 - recommended! $page_object = get_queried_object(); $page_id = get_queried_object_id(); ...
echo'<li class="item item-cat"><a href="'.$post_type_link.'">'.$post_type_object->labels->name.'</a></li>'.$sep; } // Get categories $category=get_the_category($post->ID); // If category not empty if(!empty($category)){ ...
$mainquery=get_queried_object(); Theget_queried_object()function returns the currently queried object, whatever that may be. On a single post, it will just return the post object, while on an archive it will return the category, tag, term object or whatever object relates to the archive....
要为不同的WordPress文章ID指定不同的模板,您可以使用`single_template`过滤器来实现。以下是一个示例代码,演示如何根据文章ID来指定不同的模板:function custom_single_template($template) { // 检查是否是单个文章页面 if (is_single()) { $post_id = get_queried_object_id();// 检查文章ID并返回相应...
add_filter('document_title',function($title){if((is_category()|| is_tag()|| is_tax())&& get_query_var('paged')<2){return get_term_meta(get_queried_object_id(),'seo_title',true)?:$title;}return$title;});然后把「SEO描述」和「SEO关键字」输出到分类/标签/自定义分类页的 head 中...
if($meta_value = get_term_meta(get_queried_object_id(), 'seo_'.$type, true)){ echo "<meta name='{$type}' content='{$meta_value}' />\n"; // 只有设置才输出 } } } }); 就是这么简单,如果你是 WordPress 主题或者插件开发者,使用 WPJAM Basic 进行二次开发都是超简单的一件事情,我...