gpt4 book ai didi

php - (Wordpress) 不规则的 3-4-3-4 帖子结构

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

如何将 wordpress 帖子对齐到这样的不规则结构中:


帖子 1 |帖子 2 |后 3

第 4 行 |帖子 5 |帖子 6 |后 7

帖子 8 |发布 9 |发布 10

第 11 行 |后 12 | 13 号后 |后 14


帖子显示为列表。我需要一些逻辑来将帖子对齐到不规则结构中。

<?php get_header(); ?>

<!-- Getting posts -->
<div class="kategorie-vypis">
<div class="container">
<h1 class="stredny-nadpis">Kategorie</h1>
<ul>
<?php foreach((get_the_category()) as $category) { ?>
<h3><?php echo $category->category_description . ' '; ?></h3>
<?php $catVal = $category->cat_ID; }
$IDOutsideLoop = $post->ID;
global $post;
$myposts = get_posts('category=1&showposts=999'.$catVal);
foreach ($myposts as $post) { ?>
<li<?php if($IDOutsideLoop == $post->ID) { echo " class=\"current-post jeden-vypis\""; } ?>>
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail('small-thumbnail', array('class' => 'img-responsive logo-mini')); ?><span class="jeden-vypis-link"><?php the_title(); ?></span></a></li>
<?php }; ?>
</ul>
</div>
</div>


<?php get_footer(); ?>

最佳答案

只需使用几个变量:

<?php 
$control = 3;
$current = 0;
foreach((get_the_category()) as $category) {
if ($current == 0)
echo "<div>";
?>
/***************************************/
<?php
$current++;
if ($current >= $control){
echo "</div>";
$current == 0;
if($control == 3)
$control = 4;
else
$control == 3;
}
}; ?>

关于php - (Wordpress) 不规则的 3-4-3-4 帖子结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38655274/

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