dro59505 2019-04-23 03:13
浏览 43

如何基于ID回显WordPress图像

I'm trying to echo out images and custom fields, however, I think I'm not properly connecting the ID with the variable fields. I'm using blog posts with Advanced Custom Fields in WordPress. I want the same effect as a repeater, but because it's not in a repeater, I'm not using the standard if/while statements.

I'm not well versed in PHP in regards to using with WordPress, but I've already tried to assign IDs to each custom field.

    $englishBio = get_field('english_bio', $post->ID);

I've also tried (which might actually be the same thing)

    $id = $post->ID
    $englishBio = get_field('english_bio', $id);

Here's what the image looks like: Post titleswith post ID number below

I've seen a few examples like the following (I'm looking for the same idea, but I can't simply hardcode the post ID numbers. I need to pull the ID from the image associated with its ID):

    <p><?php the_field('field_name', 123); ?></p>
<!--Pull Events category from posts-->
<?php $args = array('post_type' => 'post', 'field'=> 'ID', 'category_name'=> 'portraits', 'order' => 'ASC', 'orderby' => 'meta_value_num', 'posts_per_page' => -1); 
$catquery = new WP_Query( $args ); ?>

<?php while($catquery->have_posts()) : $catquery->the_post();
    //Convert to variables
    $id = $post->ID;
    $name = get_the_title();
    $englishBio = get_field('english_bio');
    $spanishBio = get_field('spanish_bio');
    $image = get_field('image');

?> 
    <div class="photo">
        <?php echo $image ? '<img src="'. $image['url'] .'" alt="'. $image['alt'] .'" title="'. $image['title'] .'" />' : ''; ?>
        <?php echo $name ? '<h2>'. $name .'</h2>' : ''; ?>
        <?php echo $englishBio ? $englishBio : ''; ?>
        <?php echo $spanishBio ? $spanishBio : ''; ?>
        <?php echo $id; ?>
    </div>
<?php endwhile; ?>

The end echoing of the ID is to just see if the post id numbers are displaying, which they are, and yes, they are correct, however, the image, English content, and Spanish content are not displaying at all, even if I do something like:

$englishBio = get_field('english_bio', $post->ID);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示
    • ¥15 求三国群英传pl国战时间的修改方法
    • ¥15 matlab代码代写,需写出详细代码,代价私
    • ¥15 ROS系统搭建请教(跨境电商用途)
    • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。