2016-11-21 59 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; 

試試這個