繁体   English   中英

如何增加WordPress的内容职位的高度?

[英]How to add height for content post of wordpress?

我想使我的WordPress内容像块一样。 我使用CSS和PHP简单代码编写了4列,并且可以正常工作。 但我希望内容也具有相同且相等的高度。

在此处输入图片说明

我使用了一个函数来限制内容中的字符,但帖子高度仍然不相等。

function ld_custom_excerpt_length( $length ) { return 10; } add_filter( 'excerpt_length', 'ld_custom_excerpt_length', 999 );

其实我知道我可以给他们像CSS这样的高度

article {height:100px;} 

但是这样做之后,内容将不再响应。

您可以使用jQuery来检测最高的内容,并将所有元素的高度设置为最高的元素。

在这种情况下, #custom_element是我的包含所有帖子的容器。

.content是一个容器,其中包含每个帖子的我的文本,图像等。

简短示例:

function resizeContent() {
    jQuery('#custom_element').each(function(){  

      // Select and loop the container element of the elements you want to equalise
      var highestBox = 0;
      jQuery('.content').css("height","");

      // Select and loop the elements you want to equalise
      jQuery('.content', this).each(function(){

        // If this box is higher than the cached highest then store it
        if(jQuery(this).height() > highestBox) {
          highestBox = jQuery(this).height(); 
        }

      });  

      // Set the height of all those children to whichever was highest 
      jQuery('.content',this).height(highestBox);

    }); 
}
//adjust dimensions when loaded
jQuery(window).on('load', function () {
    resizeContent();
});
//adjust dimensions when window size gets changed
jQuery( window ).resize(function() {
    resizeContent();
});

PHP-示例:

<div id="custom_element">
    <div class="content"></div>
    <div class="content"></div>
    .
    . 
    .
</div>

暂无
暂无

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

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