I don't have the link to the site, but I'm 200% sure, that there are sites with "generators" that helps to generate needed code.
Adding CPM is quite simple and can be "generated". Then You could load it as additional library to our template, or just place in newly created plugin.
Its same with adding custom taxonomies for that CPT.
Ill post You some code that might be helpfull - You can always look for informations in wordpress codex etc.
Creating CPT:
- Code: Select all
//add tweet custom post type
add_action( 'init', 'cs_twitter_register_post_types' );
function cs_twitter_register_post_types() {
$tweet_args = array(
'public' => true,
'rewrite' => array(
'slug' => 'tweets',
'with_front' => false,
'pages' => false
),
'supports' => array(
'title'
),
'labels' => array(
'name' => 'Tweety',
'singular_name' => 'Tweet',
'add_new' => 'Dodaj nowy Tweet',
'add_new_item' => 'Dodaj nowy Tweet',
'edit_item' => 'Edytuj Tweet',
'new_item' => 'Nowy Tweet',
'view_item' => 'Wyswietl Tweet',
'search_items' => 'Wyszukaj Tweety',
'not_found' => 'Tweetów nie znaleziono',
'not_found_in_trash' => 'Brak usuniętych Tweetów'
),
'has_archive' => true,
'menu_position' => 4
);
register_post_type( 'tweets', $tweet_args );
}
some info about using shortcodes:
- Code: Select all
add_action( 'init', 'cs_register_form_shortcode' );
function cs_register_form_shortcode() {
add_shortcode( 'dodajpoleinput', 'cs_form_input_shortcode' );
add_shortcode( 'dodajpoletextarea', 'cs_form_textarea_shortcode' );
add_shortcode( 'grupujpola', 'cs_form_group_elements' );
}
function cs_form_input_shortcode($atts){
//parametry
//nazwa skrocona (przekazywana z formularzem, unikalna)
//nazwa pelna (Imie i Nazwisko, e-mail )
//rodzaj validacji (brak, email, telefon, nip, niepuste, imienazwisko)
$defaults = array(
'tytul' => "Puste pole",
'skrocona' => "emptyfield",
'validuj' => "" //nie, email, telefon, nip, niepuste
);
extract( shortcode_atts( $defaults, $atts ) );
if ($validuj == 'nie' || $validuj == '') {
$star = '';
$type = '';
} elseif ($validuj == 'email') {
$star = '*';
$type = ' validateme email';
} elseif ($validuj == 'telefon') {
$star = '*';
$type = ' validateme telefon';
} elseif ($validuj == 'nip') {
$star = '*';
$type = ' validateme nip';
} elseif ($validuj == 'niepuste') {
$star = '*';
$type = ' validateme niepuste';
} else {
$star = '*';
$type = ' validateme niepuste';
}
//$output = '<tr><td class="label">'.$tytul.$star.'</td><td id="_'.$skrocona.'"><input type="text" name="'.$skrocona.'" class="input_field clear" style="color:#4c4e51;" /></td></tr>';
$output = '<div class="rowholder"><div class="elementsholder"><label for="id_'.$skrocona.'">'.$tytul.' '.$star.'</label><input type="text" id="id_'.$skrocona.'" name="'.$skrocona.'" class="input_field clear'.$type.'" /></div></div>';
return $output;
}
function cs_form_textarea_shortcode($atts) {
$defaults = array(
'tytul' => "Puste pole",
'skrocona' => "emptyfield",
'validuj' => "" //nie, email, telefon, nip, niepuste
);
extract( shortcode_atts( $defaults, $atts ) );
if ($validuj == 'nie' || $validuj == '') {
$star = '';
$type = '';
} elseif ($validuj == 'email') {
$star = '*';
$type = ' validateme email';
} elseif ($validuj == 'telefon') {
$star = '*';
$type = ' validateme telefon';
} elseif ($validuj == 'nip') {
$star = '*';
$type = ' validateme nip';
} elseif ($validuj == 'niepuste') {
$star = '*';
$type = ' validateme niepuste';
} else {
$star = '*';
$type = ' validateme niepuste';
}
$output = '<div class="rowholder"><div class="elementsholder"><label for="id_'.$skrocona.'">'.$tytul.' '.$star.'</label><textarea id="id_'.$skrocona.'" name="'.$skrocona.'" class="input_field clear'.$type.'"></textarea></div></div>';
return $output;
}
function cs_form_group_elements($atts, $content = null){
return '<div class="grouped">'.do_shortcode($content).'</div>';
}
Those are saples from one of my projects, and show logic and functions that can be used to create both CPT and shortcode.