dev90
dev90

Reputation: 7591

How to add <a href> to link other post in Wordpress

I am new to wordpress, I have searched this thing on net but unable to find exact solution.

I have created a post that contains the Actor's Profile and the list of Movies Actor has worked in. Each Movie has also a different Wordpress Post that contains Movie details.

Now i want to create a link on each Movie, by which user can view the details of that particular movie.

This following link gives the result

<a href="http://localhost/wordpress/2015/10/09/movie-main-page">

but if i add this in each post, then it would be very difficult for me in future, when i will be uploading the site on web server, to change each link individually on every post.

I believe that there must be some way out there better than what i doing here, but somehow i am unable to find that trick.

Kindly guide me.

Thanks

Upvotes: 0

Views: 7345

Answers (3)

Prateek Goyal
Prateek Goyal

Reputation: 64

wordpress link to anchor on another page

If Your Movie Page URL is Same Then You can use

echo get_permalink('11');

Here 11 is id of the page/post.

or if you have different different post for movies that can have different urls.

You can use wp_query loop for each post [https://codex.wordpress.org/Class_Reference/WP_Query][1]

and use simply **echo get_permalink();** 

Upvotes: 1

Spencer Goodrich
Spencer Goodrich

Reputation: 101

There are two ways to achieve what you're doing.

  1. The first and easiest way would be to run a search and replace on the database to change any URL's in your posts to the new URL. You should have a look at https://interconnectit.com/products/search-and-replace-for-wordpress-databases/ .

  2. You could also use Advanced Custom Fields to Achieve this. You would need to use the post object field to link to another page within wordpress. With the post object field you can create a field for each post that links to another post which you can then display in your template. Take a look here https://www.advancedcustomfields.com/resources/post-object/. With this method you could transfer all the content and associated links would still work.

Upvotes: 0

Luke Bailey
Luke Bailey

Reputation: 168

You can use the get_site_url() template tag to return the site url and concatenate into the string. I haven't tested this code, so it might need some tinkering, but it should get you started:

    <?php echo '<a href="' . get_site_url() . '/2015/10/09/movie-main-page">' ?>

Upvotes: 1

Related Questions