Lighbox仅显示Wordpress中当前帖子的数据

时间:2016-02-25 09:01:08

标签: javascript jquery wordpress shortcode

我希望通过使用短代码来展示一些灯箱功能。除了ligthbox中显示的数据之外,代码工作正常。它仅显示循环中最新帖子的数据。如何才能让灯箱显示属于帖子的数据?

<?php
    // Posts are found
    if ( $posts->have_posts() ) {
        while ( $posts->have_posts() ) :
            $posts->the_post();
            global $post;
            ?>
            <center>
            <div id="su-post-<?php the_ID(); ?>" class="su-post">
                <?php if ( has_post_thumbnail() ) : ?>
                    <a class="su-post-thumbnail" href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
                <?php endif; ?>
                <div class="su-post-excerpt">

                    <!-- Shows the button and the hidden lightbox -->
                    <?php echo do_shortcode ('[su_lightbox type="inline" src="#showInfo"][su_button] Info[/su_button][/su_lightbox]'); ?>
                    <!-- Shows the lightbox if button is clicked with the data -->
                    <?php echo do_shortcode ('[su_lightbox_content id="showInfo"][su_meta key="info" default="Geen tekst"][/su_lightbox_content]'); ?>

                    <?php echo do_shortcode ('[su_lightbox type="inline" src="#showVideo"][su_button] Video[/su_button][/su_lightbox]'); ?>
                    <?php echo do_shortcode ('[su_lightbox_content id="showVideo"][su_video url="{su_meta key=video}"][/su_lightbox_content]'); ?>

                    <?php echo do_shortcode ('[su_lightbox type="inline" src="#showFoto"][su_button] Foto[/su_button][/su_lightbox]'); ?>
                    <?php echo do_shortcode ('[su_lightbox_content id="showFoto"][su_meta key="fotos" default="Geen fotos"][/su_lightbox_content]'); ?>

                </div>
            </div>

            </center>
            <?php
        endwhile;  echo do_shortcode ('[su_lightbox_content id="showInfo"][su_meta key="info" default="Geen tekst"][/su_lightbox_content]'); 
    }
    // Posts not found
    else {
        echo '<h4>' . __( 'Posts not found', 'shortcodes-ultimate' ) . '</h4>';
    }
?>

1 个答案:

答案 0 :(得分:0)

通过在while循环中添加计数器并使用短代码SRC和ID字段中的变量。我需要为每个帖子提供唯一的ID。

$n = 0;  /* Outside While Loop */

echo do_shortcode( '[su_lightbox type="inline" src="#showInfo'.$n.'"][su_button] Info[/su_button][/su_lightbox] ');
echo do_shortcode( '[su_lightbox_content id="showInfo'.$n.'"][su_meta key="info" default="Geen tekst"][/su_lightbox_content]' );

$n++;   /* Inside While Loop */