2016-11-21 61 views
-1

我有一个代码,返回与图像集的图库编号1。PHP代码在wordpress中使用自定义字段的PHP代码

<?php echo photo_gallery(1); ?> 

但我需要使用此代码

<?php the_field('number'); ?> 

在每一个岗位与自定义字段改数字“1”到数字“2”,“3”等第一码内

我需要的是这样的:

<?php echo photo_gallery( <?php the_field('number'); ?> ); ?> 

结果:

<?php echo photo_gallery(2); ?> 

<?php echo photo_gallery(3); ?> 
+5

[php php内部处理wordpress中的自定义字段]可能重复(http://stackoverflow.com/questions/40703924/php-inside-php-to-process-custom-field-in-wordpress) – 2016-11-21 21:41:48

+1

请不要多次发布相同的问题。 – 2016-11-21 21:42:16

回答

0

如果你真的有一个自定义字段number,你的代码应该是以下几点:

<?php echo photo_gallery(get_the_field('number')); ?> 
0

,如果你想要得到这个职位,然后给后面的数字则请按照代码

$cnt=1; 
$queryarry=array('post_type' => 'post' ,'posts_per_page' => 9); 
while (have_posts()) : the_post(); 
    echo photo_gallery($cnt); 
    $cnt++; 
endwhile; 

试试这个