问题描述
我为我的项目创建了一个自定义帖子类型“ cs_portfolio”。我要实现的是使用户能够选择特定页面来显示“ cs_portfolio”的所有数据。
当您在“设置”>“阅读帖子的静态页面”中进行设置时,便是该博客帖子的示例。它会自动使用index.PHP循环所有博客文章。
就我而言,我已经弄清楚了如何在“设置”>“阅读”中添加一个下拉字段并保存。
Settings > Reading 1:https://i.stack.imgur.com/w6ybw.png
/**
* Adds a custom field: "Projects page"; on the "Settings > Reading" page.
*/
add_action( 'admin_init',function () {
$id = 'page_for_projects';
// add_settings_field( $id,$title,$callback,$page,$section = 'default',$args = array() )
add_settings_field( $id,'Projects Page:','settings_field_page_for_projects','reading','default',array(
'label_for' => 'field-' . $id,// A unique ID for the field. Optional.
'class' => 'row-' . $id,// A unique class for the TR. Optional.
) );
} );
function settings_field_page_for_projects( $args ) {
$id = 'page_for_projects';
wp_dropdown_pages( array(
'name' => $id,'show_option_none' => '— Select —','option_none_value' => '0','selected' => get_option( $id ),) );
}
add_filter( 'whitelist_options',function ( $options ) {
$options['reading'][] = 'page_for_projects';
return $options;
} );
Page List 2:https://i.stack.imgur.com/bVvWo.png
/**
* Filters the post states on the "Pages" edit page. displays "Projects Page"
* after the post/page title,if the current page is the Projects static page.
*
* @param array $states
* @param WP_Post $post
*/
add_filter( 'display_post_states',function ( $states,$post ) {
if ( intval( get_option( 'page_for_projects' ) ) === $post->ID ) {
$states['page_for_projects'] = __( 'Projects Page' );
}
return $states;
},10,2 );
我现在的问题是,要调用投资组合页面以循环“ cs_portfolio”中的所有数据的文件应该是什么?并保持“ cs_portfolio”的特色?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)