简体   繁体   中英

Add multiple Instagram feeds to theme from username or user ID

I need to be able to let users put in either their Instagram username or user ID into a custom field. I need the feed to export just the recent images, and I found a plugin that works well for the most part. I am using Instagram Feed by Smash Balloon, and I have found that I can use the following code in my theme to display a feed the way I need to:

<?php echo do_shortcode("[instagram-feed id='username']"); ?>

I need to be able to replace the username with the User Id that a user can insert into the Advanced Custom Field text field I have created. I know I can echo that code with this:

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

How can I take what is echoed from my the_field parameter and insert it into the username space in my shortcode?

If there is a better way to allow for multiple feeds to be added into Custom Post Types I am open to it, but this solved all other issues I had with styling, needing multiple feeds, etc.

You can assign a variable to your advanced custom field for it to be echoed within the Instagram Shortcode username attribute.

 $custom_acf_field = the_field('instagram_field'); echo do_shortcode("[instagram-feed id=$custom_acf_field]"); 

To then allow multiple feeds/Shortcodes you could wrap the above in a foreach loop with some arguments relevant to each user.

The answer is close to correct.

The issue is with declaring the field, the answer provided uses the_field and not get_field. Which should be used for storing variables.

$custom_acf_field = get_field('instagram_field');
echo do_shortcode("[instagram-feed id='$custom_acf_field']");

This should work out ok if not you may wish to declare the shortcode seperately:

$custom_acf_field = get_field('instagram_field');
$insta_code = [instagram-feed id='$custom_acf_field'];
echo do_shortcode($insta_code);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM