Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
$5
One Custom Post Type two different Templates
Hope it make sence and have a solution :P
Thanx to all.
This question has been answered.
Pancho Pérez | 12/14/11 at 12:17pm
Edit
The experts have suggested, on average, a prize of $20 for this question.
(2) Possible Answers Submitted...
See a chronological view of answers?
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
-

Last edited:
12/14/11
12:21pmLuis Abarca says:Same url ??
you can use a query var to show a different template, with an if statement- 12/14/11 12:27pm
Pancho Pérez says:not exactly same url. CPT is domain.com/CPT, and to show the second template need to be domain.com/CPT/metaboxes-template
- 12/14/11 12:27pm
-

Last edited:
12/14/11
12:29pmFrancisco Javier Carazo Gil says: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";
else
echo "bbbb";
If need more help tell me.- 12/14/11 12:32pm
Pancho Pérez says:genial, lo pruebo esta noche a ver si funciona :)
- 12/14/11 12:34pm
Francisco Javier Carazo Gil says:Sorry for speaking in Spanish but Pancho, Luis and me are Spanish speakers and this is a exception
Perfecto Pancho,
Muchas gracias.
Ya me dices. - 12/14/11 3:20pm
Pancho Pérez says:Hi Francisco, tocayo ;)
English is better for this site, we can help more users ;)
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 domain.com/CPT-title, 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?
- 12/15/11 2:44am
Francisco Javier Carazo Gil says:Hi Pancho,
Well, to create the permalink with CPT you should use a structure like this one (look at rewrite):
/*
* product custom post type added with new permalink
*/
function productposttype_with_custom_permalinks() {
register_post_type('product', array(
'label' => __('My product'),
'singular_label' => __('product'),
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
"supports" => array("title", "editor", "thumbnail", "author", "comments"),
'taxonomies' => array('category', 'post_tag'), // this is IMPORTANT
'rewrite' => array('slug' => 'product'),
'public' => true
));
With this structure you can work to set the second permalink as you want, use: add_rewrite_tag and add_permastruct.
For example:
add_rewrite_tag('%product%', '([^/]+)');
$extra_post_types = get_post_types(array('_builtin' => false, 'publicly_queryable' => true));
if (empty($extra_post_types))
return;
add_rewrite_tag('%post_type%', '(' . implode('|', $extra_post_types) . ')');
add_permastruct('product', '/%post_type%/%year%/%monthnum%/%day%/%product%/', true, 1);
}
Hope it helps!
- 12/14/11 12:32pm
This question has expired.
Gabriel Reguly, Christianto, Julio Potier voted on this question.
Current status of this question: Completed
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
