Support

Account

Forum Replies Created

  • Thanks for that! My code worked, but clearly yours is the cleaner and more appropriate version so I went ahead and updated mine!

  • This code below seems to work:

    <?php 
         $file = get_field('product_brochure_pdf');
         if( $file ): 
                // vars
                $url = $file['url'];
                $title = $file['title'];
                                        
         endif; ?>
    
    <?php if(get_field('product_brochure') == 'yes') : ?>
          <a href="<?php echo $url; ?>" title="<?php echo $title; ?>" target="_blank"><?php echo $title; ?></a>
    <?php else : ?>
                                    
    <?php endif; ?>

    Can any of you guys who are more versed in PHP check that out and see if there are any glaring issues? Like I said, it does work, just want to make sure it’s coded correctly.

    What it should be doing is if someone chooses ‘Yes’ from the radio button choice (meaning yes, there is a product brochure) it will then show the conditional ‘File’ field called Product Brochure PDF (to allow someone to upload a PDF). The code will output the link to the PDF along with the title of the PDF.

    If someone selects ‘NO’ on the radio button choice, it simply won’t display anything on the front end.

  • Also, the page in question is here: http://test.pr-tech.com/product/spanguard-abs-standard-power-line-marker/

    You can see in the intro section where it says ‘SpanGuard Brochure (PDF)’ which is where I using this PHP code above. It is indeed outputting the correct title of the attachment, but it’s linking to the attachment page instead of the PDF itself.

    Thoughts?

  • I’m not using PRO yet, but I am using the most current version of ACF and it doesn’t work at all.

    I’m following the ‘select’ documentation to a T but the code simply doesn’t work. So either this is a bug or the code is somehow wrong.

  • Yes, the code doesn’t work for me at all. When I view the source code my above code simply outputs:

    <p class"">Intro Text</p>

    It should be outputting:

    <p class"light_green">Intro Text</p>

    That way I can apply CSS styling to the ‘light_green’ class. Make sense?

  • Thanks again John! I’ll probably go ahead and purchase the PRO version since that has a lot of other features I would like as well!

  • Thanks John, I modified it a bit so this is what it looks like now (works perfectly!):

    <?php if( have_rows('resources_column') ): ?>
                
                    <?php while( have_rows('resources_column') ): the_row(); 
                        // variables
                        $title = get_sub_field('resource_title');
    					$internal_link = get_sub_field('resource_internal_link');
    					$external_link = get_sub_field('resource_external_link');
                        $description = get_sub_field('resource_description');
    					$resource_link_type = get_sub_field('resource_link_type');
    					if ($resource_link_type == 'internal') {
    						$link = get_sub_field('resource_internal_link');
    					} else {
    						$target = ' target="_blank" rel="nofollow"';
    						$link = get_sub_field('resource_external_link');
    					}
    				?>
                    
    				<p class="resource-title"><a href="<?php echo $link; ?>"<?php echo $target; ?>><?php echo $title; ?></a></p>
                    <p class="resource-description"><?php echo $description; ?></p>
    
                    <?php endwhile; ?>
                
                <?php endif; ?>
  • Thanks John, works like a charm! Any way I might be able to add a conditional statement on to that code that makes it so external links use a target=”_blank” in the output so that they open in a new window?

  • Sorry, I forgot to update this. I resolved the issue!

    I probably should have used repeater fields though, you’re right!

  • FYI, here is what my setup looks like on the backend…

    Backend

Viewing 10 posts - 1 through 10 (of 10 total)