Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将CSS类分配给第一个和第三个html元素_Php_Html_Css_Wordpress - Fatal编程技术网

Php 将CSS类分配给第一个和第三个html元素

Php 将CSS类分配给第一个和第三个html元素,php,html,css,wordpress,Php,Html,Css,Wordpress,我正在使用wordpress插件来显示最近的帖子。我已经更改了模板,以便最近的3篇文章将显示在主页上的特色框中。问题是第一个盒子需要分配“alpha”类,最后一个盒子需要分配“omega”类,以便它们正确匹配。我的PHP技能没有这么高 模板位于template.php页面中。守则的大部分内容如下: /** * The format for templates changed since version 0.17. * Since this code is included inside Ca

我正在使用wordpress插件来显示最近的帖子。我已经更改了模板,以便最近的3篇文章将显示在主页上的特色框中。问题是第一个盒子需要分配“alpha”类,最后一个盒子需要分配“omega”类,以便它们正确匹配。我的PHP技能没有这么高

模板位于template.php页面中。守则的大部分内容如下:

/**
 * The format for templates changed since version 0.17.
 * Since this code is included inside CatListDisplayer, $this refers to
 * the instance of CatListDisplayer that called this file.
 */

/* This is the string which will gather all the information.*/
$lcp_display_output = '';

// Show category link:
$lcp_display_output .= $this->get_category_link('strong');

//Add 'starting' tag. Here, I'm using an unordered list (ul) as an example:
$lcp_display_output .= '<div class="lcp_catlist info_box_area row clearfix" id="box_area_0">';

/**
 * Posts loop.
 * The code here will be executed for every post in the category.
 * As you can see, the different options are being called from functions on the
 * $this variable which is a CatListDisplayer.
 *
 * The CatListDisplayer has a function for each field we want to show.
 * So you'll see get_excerpt, get_thumbnail, etc.
 * You can now pass an html tag as a parameter. This tag will sorround the info
 * you want to display. You can also assign a specific CSS class to each field.
 */

foreach ($this->catlist->get_categories_posts() as $single){
  //Start a List Item for each post:
  $lcp_display_output .= '<div class="one-third column info_box alpha omega">';

  //Post Thumbnail
  $lcp_display_output .= $this->get_thumbnail($single);

  //Show the title and link to the post:
  $lcp_display_output .= $this->get_post_title($single);

  //Show comments:
  $lcp_display_output .= $this->get_comments($single);

  //Show date:
  $lcp_display_output .= ' ' . $this->get_date($single, 'span', 'lcp-date');

  //Show author
  $lcp_display_output .= $this->get_author($single);

  //Custom fields:
  $lcp_display_output .= $this->get_custom_fields($this->params['customfield_display'], $single->ID);

  /**
   * Post content - Example of how to use tag and class parameters:
   * This will produce:<p class="lcp_content">The content</p>
   */
  $lcp_display_output .= $this->get_content($single, 'p', 'lcp_content');

  /**
   * Post content - Example of how to use tag and class parameters:
   * This will produce:<div class="lcp_excerpt">The content</div>
   */
  $lcp_display_output .= $this->get_excerpt($single, 'div', 'lcp_excerpt');

  //Close li tag
  $lcp_display_output .= '</div>';

}

