Support » Plugin: Block Lab » Repeater – row-index

Viewing 4 replies - 1 through 4 (of 4 total)
  • Update: I solved it with two loops and a counter-variable. It was for an automatic structured data faq-markup:

    $j = $i; // i=counter of the first loop
    $i = 1;
    ?>
    <!– JSON-LD FAQ-Markup –>
    <?php
    global $wp;
    $url = home_url( $wp->request );
    if(block_rows(‘faqfrage’)): ?>

    <script type = “application/ld+json”> {
    “@context”: “https://schema.org”,
    “@type”: “FAQPage”,
    “name”: “<?php echo $url;?>”,
    “mainEntity”: [
    <?php
    while(block_rows(‘faqfrage’)):
    block_row(‘faqfrage’);?>
    {
    “@type”: “Question”,
    “name”: “<?php block_sub_field(‘frage’);?>”,
    “answerCount”: 1,
    “acceptedAnswer”: {
    “@type”: “Answer”,
    “text”: “<?php block_sub_field(‘antwort’);?>”} }
    <?php
    $i = $i+1;
    if($i<$j){
    echo “,”; }
    endwhile;?>
    ]
    }
    </script>
    <?php endif;?>

    Plugin Author Ryan Kienstra

    (@ryankienstra)

    Hi @max2411,
    Thanks for bringing this up, and thanks for posting your solution.

    You probably saw this, but there’s no function now that gets the index of a row.

    Plugin Author Luke Carbis

    (@lukecarbis)

    @max2411 We just created a pull request to add this functionality – check it out here: https://github.com/getblocklab/block-lab/pull/429

    Hopefully we’ll have the functions block_row_count( $name ) and block_row_index() in the next release.

    Very cool, thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.