0
votes

Long title, I know :) But anyways, what I'm trying to do is hide a post from its respective category. So say I submit a post and file it under the news category, I want it to not show up in its respective category page, if need be. Weird request, I know..

The way I have went about doing this is creating a custom field called "hide" with any value, then I echo the CSS style for the div class "post" to display:none. Here is the PHP if statement:

<?php } if($hide) { ?>

echo '<style type="text/css"> .post {display:none;} </style>';

<?php } ?>

This successfully hides the div "post" when any value for the custom field "hide" is entered, but the problem is... it hides all my posts!! Because all my posts are being displayed under the div class "post" and the echoed css style is being applied to all the .post divs and not just the one I entered the custom field for.

Looking at my Wordpress posts, each post has a seperate number and div value. Theoretically, I could manually type in the id for each div and hide each post once each post is entered, but that would take way too long.

At this point, I honestly have no idea how to fix this issue so it hides only the post that I enter the custom field for. Any help would truely be appreciated! :)

Update: I forgot to mention that I'm also using other custom fields to display the post.. here is how my full php code looks:

<?php } if (is_category('audio')) { ?>
<div class="entry-summary">
<?php if (has_post_thumbnail()){ ?>
<?php if($audiohover == '5') { ?>
<div class="view view-fifth">
<?php the_post_thumbnail(); ?>
<div class="mask">
<a href="<?php echo esc_url_raw( $url ); ?>" class="info" target="_blank"><img src="else" /></a>
</div>
</div>

<?php } elseif($audiohover == '6') { ?>
<div class="view view-fifth">
<?php the_post_thumbnail(); ?>
<div class="mask">
<a href="<?php echo esc_url_raw( $url ); ?>" class="info" target="_blank"><img src="else" /></a>
</div>
</div>              

<?php } elseif($audiohover == '4') { ?>
<div class="view view-fifth">
<?php the_post_thumbnail(); ?>
<div class="mask">
<a href="<?php the_permalink(); ?>?fromwhere=audio"" class="info"><img src="img" /></a>
</div>
</div>

<?php } if($hide) { ?>



<?php } ?>

<?php } ?>

<?php } ?>

Summary of What I want to Achieve: I want to select if a post will be displayed or not in its respective category page. Example: I post something under the News category. When I goto the news category page, I want to be able to chose if the post filed under the news category will be visible or not. My way of doing this as of right now is through custom fields. Read the question to see why it isn't working properly! :(

1
¿How do you identify those posts from the others in the category?Felipe Alameda A
Wordpress randomly gives ID's for each post so an example would be "div id="post-1304", "div id="post-1304", "div id="post-1206" etc.Dyck
That, I know, but how do you know post-1304 can be displayed, for example. Do you have a filtering script, do you select them manually, ¿how?Felipe Alameda A
I inspect the elements of my website via Google Chrome :) if you could help me out with an answer it would really mean a lot!Dyck
I would be glad to do it, but first I am trying to understand the problem and I see there is no pattern to implement a method to capture those not-to-show posts. I suggest you create a custom field for those post to identify them (You can do that easily in the editor's page) and update your question with that information.Felipe Alameda A

1 Answers

0
votes

You may try this:

$hide = get_post_meta( $post->ID, 'hide', TRUE );

if ( $hide != '' ) {
  // Don't display
}
else {
  // Display post
}

UPDATED

All the code in your update is for one category, in this case audio, so this condition should be at the top, like this:

<?php
if ( is_category( 'audio' ) ) {
$hide = get_post_meta( $post->ID, 'hide', TRUE );
  if ( $hide != '' ) {
  // Don't display
}
else { ?>

<div class="entry-summary">
<?php if ( has_post_thumbnail() ) { ?>
    <?php if ( $audiohover == '5' ) { ?>
      <div class="view view-fifth">
        <?php the_post_thumbnail(); ?>
        <div class="mask">
          <a href="<?php echo esc_url_raw( $url ); ?>" class="info" target="_blank"><img src="else" /></a>
        </div>
      </div>

      <?php
    }
    elseif ( $audiohover == '6' ) {
      ?>
      <div class="view view-fifth">
        <?php the_post_thumbnail(); ?>
        <div class="mask">
          <a href="<?php echo esc_url_raw( $url ); ?>" class="info" target="_blank"><img src="else" /></a>
        </div>
      </div>

      <?php
    }
    elseif ( $audiohover == '4' ) {
      ?>
      <div class="view view-fifth">
        <?php the_post_thumbnail(); ?>
        <div class="mask">
          <a href="<?php the_permalink(); ?>?fromwhere=audio"" class="info"><img src="img" /></a>
        </div>
      </div>

      <?php  } } } }?>

That is, if I understood right.