Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

php - splitting the paragraph into 2 sections in wordpress

I'm building a property section in WordPress that leaves me with a long and excruciating list of information when the code draws the data. This list should be divided into 2 sections to save more space on the page when on desktops, etc.

<a name="rooms"></a>
<h3><?php echo __("Property Details", "wppf"); ?></h3>
<?php foreach ($paragraphs as $paragraph) : ?>

    <div class="clearfix">
        <?php if ($paragraph['name'] != '') : ?>
            <h4><?php echo $paragraph['name'] ?></h4>
        <?php endif; ?>
        <?php if ($paragraph['filesortorder'] != '') : ?>
            <?php echo ($paragraph['filesortorder']); ?>
        <?php endif; ?>
        <p>
            <?php if ($paragraph['dimensions'] != "") : ?>
                <em><?php echo $paragraph['dimensions'] ?></em>
                <br />
            <?php endif; ?>
            <?php echo $paragraph['description'] ?>
        </p>
    </div>
<?php endforeach; ?>
<?php foreach ($links as $link) : ?>
    <div class="clearfix">
        <a href="<?php echo $link['url']; ?>" target="_blank">
            <?php echo (empty($link['name'])) ? $link['url'] : $link['name']; ?>
        </a>
    </div>
<?php endforeach; ?>

There is a maximum of 10 sections that it fills in and I want to split that into 2 groups of 5.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Something like...

if(count($paragraphs) > 5) {
   $paragraphs2 = array_splice($paragraphs, 5);
}

Would let you split the paragraphs > 5 into another array.

You'd then just need to output those in your code as you see fit - something like:

<?php foreach ($paragraphs2 as $paragraph2) :?>
<div class="clearfix">

    <?php if ($paragraph2['name']!=''):?>
    <h4>
        <?php echo $paragraph2['name'] ?>
    </h4>
    <?php endif; ?>
    <?php if ($paragraph2['filesortorder']!=''):?>
    <?php echo ($paragraph2['filesortorder']); ?>
    <?php endif; ?>
    <p>
        <?php if ($paragraph2['dimensions']!=""):?>
        <em>
            <?php echo $paragraph2['dimensions'] ?>
        </em>
        <br />
        <?php endif;?>
        <?php echo $paragraph2['description'] ?>
    </p>
</div>
<?php endforeach;?>

Should get you started to loop through and repeat the relevant display code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...