如何在简码中定义变量

时间:2018-08-31 11:26:51

标签: wordpress-theming wordpress-shortcode

我为我的wordpress网站写了一个“简码”,但是由于不确定的变量,在phpstorm提示中我遇到了几个错误。所以我的问题是,我应该如何用短代码定义变量,请先谢谢。 对不起,如果这是重复的线程。 这是代码。

我未定义的var是:$ ids,$ type,$ posts

function jumbotron_function($atts)
{
    extract (shortcode_atts (array(
        'type' => 'post',
        'posts' => '1',
        'icon' => '',
        'ids' => '',
    ), $atts));
    $id_array = explode (',', $ids);
    $args = array(
        'post_type' => $type,
        'posts_per_page' => $posts,
        'post__in' => $id_array,
    );

    ob_start (); ?>
    <div class="content_area ijumbotron">
        <div class="row progresss">
            <div id="jumbotron" class="jumbotron">
                <?php $jumbotron = new WP_Query($args);
                if ($jumbotron->have_posts ()) : ?>
                    <ul class="shortcodecarousel owl-carousel owl-theme clearfix">
                        <?php while ($jumbotron->have_posts ()) : $jumbotron->the_post (); ?>
                            <?php $english_title = get_field ('manual_english_name', false, false); ?>
                            <?php $jumbotron_cover = get_field ('single_page_background', false, false);
                            $jumbotron_size = 'jumbo-cover'; ?>
                            <li id="jumbotron-<?php the_ID (); ?>" class="blocks">
                                <div class="container jumbotron_block">
                                    <div class="cards">
                                        <a class="details_button" href="<?php the_permalink (); ?>"> <i
                                                    class="fas fa-play"></i> </a>
                                        <?php if (has_post_thumbnail ()) {
                                            the_post_thumbnail ('jumbotron');
                                        } ?>
                                    </div>
                                    <section class="section">
                                        <?php if (!empty($jumbotron_cover)) { ?>
                                            <div class="jumbotron_cover">
                                                <?php echo wp_get_attachment_image ($jumbotron_cover, $jumbotron_size); ?>
                                            </div>
                                        <?php } ?>
                                        <h3>
                                            <a href="<?php the_permalink (); ?>">
                                                <?php echo $english_title; ?>
                                            </a>
                                        </h3>
                                        <div class="jumbotron_meta">
                                            <span><?php the_genre (); ?></span>
                                        </div>
                                        <div class="col-md-8 col-sm-12 padding-off">
                                            <?php my_excerpt ('mini'); ?>
                                        </div>
                                        <div class="clear"></div>
                                        <a class="jumbotron_details hidden-sm hidden-xs"
                                           href="<?php the_permalink (); ?>">
                                            <i class="far fa-file-alt"></i> <?php esc_html_e ('جزئیات بیشتر'); ?>
                                        </a>
                                    </section>
                                </div>
                            </li>
                        <?php endwhile; ?>
                    </ul>
                <?php endif; ?>
            </div>
        </div>
    </div>
    <?php
    $return_string = ob_get_contents ();
    ob_end_clean ();
    return $return_string;
    wp_reset_postdata ();
}

add_shortcode ('jumbotron', 'jumbotron_function');

0 个答案:

没有答案