vendredi 28 novembre 2014

Custom Post Type URL


I have big problems get the result with my custom post type and taxonomy I have made. I have read a lot in the questions and tried also many, but don't know where to find the solution or where to start again to search, so I'm asking here.


I know it's an old fish.


CPT name: offer, Taxonomy: category and screw is the Post.


I would like to have this structure:



http://ift.tt/1uUhdqh


and not: http://ift.tt/15IV8Xm or, http://ift.tt/1uUhaLf


It's loosing the context where the product is from. So what should I look for?


I think it should not be so hard, something I have missed.


Also there is the question what should I use to display this kind of structure. I have made an archive-offer.php file that is showing all new posts - but if I click on the taxonomy it changes the URL to the slug from the taxonomy and strips the offer-path of. also I have single.php file used for the products single page.


-----EDIT_________________________________________________________________________


first, thanks for the answers!


to make more clear, here some facts and the code:


i named the taxonomy > category, because i would like to remove and add categorys for diffrent products on the fly. so, if i have a old car for sale, i make the taxonomy cars.


is this the wrong way to use the taxonomy system as categorys? - if not, i would be able to make a complete new taxonomy for a whole new sort of products-category like paintings, that d'oesent fits in the other taxonomy-system (cars, bikes, computers, ...) - so my code is complete - here have a look:



add_action( 'init', 'create_produkte_hierarchical_taxonomy', 0 );

//create a custom taxonomy name produkte kategorie (products categorys)

function create_produkte_hierarchical_taxonomy() {

$labels = array(
'name' => _x( 'Produkte Kategorien', 'taxonomy general name' ),
'singular_name' => _x( 'Produkte Kategorie', 'taxonomy singular name' ),
'search_items' => __( 'Suche Produkte Kategorie' ),
'all_items' => null,
'parent_item' => null,
'parent_item_colon' => __( 'Parent Produkte Kategorie:' ),
'edit_item' => __( 'Produkte Kategorie bearbeiten' ),
'update_item' => __( 'Update Produkte Kategorie' ),
'add_new_item' => __( 'Neue Produkte Kategorie hinzufügen' ),
'new_item_name' => __( 'Neue Produkte Kategorie' ),
'menu_name' => __( 'Produkte Kategorien' ),
);

// register the taxonomy

register_taxonomy('produkte_kategorien',array('inserate'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'kategorie' ),
));

}
// Create Custom Post type, called Inserate (offers)
function create_post_type_gnagerinserate()
{
register_post_type('inserate',
array(
'labels' => array(
'name' => __('Inserate'),
'singular_name' => __('Inserat'),
'add_new' => __('Neu hinzufügen'),
'add_new_item' => __('Neues Inserat verfassen'),
'edit' => __('Bearbeiten'),
'edit_item' => __('Inserat bearbeiten'),
'new_item' => __('Neues Inserat'),
'view' => __('Ansehen'),
'view_item' => __('Inserat ansehen'),
'search_items' => __('Inserate suchen'),
'not_found' => __('Keine Inserate gefunden'),
'not_found_in_trash' => __('Keine Inserate im Papierkorb vorhanden')
),
'public' => true,
'hierarchical' => true, //
'has_archive' => true,
'rewrite' => array( 'slug' => 'inserate' ),
'show_in_nav_menus' => true,
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail'
), //
'can_export' => true, //
'taxonomies' => array(
'post_tag',
'Produkte Kategorien',
'Paintings Kategorien',
// or more others
)
));
}


---> the offers are the inserate


ah forget: i use the permalink-structure: postname (and would like to keep this if possible)


-------___________________________________________________________________________


what i have now and also would like to have is this:


offers/ -> archive-offer page (list with all recent offers (posts) and a list with links with the created taxonomys (cars bike tomatos,...)


then click those taxonomy-tomatos brings the right url in place->


offers/tomatos - an archive page with the offers in this taxonomys. this now shows the correct url. the post itself not found anymore ,404. but the uri seems good. so i'm still at the initial situation, whatever i change slug rewrite to. in this - wordpress lacks big time. it's a key-feature for all purposes that needs some kind of computer sience degree to be done.





Aucun commentaire:

Enregistrer un commentaire