Wordpress: How do I convert a generated URL (permalink) to a pretty URL?

In the plugin, I create a pagination into categories,
those. http://localhost/?cat=17&paged=5 . The category is known by slug and id.

Is there a way to convert this URL to a custom permalink format,
those. http://localhost/category/foo/page/5 ?

(Suppose we run Wordpress 2.8 / 2.9 +)

Edit: Since there are some misunderstandings regarding what I'm trying to achieve, here is what I have:

  • Category id
  • Page number (i.e. the fifth page of this category archive)

With this data, I can create the URL of this page, which will be, for example, http://localhost/?cat=17&paged=5 , and this works well. The problem has a visual character: if the user has pretty permanent links, then this does not fit very well. Question: How do I get the correct, fairly permanent link (i.e. http://localhost/category/foo/page/5 ) from (or for) the information I have?

Edit 2: Obviously, if the user has fairly permalinks, then there are no good permalinks. I know this, and actually this is not a question. For now, let's assume that the user has an arbitrary permalink setting. I create a link, and it should look like the user wants.

+4
source share
6 answers

Have you looked at WP_Rewrite ?

+1
source

Does all in one SEO fit your requirements? I really bought a $ 30 “pro” version, and that was good.

0
source

My installation of Wordpress (2.9.2) does this automatically - canonical URLs have been built into Wordpress for some time. Did your plugin disable this feature ?

0
source

I suppose you already understood this, but I just wanted to pass it on to others. I seem to understand your situation. If I read your question correctly, changing the settings of the administrator’s permalink is not applicable.

You can get the category identifier and then use the get_category_link() function to get a “pretty” link. Then add the pagination to the end.

You can explode the permalink to get the category ID and page number, and then use the step above to put it together.

Is this what you were looking for?

0
source

The correct way to create a link would be to use get_category_link and add_query_arg

In your example, the following will work:

 $category_link = add_query_arg( array('paged' => 5), get_category_link($category->term_id)); 

This will create a URL and Wordpress will redirect to the correct page.

0
source

check this page, this explains the pretty permalink very well. http://codex.wordpress.org/Using_Permalinks

You should find these settings in

Wordpress-> Preferences-> Permalinks

I think,

/% Category% /% postname%

in the direction you want

You can also try redirecting the URL using htaccess, here are some examples:

[ http: //] perishablepress.com/press/2008/02/06/permalink-evolution-customize-and-optimize-your-dated-wordpress-permalinks/

Sorry, darf bis jetzt nur ein link posten pfft ...: - (

Regards, Mahatmanich

-1
source

Source: https://habr.com/ru/post/1304667/


All Articles