Rather than attempt this with ACF, I would do this with CSS. You can wrap the field in a div, like this:
<div class="my-wysiwyg">
<?php the_field('my_wysiwyg');?>
</div>
Then just apply the styling to the last <p> tag with CSS:
.my-wysiwyg p:last-child {
font-size: 30px;
}
Does that help?
GOT IT!!!!! Yay, finally, thanks so much for your help! I can’t thank you enough. If you can get me your email I will Quickly a beer or two 🙂
<div class="quick-link-sidebar">
<?php if( have_rows('pro_resource_links') ):
$h1 = true; // add a simple boolean set to true ?>
<?php // loop through the rows of data
while ( have_rows('pro_resource_links') ) : the_row(); ?>
<?php $quick_link_column = get_sub_field('quick_link'); ?>
<?php if ( $h1 && $quick_link_column == "yes" ) { ?>
<h1>Quicklinks</h1>
<ul class="resource-links">
<?php $h1 = false; //now $h1 goes before this "if" condition closing bracket and it's set to false to limit the conditional only to the first link ?>
<?php } ?>
<?php if ( $quick_link_column == "yes" ) { // Continue with all the links ?>
<li class="<?php echo the_sub_field('indy_content'); ?>">
<a href="<?php the_sub_field('pro_url') ;?><?php the_sub_field('pro_resource_download') ;?>"><?php the_sub_field('pro_resource_link_name'); ?></a>
</li>
<?php } else {
// something else
} ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</ul>
<?php endif; ?>
</div><!-- end Quicklinks Sidebar -->
Sometimes I run into issues with the detection of the post ID in the default loops. Might try manually passing in the ID and seeing if you get the expected values. Edited code:
<?php while ( have_posts() ) : the_post(); ?>
<h1><?php the_field('event_name', get_the_ID()); ?></h1>
<a href="<?php the_field('event_url', get_the_ID()); ?>">Test URL</a>
<p><?php the_content(); ?></p>
<?php endwhile; // end of the loop. ?>
Flexible content itself does not contain a unique ID. However, you can easily append one when outputting the flexible content. For example, if outputting your slider wrap it in a container such as:
<div id="slider-container-<?php echo $counter++; ?>" class="slider-wrapper">
Container content...
</div>
Define $counter
before your loop and set it to 1 or 0.
If you’re using jQuery you can also set the context for the selector so it does not apply it document-wide: http://api.jquery.com/jquery/#jQuery1
I found a work around, i suppose, but if you can tell me if this is the way i am supposed to use this field type, that would be helpful.
So to solve my problem, i wrapped every Relationship field query in a custom WP_QUERY loop. I pull the page/post id to load the current pages fields.
I’m thinking its better to use wp_query and not the wordpress loop. Doing it this way does seem to make it not ruin $post->ID for other sections of the page.
Here is a sample code from my page…i do the same thing in the header, page.php and sidebar.php – I’ve setup section on each page that will load a post that is assigned to it (I’m using to show banner ads in different spots of the page based on the settings the user makes. They can choose the banner ad per page).
<?php
$postid = get_the_ID();
$homepgqry = array(
'p' => $postid,
'post_type' => 'any',
'posts_per_page' => 1,
'status' => 'published'
);
$loop = new WP_Query( $homepgqry );
while ( $loop->have_posts() ) : $loop->the_post();
$posts = get_field('homepage_promo_bottom');
if( $posts ): ?>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php //setup_postdata($post); ?>
<?php
$attachment_id = get_field('promo_image');
$size = "promo-header";
$image_attributes = wp_get_attachment_image_src( $attachment_id, $size );
if( $image_attributes ) {
?>
<a href="<?php echo the_field('promo_url'); ?>" target="_blank"><img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>"></a>
<?php } endforeach; ?>
<?php // wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
<?php endwhile; wp_reset_query(); ?>
I agree with these comments re: ACF’s field group builder interface. But, though I’ve found no GUI alternative, I’ve started using ACF5’s new local JSON feature to build out my field groups and found it to be a great alternate option. Especially if you use a JSON editor to keep everything neat and orderly! Still, I’d love to see a better GUI as the ability to quickly build, duplicate, and iterate field groups is, I’d imagine, a huge priority for most developers!
I guess, the plugin Ultimate WP Query Search Filter can do the thing
Check this thread on Stackoverflow where I got that code, there’s a few other suggestions
To precise, I do have ” – ” displayed which means it’s not about the if statement. Also, the structure of the flexible content custom field is as follows:
field name: post_quote_field
layout name: post_quote_block
field_name: post_quote
field_name: post_quote_author
field_name: post_quote_source_link
You are a saint for sticking with this. I hope I can figure out a way to buy you a beer after this…I tried your code but made modifications to fit my revised custom fields. Now there is just one section of Resourse Links instead of URLs and Downloads. And I changed the checkbox to true/false. It seems cleaner now. Your code modification are working better. The only thing is when there are more that one entry, the subsequent entries do not display within the UL tag. I am attaching a screenshot which also shows the html result. One thing I did not take into account… when all links are Quicklinks, the random header remains in the main column.
Latest revision (ignore new section in main column):
<div class="quick-link-sidebar">
<?php if( have_rows('pro_resource_links') ): ?>
<?php
$h1 = true; // add a simple boolean set to true
// loop through the rows of data
while ( have_rows('pro_resource_links') ) : the_row(); ?>
<?php $quick_link_column = get_sub_field('quick_link'); ?>
<?php if ( $h1 && $quick_link_column == true ) { ?>
<h1>Quicklinks</h1>
<ul class="resource-links">
<?php $h1 = false; //now $h1 goes before this "if" condition closing bracket and it's set to false to limit the conditional only to the first link ?>
<?php } ?>
<?php if ( $quick_link_column == true ) { // Continue with all the links ?>
<li class="<?php echo the_sub_field('indy_content'); ?>">
<a href="<?php the_sub_field('pro_url') ;?><?php the_sub_field('pro_resource_download') ;?>"><?php the_sub_field('pro_resource_link_name'); ?></a>
</li>
<?php } else {
// something else
} ?>
</ul>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php if ($h1) { } else { ?>
</ul>
<?php } ?>
<?php endif; ?>
</div><!-- end Quicklinks Sidebar -->
For visual configuration purpose i would take a look at the tinymce advanced plugin. and about the font example you’ve asked for i would try something like that (untested)
function tweek_mce( $init ) {
$init['fontsize_formats'] = "8pt 10pt 12pt 14pt 18pt 24pt 36pt";
return $init;
}
add_filter('tiny_mce_before_init', 'tweek_mce');
place it inside the functions.php. no acf needed in that particular case. best regards ralf
Check code errors:
Remove $h1 = true after the second “while” for the download links. See if it works like this.
<div class="quick-link-sidebar">
<?php if( have_rows('pro_resource_url') || have_rows('pro_resource_download') ): ?>
<?php
$h1 = true; // add a simple boolean set to true
// loop through the rows of data
while ( have_rows('pro_resource_url') ) : the_row(); ?>
<?php $quick_link_column = get_sub_field('quick_link'); ?>
<?php if ( $h1 && $quick_link_column == "yes" ) { ?>
<h1>Quicklinks</h1>
<ul class="resource-links">
<?php $h1 = false; //now $h1 goes before this "if" condition closing bracket and it's set to false to limit the conditional only to the first link ?>
<?php } ?>
<?php if ( $quick_link_column == "yes" ) { // Continue with all the links ?>
<li class="<?php echo the_sub_field('indy_content'); ?>">
<a href="<?php the_sub_field('pro_url'); ;?>"><?php the_sub_field('pro_resource_url_name'); ?></a>
</li>
<?php } else {
// something else
} ?>
</ul>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php // loop through the rows of data
while ( have_rows('pro_resource_download') ) : the_row();?>
<?php if ( $h1 && $quick_link_column == "yes" ) { ?>
<h1>Quicklinks</h1>
<ul class="resource-links">
<?php $h1 = false; ?>
<?php } ?>
<?php if ( $quick_link_column == "yes" ) { // Continue with all the links ?>
<li class="<?php echo the_sub_field('indy_content'); ?>">
<a href="<?php the_sub_field('pro_download_link'); ;?>"><?php the_sub_field('pro_download_name'); ?></a>
</li>
<?php } else {
// something else
} ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php if ($h1) { } else { ?>
</ul>
<?php } ?>
<?php endif; ?>
</div><!-- end Quicklinks Sidebar -->
Thanks, and I can understand the desire to keep things “lean and mean”. I’m one of those people that regularly opens up the Task Manager in windows and kills tasks I don’t think need to be running… (I started programming on a TRS-80 with 4k of RAM).
What I have found is that on a modern web server the “number” of plugins running doesn’t matter anywhere near as much as the “quality” of those plugins. A well written plugin should not impact your site’s performance very much.
For my day job, I run a news site for a local radio station. I have close to a hundred plugins installed, plus one plugin I’ve written with several hundred thousand lines of code. But page load speeds are not impacted much because I am VERY particular about the plugins I install. In many cases I modify the plugins to fix performance issues. And the site is running on a dedicated server optimized for WordPress and the web.
Unlike one of my personal sites running on general $6/month hosting with hundreds of other sites and can barely handle a dozen plugins before page load speeds are impacted.
I would recommend not using a plugin to create custom post types.
You can register custom post types by adding a function to your themes functions.php file.
Here’s an example:
// REGISTER CUSTOM POST TYPES
// You can register more, just duplicate the register_post_type code inside of the function and change the values. You are set!
if ( ! function_exists( 'create_post_type' ) ) :
function create_post_type() {
// You'll want to replace the values below with your own.
register_post_type( 'genstarter', // change the name
array(
'labels' => array(
'name' => __( 'Gen Starter' ), // change the name
'singular_name' => __( 'genstarter' ), // change the name
),
'public' => true,
'supports' => array ( 'title', 'editor', 'custom-fields', 'page-attributes', 'thumbnail' ), // do you need all of these options?
'taxonomies' => array( 'category', 'post_tag' ), // do you need categories and tags?
'hierarchical' => true,
'menu_icon' => get_bloginfo( 'template_directory' ) . "/images/icon.png",
'rewrite' => array ( 'slug' => __( 'genstarters' ) ) // change the name
)
);
}
add_action( 'init', 'create_post_type' );
endif; // ####
you need to add some js and do some code changes that it fit.
depends on selected js that would normally be div or ul/li (or a combination of it)
Basicly it would be something like
wp_register_script ...
wp_enqueue_script ...
<div class="slider_container">
<ul>
<?php foreach( $slides as $slide): ?>
<li>
code to load img permalink text from slide
</li>
<?php endforeach; ?>
</ul>
</div>
maybe not what you like to hear, nevertheless i hope that this info help you to solve your problem
Hi Drivebass,
Still not there. I took some screen shots of the results. I also took a screen shot of my ACF setup in admin.
1. For starters nothing is showing up ad all from the Resource download section. Blank sidebar
2.The Resource URL entries seem to work at first but only the first entry 9see screenshot). The second entry appears to add the head above each li entry (see screenshot.
My strategy for the day is to modify the ACF checkbox field from checkboxes with yes/no options to a single true/false checkbox and continue to work with your code. Maybe the checkbox files with yes/no options is overcomplicated. (as well as unnecessary because it really is just a true/false)
Also, Im considering combining the files groups so the user can add either a url or a download within the same entry eliminating the need for 2 sections. I suppose the division of URLS vs. Downloads is unnecessary-or it can be reordered as needed. Then I don’t have to deal with the heading appearing twice- once above each section.
Thanks again for helping me with this and your quick responses. I hope to figure this out soon but please let me know if you have any other ideas!
you can try something like this:
/**
* Exclude current and static post/page from relationship field results
*/
// 1. Add the name=[NAME_OF_RELATIONSHIP_FIELD].
add_filter('acf/fields/relationship/query/name=my_relationship_field', 'exclude_id', 10, 3);
// 2. Add the $field and $post arguments.
function exclude_id ( $args, $field, $post ) {
//3. $post argument passed in from the query hook is the $post->ID.
$args['post__not_in'] = array( $post, 1994, 1999, 1979, 4201, 1989 );
//should exclude post you edit, and posts with id 1994, 1999, 1979, 4201, 1989
return $args;
}
Hi @eileen.schmidtke
I made a few changes to the code and some corrections. First the $h1 set to “false” goes before the closing bracket of the if statement so it will apply only in that condition. The first condition checks if the $h1 is “true” AND if there is any $quick_link_column that is set to “yes”. If that condition applies we display the <h1> and the opening of the ul and set the $h1 variable to false, so it applies only once. I removed the following link’s lis code to prevent the first link from showing twice.
Next we check if there is only any $quick_link_column that is set to “yes” and display the links.
Same goes for the pro_resource_download.
Please test with three possible case. If there are only pro_resource_url, if there are only pro_resource_download if there are both.
Please notice that closing should be inside the else condition brackets otherwise it will always through a closing and that’s invalid html markup. I correct it that too.
Hope this helps!
<div class="quick-link-sidebar">
<?php if( have_rows('pro_resource_url') || have_rows('pro_resource_download') ): ?>
<?php
$h1 = true; // add a simple boolean set to true
// loop through the rows of data
while ( have_rows('pro_resource_url') ) : the_row(); ?>
<?php $quick_link_column = get_sub_field('quick_link'); ?>
<?php if ( $h1 && $quick_link_column == "yes" ) { ?>
<h1>Quicklinks</h1>
<ul class="resource-links">
<?php $h1 = false; //now $h1 goes before this "if" condition closing bracket and it's set to false to limit the conditional only to the first link ?>
<?php } ?>
<?php if ( $quick_link_column == "yes" ) { // Continue with all the links ?>
<li class="<?php echo the_sub_field('indy_content'); ?>">
<a href="<?php the_sub_field('pro_url'); ;?>"><?php the_sub_field('pro_resource_url_name'); ?></a>
</li>
<?php } else {
// something else
} ?>
</ul>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php // loop through the rows of data
while ( have_rows('pro_resource_download') ) : the_row();
$h1 = true; // add a simple boolean set to true ?>
<?php if ( $h1 && $quick_link_column == "yes" ) { ?>
<h1>Quicklinks</h1>
<ul class="resource-links">
<?php $h1 = false; ?>
<?php } ?>
<?php if ( $quick_link_column == "yes" ) { // Continue with all the links ?>
<li class="<?php echo the_sub_field('indy_content'); ?>">
<a href="<?php the_sub_field('pro_download_link'); ;?>"><?php the_sub_field('pro_download_name'); ?></a>
</li>
<?php } else {
// something else
} ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php if ($h1) { } else { ?>
</ul>
<?php } ?>
<?php endif; ?>
</div><!-- end Quicklinks Sidebar -->
Sorry, here is the correct code as I have it right now, the top post had an error. I also for got to mention while the Quicklink heading does not appear with a Resource Download entry, also the Resource download entry appears twice when chick link is checked.
<div class="quick-link-sidebar">
<?php if( have_rows('pro_resource_url') || have_rows('pro_resource_download') ): ?>
<?php
$h1 = true; // add a simple boolean set to true
// loop through the rows of data
while ( have_rows('pro_resource_url') ) : the_row(); ?>
<?php $quick_link_column = get_sub_field('quick_link'); ?>
<?php if ( $h1 && $quick_link_column == "yes" ) { ?>
<h1>Quicklinks</h1>
<ul class="resource-links">
<li class="<?php echo the_sub_field('indy_content'); ?>">
<a href="<?php the_sub_field('pro_url'); ;?>"><?php the_sub_field('pro_resource_url_name'); ?></a>
</li>
<?php } ?>
<?php $h1 = false; //now set the $h1 to false so only it doesn't display multiple times ?>
<?php if ( $quick_link_column == "yes" ) { // Continue with the other links ?>
<li class="<?php echo the_sub_field('indy_content'); ?>">
<a href="<?php the_sub_field('pro_url'); ;?>"><?php the_sub_field('pro_resource_url_name'); ?></a>
</li>
<?php } else {
// something else
} ?>
</ul>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php // loop through the rows of data
while ( have_rows('pro_resource_download') ) : the_row();
$h1 = true; // add a simple boolean set to true ?>
<?php if ( $h1 && $quick_link_column == "yes" ) { ?>
<h1>Quicklinks</h1>
<ul class="resource-links">
<li class="<?php echo the_sub_field('indy_content'); ?>">
<a href="<?php the_sub_field('pro_download_link'); ;?>"><?php the_sub_field('pro_download_name'); ?></a>
</li>
<?php } ?>
<?php $h1 = false; ?>
<?php if ( $quick_link_column == "yes" ) { // Continue with the other links ?>
<li class="<?php echo the_sub_field('indy_content'); ?>">
<a href="<?php the_sub_field('pro_download_link'); ;?>"><?php the_sub_field('pro_download_name'); ?></a>
</li>
<?php } else {
// something else
} ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php if ($h1) {//do nothing
} else {
} ?>
</ul>
<?php endif; ?>
</div><!-- end Quicklinks Sidebar -->
Hi Drivebass,
I was able to fix the syntax problem by relocating the offending curly bracket. My “fix” however may be messing up your solution. It doesn’t seem to work when only a resource download entry exists. Still futzing with it… Below is what i have so far
<div class="quick-link-sidebar">
<?php if( have_rows('pro_resource_url') || have_rows('pro_resource_download') ): ?>
<?php
$h1 = true; // add a simple boolean set to true
// loop through the rows of data
while ( have_rows('pro_resource_url') ) : the_row(); ?>
<?php $quick_link_column = get_sub_field('quick_link'); ?>
<?php if ( $h1 && $quick_link_column == "yes" ) { ?>
<h1>Quicklinks</h1>
<ul class="resource-links">
<li class="<?php echo the_sub_field('indy_content'); ?>">
<a href="<?php the_sub_field('pro_url'); ;?>"><?php the_sub_field('pro_resource_url_name'); ?></a>
</li>
<?php } ?>
<?php $h1 = false; //now set the $h1 to false so only it doesn't display multiple times ?>
<?php if ( $quick_link_column == "yes" ) { // Continue with the other links ?>
<li class="<?php echo the_sub_field('indy_content'); ?>">
<a href="<?php the_sub_field('pro_url'); ;?>"><?php the_sub_field('pro_resource_url_name'); ?></a>
</li>
<?php } else {
// something else
} ?>
</ul>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php // loop through the rows of data
while ( have_rows('pro_resource_download') ) : the_row(); ?>
<?php if ( $h1 && $quick_link_column == "yes" ) { ?>
<h1>Quicklinks</h1>
<ul class="resource-links">
<li class="<?php echo the_sub_field('indy_content'); ?>">
<a href="<?php the_sub_field('pro_download_link'); ;?>"><?php the_sub_field('pro_download_name'); ?></a>
</li>
<?php } ?>
<?php $h1 = false; ?>
<?php if ( $quick_link_column == "yes" ) { // Continue with the other links ?>
<li class="<?php echo the_sub_field('indy_content'); ?>">
<a href="<?php the_sub_field('pro_download_link'); ;?>"><?php the_sub_field('pro_download_name'); ?></a>
</li>
<?php } else {
// something else
} ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</ul>
<?php endif; ?>
</div><!-- end Quicklinks Sidebar -->
Also looking for this solution.I am able to save my lat/long values into separate custom fields.
I will play around with your function example and see if I can get that working.
This might also be of value: http://wpquestions.com/question/show/id/7926
On a new site I just installed the latest 4.3.5 and 1.1.1 on WP 4.1 and I had the same problem as mentioned in my post above, with the rows shifting. I added the function created by @captaincoo1 and everything cleared up. I’m not having issues with saving fields.
Be sure all your repeater elements have unique field names…maybe thats the problem?
Then check it by disabling all your plugins, if the fields work add the plugins back 1 by 1. If all else fails restart your computer 😉
edit: sorry if I misunderstood…you are having trouble saving in VC fields, or repeater fields?
if you add this before the li tag:
<?php
echo '<pre>';
echo htmlspecialchars(print_r($image,true));
echo '</pre>';
?>
you will see the sizes that are defined. i assume full is not one of them. 😉
you can add additional sizes with plugin or inside function.php
add_image_size( 'myfullsize', '4000', '3000', false );
but i assume you just need to change a line of your code.
change it to this:
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
i think you miss the closing > of the opening div tag
<div class="<?php the_sub_field('column_width');?>">
I’ve been working on this further, still not working, but wanted to put my updates here in case anyone sees anything obvious. What happens with this is that it displays the associated post, but each instance of it appears on the page. So if I select the same post for two products, on both of those product pages it appears twice. I feel like I’m close, but can’t figure it out.
Thanks for your help.
<ul class="medium-block-grid-5 blog-posts">
<?php
$args = array( 'posts_per_page' => -1 );
$fposts = get_posts( $args );
foreach ( $fposts as $post ) : ?>
<?php setup_postdata($post); ?>
<?php $product = get_field('related_products'); if( $product ): ?>
<?php foreach( $product as $p ): ?>
<li class="post">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" ><span class="featured-title"><h3><?php the_title(); ?></h3></span></a>
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail('regular-posts'); ?>
<?php else : ?>
<img src="<?php echo get_template_directory_uri(); ?>/img/no-image.png" alt="" />
<?php endif; ?>
</li>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; wp_reset_postdata();?>
</ul>
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.