mercredi 17 janvier 2018

Wordpress - Hide blog meta data if in specific category

I have a standard wordpress blog here: http://ift.tt/2D46xp7 and I've created a new category called clients.

The clients posts on this archive page will have different meta data that the standard blog post, so I want to get rid of the excerpt, date and author etc.

To achieve this I tried adding a conditional bit of code that said, IF the category of this post area is 'client' then echo style="display:none;" inside the div.

Here's the line of code I'm trying:

<p<?php if ( in_category( 'client' )) { echo 'style="display:none;"' }?>>This is not client</p>

Here's the loop it appears in:

<div class="container blog-card-container">

    <div class="row">


        <?php if ( have_posts() ) : ?>

            <?php /* Start the Loop */ ?>

            <?php while ( have_posts() ) : the_post(); ?>

        <div class="col-md-4">  
        <a href="<?php the_permalink(); ?>">
                    <div class="card">

                        <div class="blog-thumb-container">
                            <?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?>
                        </div>




                        <div class="blog-clients-card-block">
                            <?php if( get_field('quote_name') ): ?><p class="client-name" style="color:<?php the_field('client_brand_colour'); ?>;"><?php the_field('quote_name'); ?></p><?php endif; ?>


                                <p<?php if ( in_category( 'client' )) { echo 'style="display:none;"' }?>>This is not client</p>


                            <p class="blog-cat-label"><?php the_category(', '); ?></p>
                            <h2 class="blog-card-title"><?php the_title(); ?></h2>
                            <p class="card-text"><?php the_excerpt(__('(more…)')); ?></p>
                            <p><strong><?php the_author(); ?></strong> | <?php the_date(); ?> </p>
                        </div>
                    </div>
                </a>
        </div>

        <?php understrap_pagination(); ?>

        <?php endwhile; wp_reset_postdata(); endif; ?>

    </div>

</div>

But including it here breaks the loop and the page doesn't load... I'm not sure what I'm doing wrong, or even if there might be a better solution?

I essentially want to show one set of meta for post thumbnails with the category 'client' and then another set for all other categories in the blog.

I guess it could be IF category of container is client then show META1 else show META2.

Any help would be massively appreciated :)

Aucun commentaire:

Enregistrer un commentaire