Support

Account

Forum Replies Created

  • So how is the pre-job page connected to the relevant quotes page?

  • I’m assuming that each quotes post will have a number of pre-jobs posts selected under the linked_pre_job relationship field.

    So in order to make the connection from the quotes post, you’ll need to search through those fields in each of the pre-jobs posts to make a match with your current quotes post. You’re essentially reversing how things typically work, you’d probably call this a reverse relationship query.

    If I’ve interpreted the question correctly, it looks like someone has done exactly this on this question:

    https://support.advancedcustomfields.com/forums/topic/reverse-relationship-query/

    Good luck, I hope I’ve helped.

  • Okay, so I’ve sussed it, it took a while. The two main problems I encountered were:

    1. the if/else statement for the logo, I got round it by using the input of the selection not the choice.
    2. I was using bloginfo as opposed to get_bloginfo which returns a variable.

    Here’s the final code which works a treat.

    <?php 
    $template_directory = get_bloginfo('template_directory');
    $rows = get_field('slider_image');
    shuffle ($rows);
    if($rows)
    {
    
    	foreach($rows as $row)
    	{
    		echo $row['the_caption'] . '<img src="' . $template_directory . '/logo_' . $row['logo_colour'] . '.png" />'. PHP_EOL;
    	}
     
    }
    ?>

    Thank you so much Nuro for all your help, I wouldn’t of got there without your assistance.

    I’m off to the pub now!

  • Okay so this almost worked… it outputted the following

    http://domain.com/template-directory
    <ul>
    <li>Caption 1</li>
    <li>[img src="logo_Grey.png" ]</li>
    <li>Caption 2</li>
    <li>[img src="logo_Grey.png" ]</li>
    <li>Caption 3</li>
    <li>[img src="logo_White.png" ]</li>
    </ul>

    No random order unfortunately, no real progression from my original (revised) code.

    <?php if(get_field('slider_image')): ?>
      <?php while(has_sub_field('slider_image')): ?>
        <?php the_sub_field('the_caption'); ?>
        <img src="<?php bloginfo('template_directory'); ?>/logo_<?php the_sub_field('logo_colour'); ?>.png" />
      <?php endwhile; ?>
    <?php endif; ?>

    Once again thank you for persevering!

  • Hi Nuro,

    The code didn’t work unfortunately, but I think you’ve already started thinking of alternatives…

    Yes the caption is just a text field. The entry is usually a single word.

    Colour type is indeed a select drop-down containing two entries at the moment… grey or white.

    I was just thinking myself if we could eliminate the “if” statement, by just using the field…

    I’ve just changed the original code to:

    <img src="<?php bloginfo('template_directory'); ?>/logo_<?php the_sub_field('logo_colour'); ?>.png">

    And all seems to work.

    I hope this makes it easier.

  • Well I’m assuming it’s not loading at all, when it was trying to deliver an infinite output of rows I was able to stop the loading and view source to see what it had done. Now the source is empty.

    It’s a tough one! Thanks for your patience and commitment!

  • Still no joy unfortunately… it’s just not loading when in place.

  • Okay we’re getting closer… I think the problem seems to be it’s not stopping the output… it’s pumping out an infinite number of entries. If there’s only three entries I only want three entries, I just want those three entries in random order.

    It’s close… any other ideas?

    I’m thinking

    endwhile

  • I think I’ve sorted it… there was one too many ) and we were one } short.

    <?php
     
    $rows = get_field('slider_image' );
    $sub_field = has_sub_field('slider_image');
    $rand_row = $rows[ array_rand( $rows ) ];
    $logo_colour = get_sub_field('logo_colour');
    $caption = get_sub_field('the_caption');
    $template_directory = bloginfo('template_directory');
    
    if($rows) // if slider_image exits
    	{
          echo '<ul class="invisible">';
    
    		while($sub_field) // enables us to use get_sub_field
    		    {
    		    	
    		    	$rows = $rand_row; // random order of rows
    
    				foreach ($rows as $row) {
    
    					echo '<li>' . $caption . '</li>'; // displays caption
    
    					if (($logo_colour) == "White") { // displays white logo if selected, else grey
    
    					echo '<li><img src="' . $template_directory . '/logo_white.png" /></li>';
    
    					} else {
    						
    					echo '<li><img src="' . $template_directory . '/logo_grey.png" /></li>';
                        }
    
    				    }
    
    				} 
    	      	        
    	   echo '</ul>';
    	}
                 
    ?>

    It’s difficult to test as the site is live but I’m going to have a go now!

    Thanks again!

  • That is brilliant, however it’s not working, my code editors flagging up syntax issues, any ideas? Thanks for all your help it’s much appreciated.

  • Sorry Nuro, this is probably me being awful at explaining things.

    Say at the moment the code is pumping out:

    • Caption One <grey logo>
    • Caption Two <white logo>
    • Caption Three <grey logo>

    Three separate entries. Logo colour defined and fixed to the caption.

    I want it to pump out something like:

    • Caption Two <white logo>
    • Caption Three <grey logo>
    • Caption One <grey logo>

    OR

    • Caption Three <grey logo>
    • Caption One <grey logo>
    • Caption Two <white logo>

    OR any random order really. Notice the caption and the logo colour remain the same so it’s just jumbling up the order of the entries not the contents within each entry.

    So in essence something like:

    
    <?php if(get_field('slider_image')): ?>
      <RANDOM ORDER>
      <?php while(has_sub_field('slider_image')): ?>
        <?php the_sub_field('the_caption'); ?>
        <img src="<?php bloginfo('template_directory'); ?>/logo_<?php if(get_sub_field('logo_colour') == "White") { echo 'white'; } else { echo 'grey'; }?>.png" />
      <?php endwhile; ?>
    <?php endif; ?>
    

    Flippin’ eck I’m terrible at this stuff.

  • Hi Nuro, thanks for taking a look.

    In answer to:

    Do you want the “else” color to be random?

    No I only want the order of the rows to be random.

Viewing 12 posts - 26 through 37 (of 37 total)