views:

480

answers:

5

In a plugin, I am generating a paginated link to a category,
i.e. http://localhost/?cat=17&paged=5. The category is known by slug and id.

Is there a way to have this URL converted to the user defined "nice permalink" format,
i.e. http://localhost/category/foo/page/5?

(Assuming we're running Wordpress 2.8/2.9+)

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

  • The category ID
  • The page number (i.e. the fifth page of that category's archive)

With these data I can create the URL to that page, which would be, for example, http://localhost/?cat=17&paged=5, and that works well. The problem is of a visual nature: If the user has pretty permalinks enabled, then this won't fit in very well. Question is: How do I get the correct, pretty permalink (i.e. http://localhost/category/foo/page/5) from (or for) the information I have?

Edit 2: Obviously if a user has pretty permalinks disabled, then there are no pretty permalinks. I know that, and that is really not subject of the question ... For the moment, let's just assume the user has an arbitrary permalink setting. I generate a link, and it should look like the user wants it to.

+1  A: 

Have you looked at the WP_Rewrite?

Manzabar
Yes, but I'm not sure how to use it for that task.
Markus
Do you know of any examples how to use the WP_Rewrite for this purpose? All I can find is how to add new permalink tags, etc.(The codex is _most_ useful once again ...)
Markus
Sorry, but I've not used it either. I did some more poking around the Codex and ran across the Rewrite API, maybe that will help?http://codex.wordpress.org/Rewrite_API
Manzabar
Unfortunately not. From what I understand it works the other way round, allowing a "nice" permalink to be parsed into $_GET variables.Thanks alot though!
Markus
A: 

Does All In One SEO meet your requirements? I actually bought the "pro" version for like $30 USD and it was well worth it.

Tony
Unfortunately not. It does not seem to rewrite URLs.
Markus
A: 

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

shipshape
No, definitely not. (If you add `<?php echo 'http://localhost/?cat=17 ?>` - or any similar link - somewhere in your theme you'll see the problem.)
Markus
I just tried that with my theme, and Wordpress correctly interpreted the URL and redirected me to the proper page according to my permalink settings. Are you using 2.9.2?
shipshape
Maybe I am misunderstanding your problem - if you are just echoing the URL as a string, then Wordpress is not going to do anything with it. But if you make it into a link and click it, you should be redirected to the correct page.
shipshape
The redirect is not the problem, the problem is the fact that it looks ugly. :)
Markus
Put the page number you want in a variable called $pagenumber, and try this: <a href="<?php echo get_category_link( $category_id ) . "paged/" . $pagenumber; ?>">Category Link</a>
shipshape
I'll have to check it, but in the worst case I'd produce "http://localhost/?cat=17/paged=5", resulting in "17/paged=5" as the category id. Does WP parse that?
Markus
A: 

Hi Markus, check this page out, it explains pretty permalinks pretty good. http://codex.wordpress.org/Using_Permalinks

You should find these settings in

Wordpress->Settings->Permalinks

I think

/%category%/%postname%

in the direction what you want

You can also try to redirect your 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... :-(

kind regards, Mahatmanich

mahatmanich
Alles schön und gut - und danke für die Antwort - aber jeder hier beantwortet alles mögliche, nur nicht meine Frage! :/ Mein Blog hat pretty permalinks und alles funktioniert, wie es soll. Wenn ich jetzt ein Plugin schreibe, habe ich als Programmierer aber keine Ahnung davon, was der Benutzer in seinem Blog eingestellt hat. Ich suche eine Möglichkeit, einen Link zu einer Seite so zu generieren, dass er sich in die Einstellungen des Blogs einfügt. Nen hässlichen Link generieren, der seinen Zweck erfüllt, ist kein Problem - einen schönen zu generieren allerdings zu schon.
Markus
JA AAABER ... Ich verstehe jetzt besser was du meinst, solange der Bloguser aber kein mod_rewrite angestellt hat, keine .htaccess datei angelegt hat, und oder keine settings unter permalinks gesetzt hat lauefst du gegen eine wand ... und da hilft dir auch nicht das dein "plugin" dann ein pretty rewrite macht. Ohne die einstellungen geht es nun mal einfach nicht.
mahatmanich
du kannst nach php mod_rewrite checken, und dann vielleicht nach den settings die der user in wordpress eingestellt hat, das sollte sich aus der Datenbank rausziehen lassen ... und dann wuerde ich darauf aufbauen ...
mahatmanich
@Markus @mahatmanich For the benefit of the community, can we please keep the content in English? There is on-topic discussion in there...
Marc Gravell
No Problemo Marc
mahatmanich
@Marc - Absolutely, I just explained in German what I said in the question. :)
Markus
A: 

I'm guessing you already figured it out but I just wanted to put this out for others. I think I understand your situation. If I've read your question correctly, changing admin permalink settings does not apply.

You can get the category ID then use get_category_link() function to get the 'pretty' permalink. Then append the pagination to the end.

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

Is this what you were looking for?

jtlowe