Support

Account

Home Forums General Issues How to link to single page?

Solved

How to link to single page?

  • Right now i have this code that i use to display some of the data from my custom posts with the AFC fields on a posts page. I now want to add a link to a single post for each of the results and display all of the fields on the singles page. But i can’t figure out how to add the link.

    <div class="col-12">
              <?php
              $args = array('post_type' => 'portrait', 'posts_per_page' => 999);
              $loop = new WP_Query($args);
              while ($loop->have_posts()) : $loop->the_post();
                the_title();
                echo '<div class="entry-content">';
                ?>
    
                <h2><?php the_field('title'); ?></h2>
                <h2><?php the_field('year'); ?></h2>
                <h2><?php the_field('dimension'); ?></h2>
    
                <?php
    
                $image = get_field('portrait');
    
                // thumbnail
    
                $size = 'medium';
                $thumb = $image['sizes'][$size];
    
                if (!empty($image)) : ?>
    
                  <img src="<?php echo $thumb; ?>" alt="<?php echo $image['alt']; ?>" class="imgContain" />
    
                <?php endif; ?>
    
                <?php
                echo '</div>';
              endwhile;
    
              ?>
    
              
            </div>
  • Uhm, not sure if I’m misunderstanding you but URLs of single posts are simply output with the_permalink() https://codex.wordpress.org/Function_Reference/the_permalink

    So, in order to put a link to your single post you’d have:
    <a href="<?php the_permalink(); ?>">read more</a>
    (of course instead of static “read more” text you could as well put the post title there or whatever)

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

The topic ‘How to link to single page?’ is closed to new replies.