简体   繁体   English

在Wordpress中更改动态内容的边框颜色

[英]Change border colors of dynamic content in Wordpress

Sincere apologies if this has been asked before. 诚挚的道歉,如果这已经被问过了。 To be honest I didn't know what terms to search for well enough to find relevant content. 老实说,我不知道要搜索什么术语才能找到相关内容。

Goal: My company has a press page that is built using some custom PHP built into Wordpress. 目标:我公司有一个新闻页面,该页面是使用Wordpress中内置的一些自定义PHP构建的。 The press page can be seen here: http://www.hospitalityq.com/press 可以在这里看到新闻页面: http : //www.hospitalityq.com/press

My marketing manage would like to change the light gray border on the press to colors within our company palette. 我的营销经理希望将印刷机上的浅灰色边框更改为公司调色板内的颜色。 We would have 5 colors that we would like the press items to rotate throughout. 我们将有5种颜色,我们希望印刷品能够一直旋转。 Is it possible to color each press article with it's own color and have that done through adding on to our PHP script? 是否可以用自己的颜色为每篇新闻文章上色,并通过添加到我们的PHP脚本中来完成?

Below is a copy of our existing script. 以下是我们现有脚本的副本。

I hope that makes sense. 我希望这是有道理的。 I'm happy to post a mockup if that's easier. 如果很容易,我很乐意发布一个样机。

Best, Dan 最好,丹

<?php

$postID = get_the_ID();
$meta = get_post_meta($postID);
?>
  <!--pre>
  <?php
  //var_dump ($meta);
  ?>
  </pre-->
<?php
  if( has_post_thumbnail( $postID ) ):;
?>
  <div class="clear-after">
  <div class="post-image">
    <a
       href="<?php echo $meta['hq_news_articles_link'][0] ?>"
       class="vc_read_more"
       title="Read about <?php the_title_attribute(); ?>"
       target="_blank">
      <?php the_post_thumbnail($postID); ?>
    </a>
  </div>
<?php
  endif;
  $infoClass = 'post-info '. (!has_post_thumbnail( $postID ) ? 'no_image' : '');
?>
<div class="<?php echo $infoClass; ?>">
 <h4>
    <a
       href="<?php echo $meta['hq_news_articles_link'][0] ?>"
       class="vc_read_more"
       title="Read about <?php the_title_attribute(); ?>"
       target="_blank"
     >
      <?php the_title();?>
    </a>
  </h4>
      <h5>
        <?php the_date('F j, Y');?>
      </h5>
      <p><?php
          echo substr(get_the_excerpt(),0, 115);
          // echo wp_trim_words(get_the_excerpt(), 20);
          ?>&hellip;
        <br><a
       href="<?php $meta['hq_news_articles_link'][0] ?>"
       class="hq_press-read-more"
       title="Read about <?php the_title_attribute(); ?>"
       target="_self"
     >
       Read article
    </a>
   </p>
</div>
</div>

I would use CSS nth-child : 我会使用CSS nth-child

 .company { border: 1px solid black; } .company:nth-child(5n+1) { border-color: red; } .company:nth-child(5n+2) { border-color: green; } .company:nth-child(5n+3) { border-color: yellow; } .company:nth-child(5n+4) { border-color: blue; } .company:nth-child(5n+5) { border-color: purple; } 
 <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> <div class="company">company</div> 

This is what you need to do, to elaborate on the answer in the comment for using nth-child. 这是您需要做的,以详细说明注释中使用nth-child的答案。

The example below targets what you need. 下面的示例针对您的需求。 This example targets every third element and applies this style. 此示例以每三个元素为目标并应用此样式。 So in your case, using your 5 different colors, you would use: 1n+1, 2n+2, 3n+3, etc. 因此,根据您的情况,使用5种不同的颜色,您将使用:1n + 1、2n + 2、3n + 3等。

li.entry-hq_news_articles:nth-child(3n+3) {
  border: 1px solid #e31b12;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM