跳转到主要内容

Page Link

Description

Screenshots

A Page Link field that allows you to choose an existing post, page,CPT or archive URL from a list

List of field settings shown when setting up a Page Link field

Changelog

  • Added Allow Archives in version 5.4.0.
  • Added Select2 UI in version 5.0.0.

Settings

  • Filter by Post Type
    Filters the selectable results via one or more post type. When left empty, all post types will be shown. As results are grouped by their post type, the selected post types here may be positioned into a specific order.
  • Filter by Taxonomy
    Filters the selectable results via one or more taxonomy term.
  • Allow Null
    Allows the current selection to be cleared and an empty value to be saved.
  • Allow Archives URLs
    Includes post type archive URLs within the select list of options.
  • Multiple
    Allows you to select more than one choice. When enabled, you may also drag/drop to reorder the selected choices.

Template usage

Display single value

This example demonstrates how to display a selected page link value.

<a href="<?php the_field('page_link'); ?>">Continue reading</a>

Display multiple values

This example demonstrates how to load and display multiple selected page link values.

<?php 
$urls = get_field('urls');
if( $urls ): ?>
    <h3>Further reading</h3>
    <ul>
        <?php foreach( $urls as $url ): ?>
        <li>
            <a href="<?php echo esc_url( $url ); ?>"><?php echo esc_html( $url ); ?></a>
        </li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>