在WordPress中获取自定义帖子类型以加载自定义模板

我已经在WordPress中为事件创建了自定义帖子类型。我的index.php页面基于二十十二个主题, 它设置了The Loop, 然后将渲染传递给部分模板:

<?php get_header();

if (have_posts()) {
    while (have_posts()) {
        the_post();
        get_template_part('content', get_post_format());
    }
}
else {
    get_template_part('content', 'none');
}

get_sidebar();
get_footer();

但是, 在查看事件发布时, get_post_format()仅返回一个空字符串(我希望它返回事件或类似的内容), 然后仅加载content.php模板的一部分, 而不是content-event.php。我在期待并且实际上想要。

如何使事件发布类型的报告事件成为其发布格式?


#1


我想你对发布格式和发布类型感到困惑。你这里需要的是get_post_type()。


#2


采用:

if(get_post_type()):
    get_template_part( 'content', get_post_type() );
else:
    get_template_part( 'content', get_post_format() );
endif;

来源:

https://www.srcmini02.com/66495.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_40459.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?