首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WP炼金术:尝试回显索引

WP炼金术:尝试回显索引
EN

Stack Overflow用户
提问于 2012-04-21 13:46:52
回答 1查看 365关注 0票数 0

我试图向用户显示他们所在幻灯片的当前索引。使用WP Alchemy,我可以获得所有的标签和输入,以正确显示它们的名称和值。但是,当尝试使用the_index()时,在添加超过2张幻灯片后,我无法获得正确的索引以进行回显。

我已经删除了我所有的javascript,以确保它不会与jQuery的.sortable()冲突。在第二张幻灯片之后,标签或输入之外的所有名称和索引都是:_homepage_slider[slides_2][1][handle]1。我需要做什么,或者它只在输入和标签中起作用?

代码语言:javascript
复制
<?php global $wpalchemy_media_access; ?>
<div class="my_meta_control">

    <?php while($mb->have_fields_and_multi('slides_2')): ?>
    <?php $mb->the_group_open(); ?>
    <table class="meta-field sortable table" cellspacing="0">
        <tr>
            <td width="30" class="handle"><?php $mb->the_index() //Only echoes '1' after the second iteration ?></td>
            <td width="280" class="imagefield">
                <?php $mb->the_field('imgurl'); ?>
                <?php $wpalchemy_media_access->setGroupName('img-n'. $mb->get_the_index())->setInsertButtonLabel('Insert'); ?>

                <img data-image="mediafield-img-n<?php $mb->the_index() ?>" src="<?php bloginfo('template_url') ?>/framework/images/cm-no-image.jpg" />

                <div class="media-field-input hide">
                <?php echo $wpalchemy_media_access->getField(array('name' => $mb->get_the_name(), 'value' => $mb->get_the_value())); ?>
                </div>

                <div class="add-media-btn">
                <?php echo $wpalchemy_media_access->getButton(); ?>
                </div>
            </td>

            <td class="last-col">
                <?php $mb->the_field('title'); ?>
                <label for="<?php $mb->the_name(); ?>">Title</label>
                <div><input type="text" id="<?php $mb->the_name(); ?>" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/></div>

                <?php $mb->the_field('handle'); ?>
                <p>Name: <?php $mb->the_name(); //Only echoes _homepage_slider[slides_2][1][handle] after second iteration ?></p>
                <p>Index: <?php $mb->the_index(); //Only echoes '1' after second iteration ?></p>

                <a href="#" class="dodelete x-btn">Remove Slide</a>
            </td>

        </tr>
    </table><!-- /.meta-field -->
    <?php $mb->the_group_close(); ?>
    <?php endwhile; ?>

    <p style="margin-bottom:15px; padding-top:5px;"><a href="#" class="docopy-slides_2 button">Add</a></p>

</div>
EN

回答 1

Stack Overflow用户

发布于 2012-04-21 21:48:29

对于任何想知道的人来说,WP炼金术不是这样工作的。您可以向元素的name、class、id或value属性添加字段标识符。当回显索引时,它的前面需要一个"n“。

例如:

代码语言:javascript
复制
<?php $mb->the_field('handle'); ?>
<input type="hidden" class="anything-i-want-n<?php $mb->the_index() //This will work ?>" name="<?php $name = $mb->get_the_name() ?>" />
<?php echo $mb->the_index() //This will not ?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10256580

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档