php - 如何仅为我的cpt“投资组合”创建单独的“存档小部件”?
问题描述
我正在为我的投资组合创建一个自定义 wordpress 主题,尝试通过使用字段和元框从头开始做所有事情,并且不想使用任何插件。
我创建了一个cpt,如下所示:
function codex_custom_init() {
register_post_type(
'Portfolio', array(
'labels' => array('name' => __( 'Portfolio' ), 'singular_name' => __( 'Portfolio' ) ),
'public' => true,
'has_archive' => true,
'supports' => array('title', 'editor', 'thumbnail', 'comments'),
'menu_icon' => 'dashicons-sos',
)
);
//register taxonomy for portfolio post tags
register_taxonomy(
'portfolio-tag', //taxonomy
'portfolio', //post-type
array(
'hierarchical' => false,
'label' => __( 'Portfolio Tags','taxonomy general name'),
'singular_name' => __( 'Tag', 'taxonomy general name' ),
'rewrite' => true,
'query_var' => true
)
);
// add categories for Portfolio
register_taxonomy(
'portfoliocategories',
'portfolio',
array(
'labels' => array(
'name' => 'Portfolio Categories',
'add_new_item' => 'Add New Portfolio Category',
'new_item_name' => "New Portfolio Type"
),
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true
)
);
}
add_action( 'init', 'codex_custom_init' );
我已经创建了所有必需的页面和侧边栏。我想在我的“存档投资组合页面”上显示存档小部件,这是一个单独的存档小部件,其中包含仅与投资组合相关的帖子。感谢你的关心。
如何为 cpt 编辑和自定义:
<?php
wp_get_archives(
apply_filters(
'widget_archives_args',
array(
'type' => 'monthly',
'show_post_count' => $count,
),
$instance
)
);
?>
解决方案
你在哪里显示你的小部件,把你的代码放在这个条件内。
if ( is_singular( 'yourcpt' ) ) {
// conditional content/code
}
推荐阅读
- javascript - NodeJs 将当前日期时间字段插入 MySQL 数据库
- sql - 如何展平 SQL 查询的结果 - 将行转换为列?
- python - Plotly:在热图中通过单元格中间的形状线
- abap - 如何为作为标准类增强的方法添加 ABAPDoc?
- selenium - Selenium 与 Power Apps
- json - 未处理的异常:键入“列表”
' 不是 'SubJsonModel' 类型的子类型 - 颤振 - python - Python Numpy - 如果数组在数组中
- c - 在 C 中将结构写入文本文件
- postgresql - 企业数据库 13.1 上的离线 slony 安装
- reactjs - 如何使用 react 和 redux 提交表单?