gpt4 book ai didi

php - 尝试通过 PHP 将内容居中

转载 作者:行者123 更新时间:2023-11-28 01:32:58 25 4
gpt4 key购买 nike

我正在尝试使用 PHP 自动在图片发布缩略图下方居中对齐。

包括图片和目前的PHP代码。我尝试了一下,但失败得很厉害,我的 PHP 技能充其量只是平庸,对此的任何帮助将不胜感激。

enter image description here

<?php  $count = 1; 
$settings = _WSH()->option();
$query_args = array('post_type' => 'sh_services' , 'showposts' => $num , 'order_by' => $sort , 'order' => $order);

if( $cat ) $query_args['services_category'] = $cat;
$query = new WP_Query($query_args) ;
$top_heading_img= get_template_directory_uri()."/images/head-top.png";
$top_heading_img = sh_set( $settings, 'top_heading_img' ) ? sh_set( $settings, 'top_heading_img' ) : $top_heading_img;
//printr($top_heading_img);

ob_start() ;?>

<?php if( $query->have_posts() ):?>

<!--======= SERVICES =========-->
<section class="services">
<div class="container">

<!--======= TITTLE =========-->
<div class="tittle"> <img src="<?php echo $top_heading_img; ?>" alt="">
<h3><?php echo balanceTags($title);?></h3>
<p><?php echo balanceTags($text);?></p>
</div>
<ul class="row">

<?php while($query->have_posts()): $query->the_post();
global $post ;
$services_meta = _WSH()->get_meta();
?>

<!--======= SERVICE SECTION =========-->
<li class="col-md-3 col-sm-4 col-xs-6">
<section>
<!--======= SERVICE IMG =========-->
<?php the_post_thumbnail('271x337', array('class' => 'img-responsive'));?>
<div class="icon"> <img src="<?php echo sh_set($services_meta, 'small_image');?>" alt="image"> </div>

<!--======= SERVICE HOVER =========-->
<div class="ser-hover">
<p><?php echo _sh_trim(get_the_content(), $text_limit);?> <a href="<?php echo sh_set($services_meta, 'readmore_link');?>" class="read-more"><?php esc_html_e('Read more ', 'realtor');?><i class="fa fa-angle-double-right"></i></a> </p>
</div>
<a href="<?php echo sh_set($services_meta, 'readmore_link');?>" class="heading"><?php the_title();?></a> </section>
</li>

<?php endwhile;?>

</ul>
</div>
</section>

<?php endif;?>
<?php wp_reset_postdata();
return ob_get_clean();

最佳答案

根据您使用的 Bootstrap 版本,您可以使用以下任一版本

V4+

class="img-fluid mx-auto d-block"

V3

class="img-responsive center-block"

但如前所述,这是一个 CSS 问题,而不是 PHP

关于php - 尝试通过 PHP 将内容居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50862331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com