Change URL of previous posts and next posts link in Wordpress - php

I'd like to change the URL of the <?php previous_posts_link ?> and <?php next_posts_link ?> that are being outputted by Wordpress.
Problem:
When I am on my single page, I am getting this kind of an url:
http://example.com/post-title/2/
What I like to achieve:
When I am on my single page, I would like to get:
http://example.com/2/
So, the URL without the post title!
I don't know if this is even possible, but I'd like to understand if this is doable or not.
Could someone help me out here, please?

Get next/previous post object using get_previous_post() & get_next_post() and build your custom url.

You can create custom URLs for your pages within the .htaccess file. I found a useful link that might be able to help you out from another thread. php custom link and custom pages

Related

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
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">' ?>
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();**
There are two ways to achieve what you're doing.
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/ .
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.

Pass query string variable to WordPress page template

I have a fully-functional WordPress site with a URL structure like this:
http://example.com/friendlyurl/
But I would like to be able to pass an ID number like this (or whatever URL structure would work):
http://example.com/friendlyurl/?id=123
I have a custom page template that will handle everything from there, I just need a simple way to get the number to the page template. I.e.:
$id=trim($_GET["id"]);
I am not a WordPress whiz, just looking for a simple solution here to solve a problem. Would appreciate any advice or direction.
Thank you!

Need help changing search results URL to something which can be bookmarked

I hope someone can help me with this.
Currently when someone does a search on my website, the page that is returned has the URL:
http://www.dublinjobs.ie/main/index.
(Let's call this "the search results URL").
If you scroll to the bottom of the page you will see the pagination URLs use the form
http://www.dublinjobs.ie/main/index/2/basic/php/0/relevance/all/0/0/20/0/0/0/0/0/0/0.
(Let's call this "the pagination URL").
Is there some way I can change my website so the search results URL has a similar format to the pagination URL?
I need to to fix this because currently the search results URL cannot be bookmarked or emailed to someone as it is unspecific.
I'm guessing the solution is some sort of internal URL rewrite but I am not sure how to do this.
Thank you for your assistance.
EDIT: I don't want to just use a GET instead of a POST as I want to be able to control the URL layout.
Even your pagination URL doesn't include search term. What you need is to include search keywords in the URL itself to make it unique which can be bookmarked or shared.
Most likely you're using method="POST" in your search form which needs to change to: method="GET".
Note that it will make your URL like:
http://www.dublinjobs.ie/main/index?search=keyword
OK. I have a dirty hack fix.
I am using a header redirect in my PHP code to send them to the URL I want after doing my processing.

Wordpress sidebar to load specific posts

I am building a website in Wordpress and I need a sidebar that when you click the name of each post on the sidebar, it loads that specific post in the middle of the page.
I am unsure of how to go about doing this.
I am new to wordpress and php and any help is appreciated :)
Well basically as far as I understood you want to replace the current middle content with post content.
To do that you will have to use AJAX connection. You will need to pass post id to function, where you will retrieve post data and return it back to the page, where you will need to just insert it in the content.
I suggest that you check these links -
http://api.jquery.com/jQuery.ajax/
http://codex.wordpress.org/AJAX
Example -
http://net.tutsplus.com/tutorials/javascript-ajax/uploading-files-with-ajax/
http://www.1stwebdesigner.com/css/implement-ajax-wordpress-themes/
A more simple solution would be just to add the_permalink(); to page link, so it directly links to the post.

How to add dynamicly linked and created pages in wordpress?

Since I had some comments on the formulation of my question, I decided to rewrite it completely. And also, I understand a little bit more about wordpress so it should make more sense now.
So, let's start with what I'm trying to accomplish by using a simple example:
Goal:
Make a search engine for some products and link to them using a database to generate the information.
Result:
http://my.site.url/wordpress/<plugin-name> <-- The page with the "search" and "search result
http://my.site.url/wordpress/<plugin-name>/products/<product_name> <-- When click on a search result
Part 1:
I want to make a plugin with the name "plugin-name" Right now, I put my code in
http://my.site.url/wordpress/wp-content/plugins/<plugin-name>
On the activate, I create some tables with some data. Since there is no page yet, I create 1 on the fly using the API call 'wp_insert_post'. I give the name and slug "myPlugin".
So, when I go on the main site, I can see my newly created page "myPlugin". But right now, there is no content attached to it. To do so, from what I understand, I need to create a page in my plug-in directory named "myPlugin.php".
http://my.site.url/wordpress/wp-content/plugins/<plugin-name>/myPlugin.php
So, how do I link the page I created manually and the source file in the plugin directory?
Part 2
When clicking on a link in the search result, I would like to have a page "product.php" and display its information. So, is it possible to create a "temporary url" for the result using sub pages (see result at the beginning)? And if possible, how can we achieve that?
Thanks in advance and I hope it's clearer.
u can find how to create plugin from
http://ditio.net/2007/08/09/how-to-create-wordpress-plugin-from-a-scratch/
in plugin write function for search(as per u r logic) fetch result
create a custom page refer video from www.wordpressmax.com/customize-wordpress/custom-page
in custom pages template in between get_header(); and get_footer(); call search function and display records.
Thats it.
thisMayhem is right. This sounds like a bunch of nonsense. But, if you're trying to make a WP page that executes some custom PHP, look up the WP template hierarchy.
What you can do is this:
create a WP "page" - call it "Search results."
create a template directory file called page-search-results.php (filename corresponds with slug of page from step 1)
put some generic header/footer stuff there (see other template files - most often it's just a question of putting in <?php get_header(); ?> and <?php get_footer(); ?>)
put PHP code in that thar page. in them hills.
if you use a caching plugin, may want to put an exemption for /search-results/
So, when someone pulls up http://your.site/search-results/ - your custom PHP code will execute. It's up to you to make that logic and communication happen - whether via $_GET or $_POST, etc.
I'm sorry you're experiencing some problems. Unfortunately as we say above because it's a 'one off' for a client project we can't support it - it works for them :) Feel free to rip it apart and retest and if you have any success let us know.

Categories