Shortcode中的Wordpress页面ID

时间:2014-08-11 07:41:07

标签: wordpress post shortcode

我正在使用一个名为InPost Gallery的插件。我已将短代码添加到模板文件中,但短代码需要帖子ID才能找到与页面相关的图像。是否可以将帖子ID添加到模板文件中的短代码中?

这就是我现在所拥有的:

<?php echo do_shortcode("[inpost_nivo slide_width='600px' slide_height='auto' thumb_width='75' thumb_height='75' post_id="28" skin='light' transition_effect='random' transition_speed='600' autoslide='5000' control_nav='1' control_nav_thumbs='1' direction_nav='1' direction_nav_hide='0' controlNavThumbs='0' random_start='0' pause_on_hover='1' show_description='1' box_rows='4' box_cols='8' slices='15' start_slide='0' id='' random='0' group='0' show_in_popup='0' album_cover='' album_cover_width='200' album_cover_height='200' popup_width='800' popup_max_height='600' popup_title='Gallery' type='nivo'][/inpost_nivo]"); ?>

您可以看到post_id设置为28.这需要根据当前正在查看的页面进行更改。

如果可能,听取您的建议会很有帮助。

非常感谢

1 个答案:

答案 0 :(得分:0)

如果它在循环中,您可以使用:

<?php 

// Display shortcode for current post:

$s = sprintf( '[inpost_nivo post_id="%d"]', get_the_ID() );

echo do_shortcode( $s ); 

?>

您还可以尝试跳过post_id属性,看看它是否具有相同的默认设置。

相关问题