![](/img/trans.png)
[英]WordPress Archive Loop - Displaying category or custom post type name, depending on post
[英]Wordpress Post Pages With Custom HTML includes depending on Category
我一直在努力使它整天工作。 我想根据不同类别的Wordpress中帖子的类别添加一些自定义HTML,以保持内容整洁。 我似乎无法加载html文件。
相关代码为:
<div class="container">
<?php while ( have_posts() ) : the_post(); ?>
<div class="row clearfix">
<?php if (function_exists('breadcrumbs')) breadcrumbs(); ?>
<div class="title clearfix">
<a href="javascript:window.history.back();" class="back-list"></a>
<?php global $post; $category = get_the_category($post->ID); setPostViews($post->ID); ?>
<h1><?php echo $category[0]->name;?></h1>
</div>
<div class="detailBlock clearfix">
<h1><?php the_title()?></h1>
<div class="detail-inner">
<?php $featured_img = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full', true);
if($featured_img) {
echo "<div class='detail-img'><img src='$featured_img[0]' alt='".get_the_title()."'></div>";
echo $category[0]->ID ;
}
the_content();
?>
<?php
/* TEST CODE */
global $post; $category = get_the_category($post->ID);
if($category[0] == '6'){
include( get_template_directory_uri() '/call-to-actions/cta-weight-loss-fem.html');
}
?>
</div>
</div>
<?php endwhile;?>
</div>
更改:
if($category[0] == '6'){
至
if($category[0]->ID == '6'){
那应该起作用。
注意:您不需要上面的行就可以获取类别,因为以前已经有了它。 更好的主意是将值存储为变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.