Using advanced custom fields with fishpig extension just shows URL or “Array” or “ID” of the picture in fronted.
How can the picture be shown.
When creating a field of Image type, you can choose the return type. If you are using the latest version of the FishPig Advanced Custom Fields add-on extension (1.4.0.1), you have 3 options for the return type:
Object
URL
Array
If you choose object, the image model will be returned. Once you have the image model you can get any of the different URLs for the image (each URL is for a different sized image). For a list of methods you can call to get different images, see this article.
If you choose URL, the URL to the originally uploaded image will be returned.
If you choose array, an array will be returned that contains the image ID, URL and object. (eg. $image['id'], $image['object'] and $image['url']). To convert the image ID to an object, use the following code:
<?php $image = Mage::getModel('wordpress/image')->load($image['id']) ?>
<?php if ($image->getId()): ?>
<img src="<?php echo $image->getAvailableImage() ?>" alt="" />
<?php endif; ?>
If you aren't already, I would recommend upgrading Magento WordPress Integration and Advanced Custom Fields to the latest versions.
when echoing out the URL, run this inside an img src.
i.e.
<img src="<?php echo the_field('image-url') ?>" />
Related
so after a lot of researching and trials and errors, I come to you. This seems to be very basic and still no luck. The issue is that my image does not appear and in the console it gives me an <img src (unknown) />.
So, in my ACF, I have a field called first_row that contains sub fields, one of the is called left_side_bg. It's attributes are all standard, and is set to return an Image Array. As a side note, I have another subfield called left_side_text.
On my php file, I'm trying to retrieve it like this:
<?php
$info = get_field('first_row');
$left_side_bg = get_sub_field('left_side_bg');
?>
<div class="single-banner">
<img src="<?php echo $left_side_bg['url']?>" alt="">
<div class="inner-text">
<h4><?php echo $info['left_side_text']; ?></h4>
</div>
</div>
The left_side_text shows fine, but no luck with the image... is there anywhere I can double check or debug this better, or am I fetching the data incorrectly?
As a side note, I have tried different ways to retrieve the image by changing to Image URL, Image ID (in the ACF custom editor) and so on, but no luck, so I returned to the original format I tried to get the image the first time with all the ACF fields as default (getting the Image as an Array).
get_sub_field() is meant for Repeaters and Flexible Content (rows). I assume left_side_bg and left_side_text are in the same group. Therefore, try it like so:
<?php
$info = get_field('first_row');
?>
<div class="single-banner">
<img src="<?php echo $info['left_side_bg']['url']?>" alt="">
<div class="inner-text">
It also makes a difference to what your Return Value is configured. I hope it is set to "Image Array". Otherwise, you might have to omit the ['url'] if it's "Image URL" instead.
If that isn't working, it might be a good idea to post a screenshot of what your ACF field configuration (field group) looks like.
Is there a way to add a custom field to change the image displayed in my web site's header?
I want the same imageto be displayed in every page, so I dont know how to make a general custom field instead of a field specific for each page.
<?php
$img = the_field('background_url');
?>
Add Options page for ACF with the help of below code:
if( function_exists('acf_add_options_page') ) {
acf_add_options_page();
}
and then assign options to acf field.
now you can access this common field with <?php the_field('logo', 'option'); ?>
If you are using ACF Pro then you can create an option page and create Header, Footer fields into that. check the below link.
https://www.advancedcustomfields.com/resources/options-page/
I'm assuming that the header image is loaded from the header.php file in your theme?
If you want the same background image on all pages you could set the default header image via the set_theme_mod function. The set_theme_mod is responsible for all modification values for the current theme. In this case you would want to set the header_image property.
Start with setting the default header_image for your theme in your themes functions.php file:
function theme_setup() {
set_theme_mod(‘header_image’, ‘http://yoursite.com/wp-content/uploads/yourimage.png’);
}
add_action('after_setup_theme', 'theme_setup');
Display the newly set header image in your theme file responsible for displaying your header (assumingly header.php):
<?php if ( get_header_image() ) : ?>
<div id="site-header">
<img alt="" src="<?php header_image(); ?>
</div>
<?php endif; ?>
If you want to be able to upload custom images from within the Customizer (Appearance > Header) in the wp admin section you could use the custom_header property, you'll find more information about it here:
Theme Handbook: Custom Headers
I found a way after reading ACF documentation, in order to make the custom field's scope global, I have to add the post/page ID on it:
$video_file = get_field('background_video',156);
Please install ACF plugin and you would easily get the image. While creating an image field there would be an option which name is Return Format, please select any of them and you would get results accordingly.
Image Array
Image URL
Image ID
For further please follow ACF official documentation.
AdvancedCustomField
I'm trying to create a slider on the homepage of my Magento site. I am totally new to Magento and have someone else on our team coding most of that stuff after realizing how far into the deep end I jumped.
My issue: I'm trying to pull custom posts from WP (with the paid advanced custom fields extension) to display an image that will go into a slider.
I'm stuck at the most basic part - pulling in a list of Wordpress posts.
I created a new file: mytemplatedirectory/default/template/home/slider.phtml with
<?php $posts = $this->getPosts() ?>
<?php foreach ($posts as $_post) : ?>
<?php echo $post->getPostContent() ?>
<?php endforeach ?>
and I put this into the CMS page in the Magento admin:
{{block type="core/template" template="home/slider.phtml"}}
But not even the default post is showing up.
If anyone has any guidance that would be extremely helpful. The beginning steps are what are throwing me off but it would also be nice to have help pulling the custom post and the advanced custom field (although it seems that Fishpig's documentation makes this pretty simple).
Thanks in advance! Sorry for such an amateur question.
The block type you're using does not include the getPosts() method, which is the reason your call to this returns nothing. If you change the block type to 'wordpress/sidebar_widget_posts' then the call to getPosts will return a post collection object.
The following link explains a little bit more about how to include this block and what you can do with it:
Display WordPress Blog Posts on the Magento homepage
Figured this out with Ben's help (who I believe is the creator of the excellent Fishpig extension).
I created a custom post (with the Custom Post Type UI plugin for WP) and a custom field (with the Advanced Custom Fields plugin for WP).
On my Homepage in the CMS I added in the content area
{{block type="wordpress/sidebar_widget_posts" name="wordpress.widget.recent_posts" post_count="5" post_type="slider_home" template="wordpress/sidebar/widget/slider_home.phtml"}}
In that block, slider_home is my post type and slider_home.phtml is a new file I created that pulls the code from wordpress/sidebar/widget/posts.phtml but customizes it to my need.
Within the loop in slider_home.phtml I took out what was currently there and added:
<?php $image = $post->getMetaValue('image'); ?>
<?php $url = $post->getMetaValue('url'); ?>
<a href="<?php echo $url; ?>" target="_blank">
<img src="<?php echo $image; ?>" />
</a>
which is pulling in the custom fields I made in Wordpress. works perfectly and now my client will be able to update their Magento site through the Wordpress CMS.
I am having trouble getting imagecache to generate a thumbnail based on a preset I have created named 'thumbnail'. I have an cck image_field and a custom node view. The code I am using to output my images is:
<?php foreach($node->field_comm_gallery as $galleryItem) { ?>
<?php print theme('imagecache', 'thumbnail', $galleryItem['filepath'], $alt = '', ''); ?>
<?php } ?>
The output I get from the following is:
<img class="imagecache imagecache-thumbnail" title="" alt="" src="http://127.0.0.1/sites/default/files/imagecache/thumbnail/cedimages/3388564188_4427beac12_b_0.jpg"/>
<img class="imagecache imagecache-thumbnail" title="" alt="" src="http://127.0.0.1/sites/default/files/imagecache/thumbnail/cedimages/3388564188_4427beac12_b_2.jpg"/>
Everything looks correct but those files do not exist in that folder.
My question: Is the print theme(..) call supposed to generate the thumbnail on the fly when it is called, or is the thumbnail generated when a node is created/updated?
I am using the GD Image processer and receive no errors.
The node field value has within it the display value already generated. So using theme function is not needed. But the file should be created regardless. It looks like the problem is the permission to either Drupals temp folder or the files folder. Take a look at those in the files settings.
Thanks for the help. It actually turned out to be this bug (http://drupal.org/node/540486#comment-2356560)
I had to remove the & from the function parameters in imageapi.module
function imageapi_gd_image_resize(&$image, $width, $height)
No clue why, but it seems to break when using php 5.x
What's the best way to associate an image with a post in WordPress?
What I mean by that is when each post has a 'header' image which is not in the body of the post. You'd most likely use it to show a small image next to each post when they're listed somewhere.
I know you can use custom fields with posts, but are there any better ways of doing it?
Thanks in advance.
If you go the custom field route - in your template code you can save the value of the custom field to a variable and then echo it out to your image.
<?php $post_image = get_post_meta($post->ID, post_image, true); ?>
<?php if( $post_image != "" && isset($post_image) ) : ?>
<p><img src="<?php echo $post_image; ?>" alt="<?php echo $post_image; ?>" /></p>
<?php endif; ?>
<?php the_content('read more...'); ?>
The function the_content() may or may not be what you will end up using - for more control, you can try setting a new WP_Query() and then revamping the loop.
Not really any better way than custom fields, although you could always write out a unique class name containing the post ID on the container div and add the images via CSS each time you add a post. You'd end with a potentially huge CSS file though so I'd go for custom fields myself.
If you want a different image per post then use Customs Fields as suggested before - the only problem with that will be that Custom Fields are text fields and so you will have to upload your image and then paste the filename into your Custom Field. You could use the normal Add Image facility in the main post entry form but that will break up your workflow a bit as you will have to: upload the image in main post form, copy image url from HTML of form, remove image from form, paste URL into a custom field.
A bit of a pain!
If you want to use an image per category. Say, for example, you have a thumbnail for news items and a thumbnail for tutorials and so on. You could edit your WP theme template, check the category inside The Loop and show the relevant image from there.
The first option is a bit of a pain and the second requires some PHP coding.
A good way of associating an image with a post is to call the first image attached to that post in your template file.
I've elaborated a bit in this thread:
How would you recommend adding an image as a custom field in WordPress?