I was able to partially answer my own question. This is slick btw. Well done!
My other question is if we are parsing through blocks for a specific block to display elsewhere on a page how do we prevent the block from ALSO appearing within the content?
Hey Matthew!
Thanks for this. This looks like a possible answer to something I’m trying to do. Your function looks like it loops through blocks and if a given block exists then you can display content from it. I have an acf block ‘hero-block’ that I want to place outside of and before the content area. How would I place a specific block where I want it to go using this method?
When I enter that code into functions.php (btw, awesome clean way to do that. Always just did a var_dump, so thanks!)
WP_Post Object
(
[ID] => 169
[post_author] => 1
[post_date] => 2013-09-30 04:12:52
[post_date_gmt] => 2013-09-30 04:12:52
[post_content] =>
[post_title] => Our Shop
[post_excerpt] =>
[post_status] => publish
[comment_status] => open
[ping_status] => open
[post_password] =>
[post_name] => our-shop
[to_ping] =>
[pinged] =>
[post_modified] => 2013-10-01 06:29:28
[post_modified_gmt] => 2013-10-01 06:29:28
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://www.pspfit.dev/?page_id=169
[menu_order] => 0
[post_type] => page
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
[format_content] =>
)
Hey Elliot,
Thanks for the prompt reply. This is just a function I’m running that pulls a field from the image/attachment meta. So it would be the page.php template, I suppose. This is a genesis child theme, too, if that helps.
In the function I didn’t declare the global $post variable originally, but I did just now and it didn’t seem to change anything. I tried getting the field using the_field() method and also as a variable and neither seemed to work.
Here’s teh function in full, don’t mind the ugly code. =)
add_action( 'genesis_before_loop', 'ds_add_featured_image', 1 );
function ds_add_featured_image() {
global $post;
$variable = get_field('featured_image_link');
?>
<div class="featured-image">
<a href="<?php get_field( $variable ); ?>" title=""><?php the_post_thumbnail(); ?></a>
<span class="caption"><?php get_post( get_post_thumbnail_id() )->post_excerpt;?> </span>
</div>
<?php }
Sorry about that; I think even I was confused on what I wanted to do…
The code below gave me what I wanted; I’m always open to tips on optimizing it further.
<?php if(get_field('choose_layout') == "1col")
{ ?>
<p><?php the_field('single_column'); ?></p>
<?php } elseif (get_field('choose_layout') == "2col")
{ ?>
<p><?php the_field('two_columns_left'); ?></p>
<p><?php the_field('two_columns_right'); ?></p>
<?php } elseif (get_field('choose_layout') == "3col")
{ ?>
<p><?php the_field('three_columns_left'); ?></p>
<p><?php the_field('three_columns_middle'); ?></p>
<p><?php the_field('three_columns_right'); ?></p>
<?php } ?>
I’d like to tack a +1 to Foyle’s suggestion for adding images or additional context to certain types of fields.
I’m looking to implement a means for clients to create multiple columns within their content and I want to do that with ACF and I can. But Id like to make it a really intuitive experience where they can get an idea what each layout choice looks like, similar to how StudioPress does it: http://cl.ly/image/1Z2t0f0N1f1k
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.