Support

Account

Home Forums Front-end Issues Page link – get page title, copy and image

Solving

Page link – get page title, copy and image

  • I am using ‘Page Link’ in an repeater on the homepage and have 4 sections that each go to an alternate page.

    What I want is that pages title, description and featured image to appear on the homepage as well just by knowing what ‘Page Link’ was selected.

    Is this possible?

    <?php if( have_rows('page_selector') ):
    $i=1;
    $count = (count($my_fields['value']));
    ?>          
    <?php while( have_rows('page_selector') ): the_row(); 
        // vars
        $page = get_sub_field('page');
    ?>  
    	<div class="lg-col-6 md-col-6">
    		<div class="sub_service">
    			
    			<a href="<?php echo $page; ?>"><?php the_title(); ?></a>
    		</div>
    	</div>			        		
    <?php
        $i++;
        endwhile; ?>
    <?php endif; ?> 
    <?php wp_reset_query(); ?>
  • I have been able to get the page title but can’t get the custom field inside of it….

    <?php if( have_rows('page_selector') ):
    $i=1;
    $count = (count($my_fields['value']));
    ?>          
    <?php while( have_rows('page_selector') ): the_row(); 
        // vars
        $page = get_sub_field('page');
    ?>  
    	<div class="lg-col-6 md-col-6">
    		<div class="sub_service">
    
    			<?php 
    			// vars
    			$post_id = get_sub_field('page', false, false);
    
    			// check 
    			if( $post_id ): ?>
    			<a href="<?php echo get_the_permalink($post_id); ?>"><h2><?php echo get_the_title($post_id); ?></h2></a>
    
    			<?php endif; ?>
    
    			
    			<p>Content</p>
    			
    		</div>
    	</div>			        		
    <?php
        $i++;
        endwhile; ?>
    <?php endif; ?> 
    <?php wp_reset_query(); ?>
  • I realise this is old but I just wanted to use an image while using the Page Link field as well. I used the following to grab the post thumbnail whilst using the Advanced example from here.

    <?php if (has_post_thumbnail( $post_id )) echo get_the_post_thumbnail($post_id, 'large'); ?>

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

The topic ‘Page link – get page title, copy and image’ is closed to new replies.