【问题标题】:domPDF and ACF repeater fieldsdomPDF 和 ACF 转发器字段
【发布时间】:2020-08-13 14:15:59
【问题描述】:

我正在使用 domPDF 在我网站的某些页面上生成 PDF

我遇到的问题是它不允许我使用重复值(通过任何类型的循环),它似乎不想在创建 PDF 时生成它们。

如果我将转发器字段本身称为变量,它会返回“数组”,所以我认为它可以以某种方式工作。

似乎首先需要生成中继器,然后将其包含在内(可能作为变量?),但我不确定如何执行此操作。

有人知道我怎样才能让它工作吗?

这是我的 ACF 中继器代码:

<?php if( have_rows('team_contact_details') ): ?>
    <div class="profile-item">
        <ul class="list-contact">
        <?php while( have_rows('team_contact_details') ): the_row(); ?>
            <li>
                <div class="list-contact-letter">
                    <?php the_sub_field("contact_label"); ?>
                </div>
                <div class="list-contact-detail">
                    <?php
                        if(get_sub_field('contact_link') == 'phone' ) {
                            echo '<a href="tel:' . get_sub_field("phone_number") . '">' . get_sub_field("phone_number") . '</a>';
                        } else if(get_sub_field('contact_link') == 'email' ) {
                            echo '<a href="mailto:' . get_sub_field("email_address") . '">' . get_sub_field("email_address") . '</a>';
                        }
                    ?>
                </div>
            </li>
        <?php endwhile; ?>
        </ul>
    </div>
<?php endif; ?>

这是我的 domPDF 代码:

    //Print PDF
    require_once get_template_directory() . '/dompdf/autoload.inc.php';
    use Dompdf\Dompdf; 

    $content = '
    <html>
        <head></head>
        <body>
        
            <div class="person">
                <img src="' . get_field('page_image') . '"/>
            </div>
  
            <h1>' . get_the_title() . '</h1>

            <div class="pdf-label">' . get_field('team_academic') . '</div>
            <div class="pdf-label">' . get_field('team_position') . '</div>

            
            <<<< Attempting to put repeater values here as unordered list >>>>
            
                
        </body>
    </html>
    ';
     
    // instantiate and use the dompdf class
    $dompdf = new Dompdf(array(
        'enable_remote' => true
        )
    );
    $dompdf->loadHtml($content);
     
    // (Optional) Setup the paper size and orientation
    $dompdf->set_paper( 'letter' , 'portrait' );
     
    // Render the HTML as PDF
    $dompdf->render();
     
    $doctitle = get_the_title();
    $dompdf->stream($doctitle);
     

谢谢

【问题讨论】:

    标签: wordpress advanced-custom-fields dompdf


    【解决方案1】:

    我明白了。仅供参考,是这样的:

            if( have_rows('team_contact_details')) :
                while(have_rows('team_contact_details')) : the_row();
                    $content .= '<h3>'. get_sub_field('contact_label') .'</h3>';
                    
                    if(get_sub_field('contact_link') == 'phone') {
                        $content .= '<div>'. get_sub_field('phone_number') .'</div>';
                    } else {
                        $content .= '<div>'. get_sub_field('email_address') .'</div>';
                    }
                endwhile;
            endif;
    

    【讨论】:

      猜你喜欢
      • 2018-10-06
      • 2020-04-04
      • 2018-04-12
      • 2021-04-26
      • 2019-05-24
      • 2014-07-07
      • 1970-01-01
      • 2016-06-17
      • 2020-05-15
      相关资源
      最近更新 更多