Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

One Custom Post Type two different Templates WordPress


I have a custom post type with some metaboxes, for this CPT have his own single-CPT.php where I show his content and metaboxes and url But what I need to know is if posible to create a second template where I only show the metaboxes content of this CPT and url

Hope it make sence and have a solution :P

Thanx to all.

Answers (2)


Francisco Javier Carazo Gil answers:

Hi Pancho,

Well, to make it possible you need to know which URL are you using. How?

First try: get_permalink() if the function is not working, try the next code.

function get_current_url () {
if (isset($_SERVER['REQUEST_URI'])) {
$current_url = $_SERVER['REQUEST_URI'];
} else {
$current_url = $_SERVER['SCRIPT_NAME'];
$current_url .= (!empty($_SERVER['QUERY_STRING'])) ? '?' . $_SERVER['QUERY_STRING'] : '';
return $current_url;

Now you know your current URL so it's the moment to do the if statement:

if($current_url == "A")
echo "aaaaaa";
echo "bbbb";

If need more help tell me.

Pancho Pérez comments:

genial, lo pruebo esta noche a ver si funciona :)

Francisco Javier Carazo Gil comments:

<em>Sorry for speaking in Spanish but Pancho, Luis and me are Spanish speakers and this is a exception</em>

Perfecto Pancho,

Muchas gracias.

Ya me dices.

Pancho Pérez comments:

Hi Francisco, tocayo ;)

<em>English is better for this site, we can help more users ;)</em>

I understand the idea to get the link so then show one type of content or other, but my problem is there is not a second link. I think to do what I need is better IF the CPT can have a second URL and with this choose wich content show, and then your code could work. i.e: the CTP have a permalink like, how can I create a rule using functions.php or htaccess where all this CPTs have a second url builded with the content (text) from the metabox of the same CPT.

So, How can I create that url?