Lighbox只显示Wordpress中当前帖子的数据
Lighbox only showing data of the current post in Wordpress
我想通过使用短代码来展示一些灯箱功能。除了 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>';
}
?>
通过在 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 */
相关文章:
- 如何将json数据显示为html
- 解耦按钮(两个按钮同时切换),并根据数据显示相应的按钮
- 将json提要数据显示为html
- 使用Ajax Get方法将数据显示到特定元素中
- 如何将数据显示为线性highChart
- Json显示来自网站的数据显示仅未定义
- 使 ajax 请求和成功数据显示在 id <选择>选择>部分中
- 在按钮单击时将图像URL数据显示到弹出框中,而无需禁用背景
- 如何在循环中将 json 数据显示为 HTML
- 如何使用javascript在html中将firebase数据显示为列表
- PHP同时循环数组数据显示到javascript中
- 原始图像数据显示
- 如何在 y 轴上将数据显示为 KB、MB、GB、TB
- Ajax 数据显示在包含 10 行的表中
- 如何让 Mathjax.js 与 ANCII.js 将附加的 json 数据显示为正确的公式
- 调用 Worklight 适配器并将列表视图中的 JSON 数据显示为字符串
- Jquery/Javascript Datatables : 如何在行选择时将行数据显示到 html 文本字段中
- 双击 td 时,如何在警告框中将数据库中的数据显示为 html 表
- 日期之间的数据显示所有头
- 如何使用模板中的数据显示谷歌地图