Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在页面上显示自定义文章类型摘录_Php_Wordpress_Custom Post Type - Fatal编程技术网

Php 在页面上显示自定义文章类型摘录

Php 在页面上显示自定义文章类型摘录,php,wordpress,custom-post-type,Php,Wordpress,Custom Post Type,我创建了一个简单的自定义帖子类型,如下所示: add_action( 'init', 'create_services_post_type' ); function create_services_post_type() { $args = array( 'description' => 'Services post type', 'show_ui' => true,

我创建了一个简单的自定义帖子类型,如下所示:

add_action( 'init', 'create_services_post_type' );

function create_services_post_type() {
    $args = array(
                  'description' => 'Services post type',
                  'show_ui' => true,
                  'menu_position' => 4,
                  'exclude_from_search' => true,
                  'labels' => array(
                                    'name'=> 'Services',
                                    'singular_name' => 'Service',
                                    'add_new' => 'Add New Service',
                                    'add_new_item' => 'Add New Service',
                                    'edit' => 'Edit Services',
                                    'edit_item' => 'Edit Service',
                                    'new-item' => 'New Service',
                                    'view' => 'View Services',
                                    'view_item' => 'View Service',
                                    'search_items' => 'Search Services',
                                    'not_found' => 'No Services Found',
                                    'not_found_in_trash' => 'No Services Found in Trash',
                                    'parent' => 'Parent Service'
                                   ),
                 'public' => true,
                 'capability_type' => 'post',
                 'hierarchical' => false,
                 'rewrite' => true,
                 'supports' => array('title', 'editor', 'thumbnail', 'comments')
                 );
    register_post_type( 'services' , $args );
}
现在,我创建了一个新的页面模板,我想在这个模板上显示来自该类别(服务)的3篇最新文章摘录,但由于我是一个PHP新手,无论我怎么努力,我都无法让它工作

有人愿意帮助我吗?
非常感谢

在要显示结果的地方尝试使用以下代码:

$args = array( 'post_type' => 'services', 'posts_per_page' => 3,'cat' => cat_id_of_services_category );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
  the_title();
  echo '<div class="entry-content">';
  the_excerpt();
  echo '</div>';
endwhile;
$args=array('post\u type'=>'services','posts\u per\u page'=>3,'cat'=>cat\u id\u服务类别);
$loop=新的WP_查询($args);
而($loop->have_posts()):$loop->the_post();
_title();
回声';
_摘录();
回声';
结束时;
如果在某种情况下,您无法获得所需的结果,请在此处查看: