首页 文章

排除Wordpress帖子显示在各自的类别中

提问于
浏览
0

很长的 Headers ,我知道:)但无论如何,我要做的是隐藏其各自类别的帖子 . 所以说我提交一个帖子并将其归档在新闻类别下,我希望它不会出现在各自的类别页面中,如果需要的话 . 奇怪的要求,我知道..

我这样做的方法是创建一个名为"hide"的自定义字段,其中包含任何值,然后我将div类"post"的CSS样式回显为 display:none . 这是PHP if语句:

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

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

<?php } ?>

当输入自定义字段"hide"的任何值时,这成功隐藏了div "post",但问题是......它隐藏了 all 我的帖子!因为我的所有帖子都显示在div类"post"下,并且回显的css样式正在应用于所有.post div,而不仅仅是我输入自定义字段的那个 .

看看我的Wordpress帖子,每个帖子都有一个单独的数字和div值 . 从理论上讲,我可以手动输入每个div的id并在每个帖子输入后隐藏每个帖子,但这会花费太长时间 .

在这一点上,我真的不知道如何解决这个问题所以它只隐藏我输入自定义字段的帖子 . 真的很感激任何帮助! :)

更新:我忘了提到我还使用其他自定义字段来显示帖子..这是我的完整PHP代码的样子:

<?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 回答

  • 0

    你可以试试这个:

    $hide = get_post_meta( $post->ID, 'hide', TRUE );
    
    if ( $hide != '' ) {
      // Don't display
    }
    else {
      // Display post
    }
    

    UPDATED

    更新中的所有代码都是针对一个类别的,在本例中为 audio ,因此这个条件应该位于顶部,如下所示:

    <?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  } } } }?>
    

    也就是说,如果我理解正确的话 .

相关问题