$lcp_display_output .= '</div>';
/**
*自版本0.17以来,模板的格式已更改。
*由于此代码包含在CatListDisplayer中,$表示
*调用此文件的CatListDisplayer的实例。
*/
/*这是将收集所有信息的字符串*/
$lcp_显示_输出=“”;
//显示类别链接:
$lcp_显示_输出。=$this->get_category_链接('strong');
//添加“开始”标记。这里,我以无序列表(ul)为例:
$lcp_显示_输出。='';
/**
*帖子循环。
*这里的代码将针对类别中的每个帖子执行。
*如您所见,不同的选项是从上的函数调用的
*$此变量是CatListDisplayer。
*
*CatListDisplayer对我们要显示的每个字段都有一个函数。
*因此,您将看到get_摘录、get_缩略图等。
*现在可以将html标记作为参数传递。此标签将对信息进行排序
*您想要显示。您还可以为每个字段指定特定的CSS类。
*/
foreach($this->catlist->get\u categories\u posts()作为$single){
//为每个帖子启动一个列表项:
$lcp_显示_输出。='';
//后缩略图
$lcp\u display\u output.=$this->get\u缩略图($single);
//显示文章的标题和链接:
$lcp\u display\u output.=$this->get\u post\u title($single);
//显示评论:
$lcp\u显示\u输出。=$this->get\u注释($single);
//放映日期:
$lcp_显示_输出。=''.$this->get_日期($single,'span,'lcp date');
//节目作者
$lcp\u display\u output.=$this->get\u author($single);
//自定义字段:
$lcp_display_output.=$this->get_custom_字段($this->params['customfield_display'],$single->ID);
/**
*Post内容-如何使用标记和类参数的示例:
*这将产生:

内容

*/ $lcp_display_output.=$this->get_content($single,'p','lcp_content'); /** *Post内容-如何使用标记和类参数的示例: *这将产生:内容 */ $lcp_display_output.=$this->get_extract($single,'div','lcp_extract'); //关李牌 $lcp_显示_输出。=''; } $lcp_显示_输出。='';
我的第一个想法是为每个div元素自动增加一个类,然后专门格式化这些元素,但是如果有更简单的方法直接添加alpha和omega类,那就太好了

CSS:

.lcp_catlist .info_box:first-child, .lcp_catlist .info_box:last-child  {
  opacity: 0.3
}

要在PHP中实现这一点,只需将条件添加到循环中

$i = 1;

foreach ($this->catlist->get_categories_posts() as $single){
  //Start a List Item for each post:
  if ($i == 1)
    $lcp_display_output .= '<div class="one-third column info_box alpha">';
  elseif ($i == 3)
    $lcp_display_output .= '<div class="one-third column info_box omega">';
  else
    $lcp_display_output .= '<div class="one-third column info_box">';

  // the rest of your foreach code
  ...

  $i++;

}
$i=1;
foreach($this->catlist->get\u categories\u posts()作为$single){
//为每个帖子启动一个列表项:
如果($i==1)
$lcp_显示_输出。='';
elseif($i==3)
$lcp_显示_输出。='';
其他的
$lcp_显示_输出。='';
//foreach代码的其余部分
...
$i++;
}

为什么不简单尝试一下:

$post_position = 1;

foreach ($this->catlist->get_categories_posts() as $single){
  //Start a List Item for each post:
  if ($post_position == 1){
      $lcp_display_output .= '<div class="one-third column info_box alpha">';
  }elsif ($post_position == 3){
      $lcp_display_output .= '<div class="one-third column info_box omega">';
  }else{
      $lcp_display_output .= '<div class="one-third column info_box">';
  }
  //Post Thumbnail
  $lcp_display_output .= $this->get_thumbnail($single);

  //Show the title and link to the post:
  $lcp_display_output .= $this->get_post_title($single);

  //Show comments:
  $lcp_display_output .= $this->get_comments($single);

  //Show date:
  $lcp_display_output .= ' ' . $this->get_date($single, 'span', 'lcp-date');

  //Show author
  $lcp_display_output .= $this->get_author($single);

  //Custom fields:
  $lcp_display_output .= $this->get_custom_fields($this->params['customfield_display'], $single->ID);

  /**
   * Post content - Example of how to use tag and class parameters:
   * This will produce:<p class="lcp_content">The content</p>
   */
  $lcp_display_output .= $this->get_content($single, 'p', 'lcp_content');

  /**
   * Post content - Example of how to use tag and class parameters:
   * This will produce:<div class="lcp_excerpt">The content</div>
   */
  $lcp_display_output .= $this->get_excerpt($single, 'div', 'lcp_excerpt');

  //Close li tag
  $lcp_display_output .= '</div>';

  $post_position++;
}
$post\u position=1;
foreach($this->catlist->get\u categories\u posts()作为$single){
//为每个帖子启动一个列表项:
如果($post_position==1){
$lcp_显示_输出。='';
}elsif($post_position==3){
$lcp_显示_输出。='';
}否则{
$lcp_显示_输出。='';
}
//后缩略图
$lcp\u display\u output.=$this->get\u缩略图($single);
//显示文章的标题和链接:
$lcp\u display\u output.=$this->get\u post\u title($single);
//显示评论:
$lcp\u显示\u输出。=$this->get\u注释($single);
//放映日期:
$lcp_显示_输出。=''.$this->get_日期($single,'span,'lcp date');
//节目作者
$lcp\u display\u output.=$this->get\u author($single);
//自定义字段:
$lcp_display_output.=$this->get_custom_字段($this->params['customfield_display'],$single->ID);
/**
*Post内容-如何使用标记和类参数的示例:
*这将产生:

内容

*/ $lcp_display_output.=$this->get_content($single,'p','lcp_content'); /** *Post内容-如何使用标记和类参数的示例: *这将产生:内容 */ $lcp_display_output.=$this->get_extract($single,'div','lcp_extract'); //关李牌 $lcp_显示_输出。=''; $post_position++; }