WP-根据帖子类别隐藏特定的div

时间:2019-03-07 10:22:42

标签: php wordpress

大家好,我对自定义帖子有点疑问。 我想根据帖子类别在帖子模板中隐藏特定的div。

如果帖子类别设置为coordonnees,我想用annuaire id(第139行)隐藏div。

如果您知道该怎么做,那就太好了!

非常感谢您的帮助!

<?php if(is_single()) : ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php else : ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('first-article'); ?>>
<?php endif; ?>
<div class="post-header col-xs-12 col-md-8">
<?php if(!get_theme_mod('sp_post_cat')) : ?>
<span class="cat"><?php the_category(' • '); ?></span>
<?php endif; ?>
<?php if(is_single()) : ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php else : ?>
<h2 class="entry-title first-article"><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php endif; ?>
</div>
<?php if(has_post_format('gallery')) : ?>
<?php $images = get_post_meta( $post->ID, '_format_gallery_images', true ); ?>
<?php if($images) : ?>
<div class="post-img">
<div class="sideslides">
<ul class="bxslider">
<?php foreach($images as $image) : ?>
<?php $the_image = wp_get_attachment_image_src( $image, 'full-thumb' ); ?> 
<?php $the_caption = get_post_field('post_excerpt', $image); ?>
<li><img src="<?php echo esc_url($the_image[0]); ?>" <?php if($the_caption) : ?>title="<?php echo $the_caption; ?>"<?php endif; ?> /></li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php endif; ?>
<?php elseif(has_post_format('video')) : ?>
<div class="post-img">
<?php $sp_video = get_post_meta( $post->ID, '_format_video_embed', true ); ?>
<?php if(wp_oembed_get( $sp_video )) : ?>
<?php echo wp_oembed_get($sp_video); ?>
<?php else : ?>
<?php echo $sp_video; ?>
<?php endif; ?>
</div>
<?php elseif(has_post_format('audio')) : ?>
<div class="post-img audio">
<?php $sp_audio = get_post_meta( $post->ID, '_format_audio_embed', true ); ?>
<?php if(wp_oembed_get( $sp_audio )) : ?>
<?php echo wp_oembed_get($sp_audio); ?>
<?php else : ?>
<?php echo $sp_audio; ?>
<?php endif; ?>
</div>
<?php else : ?>
<?php if(has_post_thumbnail()) : ?>
<?php if(!get_theme_mod('sp_post_thumb')) : ?>
<div class="post-img">
<?php if(is_single()) : ?>
<?php else : ?>
<a href="<?php echo get_permalink() ?>"><?php the_post_thumbnail('full-thumb'); ?></a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<div class="post-entry">
<?php if(is_single()) : ?>
<div class="col-xs-12 col-md-8">
<?php the_content(); ?>

<?php
 $credits = get_field( "credits" );
?>

<?php
echo "<p>" . $credits . "</p>";
?>

</div>
<div class="col-md-4"></div>

<?php else : ?>
<?php if(get_theme_mod('sp_post_summary') == 'excerpt') : ?>
<p><?php echo sp_string_limit_words(get_the_excerpt(), 40); ?>&hellip;</p>
<p><a href="<?php echo get_permalink() ?>" class="more-link"><span class="more-button"><?php _e( 'Découvrir<span class="more-line"></span>', 'redwood' ); ?></span></a>
<?php else : ?>
<?php the_content(__('Découvrir<span class="more-line"></span>', 'redwood')); ?>
<?php endif; ?>
<?php endif; ?>
<?php wp_link_pages(); ?>
<?php if(!get_theme_mod('sp_post_tags')) : ?>
<?php if(is_single()) : ?>
<?php if(has_tag()) : ?>
<div class="post-tags">
<?php the_tags("",""); ?>
</div>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
</div>
<?php if(!is_front_page()){ ?>

<?php if(get_theme_mod('sp_post_comment_link') && get_theme_mod('sp_post_share') && get_theme_mod('sp_post_share_author')) : else : ?>
<div class="post-share">
<?php if(is_single()) : ?>

<div class="col-md-12">

<?php if(!get_theme_mod('sp_post_share')) : ?>
<div class="post-share-box share-buttons">
<a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=<?php the_permalink(); ?>"><i class="fa fa-facebook"></i></a>
<a target="_blank" href="https://twitter.com/intent/tweet?text=Check%20out%20this%20article:%20<?php print solopine_social_title( get_the_title() ); ?>&url=<?php echo urlencode(the_permalink()); ?>"><i class="fa fa-twitter"></i></a>
<?php $pin_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
<a data-pin-do="none" target="_blank" href="https://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php echo $pin_image; ?>&description=<?php the_title(); ?>"><i class="fa fa-pinterest"></i></a>
<a target="_blank" href="https://plus.google.com/share?url=<?php the_permalink(); ?>"><i class="fa fa-google-plus"></i></a>
</div>
<?php endif; ?>
<?php endif; ?>
</div>

</div>
<?php endif; ?>
<?php }; ?>

<?php
$id = get_the_ID();
$custom_fields = get_post_custom($id);
$count = sizeof($custom_fields);
// echo $count;
?>
<?php if(is_single()) : ?>
<?php
 $adresse = get_field( "adresse" );
 $metro = get_field( "metro" );
 $horaires = get_field( "horaires" );
 $coordonnees = get_field( "coordonnees" );
 $map = get_field( "map" );
?>

<?php
if(!empty($adresse) || !empty($metro) || !empty($horaires) || !empty($coordonnees) || !empty($map)):
?>

<div id="coordonnees">
<div class="col-md-12">
<h2>Comment s'y rendre ?</h2>
</div>
<div class="col-xs-12 col-sm-4 col-md-4">

<?php
if(!empty($adresse)){
echo "<h3>Adresse</h3>";
echo "<p>" . $adresse . "</p>";
}
?>

<?php
if(!empty($metro)){
echo "<h3>Métro</h3>";
echo "<p>" . $metro . "</p>";
}
?>

<?php
if(!empty($horaires)){
echo "<h3>Horaires</h3>";
echo "<p>" . $horaires . "</p>";
}
?>
<?php
if(!empty($coordonnees)){
echo "<h3>Contact</h3>";
echo "<p>" . $coordonnees . "</p>";
}
?>
</div>

<div class="col-xs-12 col-sm-8 col-md-8">
<?php
if( !empty($map) ):
?>
<div class="acf-map">
<div class="marker" data-lat="<?php echo $map['lat']; ?>" data-lng="<?php echo $map['lng']; ?>"></div>
</div>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
<?php if(get_theme_mod('sp_post_pagination')) : ?>
<?php if(is_single()) : ?>
<?php endif; ?>
<?php endif; ?>
<?php if(!get_theme_mod('sp_post_related')) : ?>
<?php if(is_single()) : ?>
<?php get_template_part('inc/templates/related_posts'); ?>
<?php endif; ?>
<?php endif; ?>
</article>

1 个答案:

答案 0 :(得分:1)

你在这里

<?php $categories = get_the_category();?>
<div id="coordonnees" <?php echo esc_html( $categories[0]->name ) == 'annuaire' ? 'style="display:none"' : ''?> >