English 中文(简体)
wordpress permalink post_type
原标题:

i am looking for a way to get the post_type into a wordpress permalink structure - especially considering custom post_type s defined by my own plugin.

is there an easy way to do that, or do you know any decent documents about wordpress url handling / redirection (codex seems to lack a bit on the rewriting side of things).

最佳回答

It seems that if you use any permalink structure besides the default, then you end up getting a permalink structure of /post_type/post_name.

So, if I registered the post_type video it would be http://yourdomain.com/video/post_name

If you re using the default permalink, then obviously it doesn t matter because you ll just have ?id=123 or whatever. (Though, you can specify post_type as a query_var, which can be useful in your theme.)

As a sidenote, it seems ridiculously difficult to try and override WP s default URL routing, and you COULD do it by using some of the actions and filters... but the above should work for what you are wanting.

问题回答

By post_type do you mean category? If so, I think you can do this using the custom permalinks settings in the wordpress admin panel.

%category% is the one you want. Note from the wordpress codex there is a warning about performance if it s at the start of the permalink - I haven t used this, so something you may want to look into:

%category% - A sanitized version of the category name (category slug field on New/Edit Category panel). Nested sub-categories appear as nested directories in the URI. Starting Permalinks with %category% is strongly not recommended for performance reasons.

EDIT - If however, you are looking for post type, as in post / page, then this will be more tricky. It isn t one of the built in structure tags, so you may be looking at having to add this new structure tag, which would be a change to wp-includes ewrite.php (and reapplying with each new wordpress patch). There may be another way to do it with mod-rewrite, but heading beyond the scope of my knowledge I m afraid





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签