WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Custom Fields
Page/Post link displaying its TITLE (2 posts)

  1. salatfresser
    Member
    Posted 1 year ago #

    Hello, i'd like to use a "links" box next to my posts, but having the links displaying the name/title of the post, and linking to it obviously. For now i could only use to display the URL to the post, but not having the actual post TITLE displayed.

    Anyone know how to do this? What i'm using right now is

    <?php echo get_field( 'links', $post_object->ID ); ?>

    Thanks for your help!
    Mike

    http://wordpress.org/extend/plugins/advanced-custom-fields/

  2. fancyfiber
    Member
    Posted 1 year ago #

    There really isn't enough information in your original post to give a proper answer to your question, but I'll give a "best guess" about what you are attempting to do:

    I think, you would like to have posts (or pages) that are related to the post/page that is presently being displayed, displayed in a box, say in a sidebar.

    Assuming these are posts/pages are on your site, why would you not use a Relationship field for this? Then you would basically use the code from the ACF website to build your links to the posts.

    /*
    *  Loop through post objects ( don't setup postdata )
    *  Using this method, the $post object is never changed so all functions need a second parameter of the post ID in question.
    */
    
    $posts = get_field('relationship');
    
    if( $posts ): ?>
    	<ul>
    	<?php foreach( $posts as $post_object): ?>
    	    <li>
    	    	<a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_title($post_object->ID); ?></a>
    	    </li>
    	<?php endforeach; ?>
    	</ul>
    <?php endif;

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.