dongxi7609 2013-05-07 15:25 采纳率: 0%
浏览 48

显示Wordpress自定义字段$ value

I am attempting to display, outside of the loop, an alternative, shortened post title using custom fields under a set of 8 post featured image thumbnails in a slidesow. I can display the corresponding post's title under these thumbnails with this snippet of code:

<?php $titletext = get_the_title(); echo( $arr[$i]['titletext'] ); ?>

And I can display the custom field within the loop:

<?php $key="short_title"; echo get_post_meta($post->ID, $key, true); ?>

But any combination of the two that I've tried outside of the loop returns nothing or returns "Array" under each thumbnail. The solution feels obvious but it's eluding me. Can someone show me how to do this correctly?

Adding more code for clarification:

    <?php if (have_posts()) : while (have_posts()) : the_post();
     global $post; ?>
        <?php if ( $responsive ) { ?>
            <li class="slide">
        <?php } else { ?>
            <div class="slide">
        <?php } ?>
                <?php
                $width = $responsive ? 560 : 558;
                $height = 340;
                $small_width = 110;
                $small_height = 63;
                $titletext = get_the_title();

                $thumbnail = get_thumbnail($width,$height,'',$titletext,$titletext,false,'Featured');

                $arr[$i]['thumbnail'] = get_thumbnail($small_width,$small_height,'',$titletext,$titletext,false,'Small');
                $arr[$i]['titletext'] = $titletext;

                $thumb = $thumbnail["thumb"];
                print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?>
                <div class="featured-top-shadow"></div>
                <div class="featured-bottom-shadow"></div>  
                <div class="featured-description scrollcustom">
                <div class="feat_desc">
                    <h2 class="featured-title"><a href="<?php the_permalink(); ?>"><?php the_title()  ?></a></h2>

                        <p>                 <?php $key="short_title"; echo $shorttitle; ?> <?php the_content(); ?></p>
                    </div>

                </div> <!-- end .description -->

        <?php if ( $responsive ) { ?>
            </li> <!-- end .slide -->
        <?php } else { ?>
            </div> <!-- end .slide -->
        <?php } ?>
        <?php $i++; endwhile; endif; wp_reset_query(); ?>
<?php if ( $responsive ) { ?>
    </ul> <!-- end .slides -->
<?php } else { ?>
    </div> <!-- end #slides -->
<?php } ?>
</div> <!-- end #featured -->

<div id="controllers" class="clearfix">
    <ul>
        <?php for ($i = 0; $i < $featured_num; $i++) { ?>
            <li>
                <div class="controller " >
                    <a href="#"<?php if ( $i == 0 ) echo ' class="active"'; ?>>
                    <?php $titletext ?>
                        <?php print_thumbnail( $arr[$i]['thumbnail']['thumb'], $arr[$i]['thumbnail']["use_timthumb"], $arr[$i]['titletext'], $small_width, $small_height ); ?>
                    <span class="overlay"></span><br>
                                    <?php echo( $arr[$i]['titletext'] ); ?>  
                    </a>
                </div>  
            </li>   
        <?php } ?>
  • 写回答

1条回答 默认 最新

  • 普通网友 2013-05-07 16:12
    关注

    You need global $post if you're outside of the loop

    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行