view post types on the site
-
Friends’m studying posttypes is running in the test environment CRUD.
But I do not know how do I appear in the former site:
If you created a posttype portfolio or products such as phaco to remain visible for people to see, they were hidden in the admin, so the admin appear.I used the following examples
http://tableless.com.br/custom-post-types-wordpress/
http://www.escolawp.com/2010/07/como-criar-custom-post-types-wordpress/How do I resolve this?
since already grateful.
-
Hello @hyper_pixel,
I would like to help you, but I’m having trouble understanding your English.
If I read your question correctly (and not sure I do), it sounds like you’ve created some Custom Post Type(s), but you’re not seeing them in your Admin Menu (on the left) in the back end when you’re logged in?
Can you please post the snippet you added to your functions.php (or plugin) that registers your Custom Post Type? Also are you logged in as an Admin?
Hy
after I soon see the admin problem I want to know how do I appear on the site’s home that is for users to see?#TRECHO DOS PRODUTOS
add_action(‘init’, ‘produtos_register’);
function produtos_register() {
$labels = array(
‘name’ => _x(‘Produtos’, ‘post type general name’),
‘singular_name’ => _x(‘Produto’, ‘post type singular name’),
‘add_new’ => _x(‘Adicionar Novo’, ‘Produtos item’),
‘add_new_item’ => __(‘Adicionar Novo Produto’),
‘edit_item’ => __(‘Editar Produto’),
‘new_item’ => __(‘Novo Produto’),
‘view_item’ => __(‘Visualizar Produtos’),
‘search_items’ => __(‘Procurar Produtos’),
‘not_found’ => __(‘Nothing found’),
‘not_found_in_trash’ => __(‘Nothing found in Trash’),
‘parent_item_colon’ => ”
);$args = array(
‘labels’ => $labels,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘query_var’ => true,
‘menu_icon’ => get_stylesheet_directory_uri() . ‘/article16.png’,
‘show_in_menu’ => true,
‘rewrite’ => true,
‘capability_type’ => ‘post’,
‘has_archive’ => true,
‘hierarchical’ => false,
‘menu_position’ => null,
‘supports’ => array(‘title’,’editor’,’thumbnail’)
);register_post_type( ‘produtos’ , $args );
}add_action(“admin_init”, “admin_init”);
function admin_init(){
add_meta_box(“Nome-meta”, “Nome”, “Nome”, “produtos”, “side”, “low”);
add_meta_box(“credits_meta”, “Detalhes”, “credits_meta”, “produtos”, “normal”, “low”);
}function Nome(){
global $post;
$custom = get_post_custom($post->ID);
$Nome = $custom[“Nome”][0];
?>
<label>Nome:</label>
<input name=”Nome” value=”<?php echo $Nome; ?>” />
<?php
}function credits_meta() {
global $post;
$custom = get_post_custom($post->ID);
$ID = $custom[“ID”][0];
$Nome = $custom[“Nome”][0];
$Preco = $custom[“Preco”][0];
$Detalhes = $custom[“Detalhes”][0];
?>
<p><label>ID:</label>
<input type=”text” name=”ID” value=”<?php echo $ID; ?>” /></p>
<p><label>Nome:</label>
<input type=”text” name=”Nome” value=”<?php echo $Nome; ?>” /></p>
<p><label>Preco:</label>
<input type=”text” name=”Preco” value=”<?php echo $Preco; ?>” /></p>
<p><label>Detalhes:</label>
<textarea cols=”50″ rows=”5″ name=”Detalhes”><?php echo $Detalhes; ?></textarea></p>
<?php
}add_action(‘save_post’, ‘save_details’);
function save_details(){
global $post;update_post_meta($post->ID, “ID”, $_POST[“ID”]);
update_post_meta($post->ID, “Nome”, $_POST[“Nome”]);
update_post_meta($post->ID, “Preco”, $_POST[“Preco”]);
update_post_meta($post->ID, “Detalhes”, $_POST[“Detalhes”]);
}add_action(“manage_posts_custom_column”, “produtos_custom_columns”);
add_filter(“manage_edit-produtos_columns”, “produtos_edit_columns”);function produtos_edit_columns($columns){
$columns = array(
“cb” => “<input type=\”checkbox\” />”,
“title” => “Produtos Title”,
“Detalhes” => “Detalhes”,
“Preco” => “Preco”,);
return $columns;
}
function produtos_custom_columns($column){
global $post;switch ($column) {
case “description”:
the_excerpt();
break;
case “year”:
$custom = get_post_custom();
echo $custom[“descricao”][0];
break;
case “skills”:
echo get_the_term_list($post->ID, ‘Skills’, ”, ‘, ‘,”);
break;
}
}#TRECHO DO PORTFOLIO
add_action(‘init’, ‘portfolio_register’);
function portfolio_register() {
$labels = array(
‘name’ => _x(‘My Portfolio’, ‘post type general name’),
‘singular_name’ => _x(‘Portfolio Item’, ‘post type singular name’),
‘add_new’ => _x(‘Add New’, ‘portfolio item’),
‘add_new_item’ => __(‘Add New Portfolio Item’),
‘edit_item’ => __(‘Edit Portfolio Item’),
‘new_item’ => __(‘New Portfolio Item’),
‘view_item’ => __(‘View Portfolio Item’),
‘search_items’ => __(‘Search Portfolio’),
‘not_found’ => __(‘Nothing found’),
‘not_found_in_trash’ => __(‘Nothing found in Trash’),
‘parent_item_colon’ => ”
);$args = array(
‘labels’ => $labels,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘query_var’ => true,
‘menu_icon’ => get_stylesheet_directory_uri() . ‘/article16.png’,
‘rewrite’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘menu_position’ => null,
‘supports’ => array(‘title’,’editor’,’thumbnail’)
);register_post_type( ‘portfolio’ , $args );
}register_taxonomy(“Skills”, array(“portfolio”), array(“hierarchical” => true, “label” => “Skills”, “singular_label” => “Skill”, “rewrite” => true));
add_action(“admin_init”, “admin_initportfolio”);
function admin_initportfolio(){
add_meta_box(“year_completed-meta”, “Year Completed”, “year_completedportfolio”, “portfolio”, “side”, “low”);
add_meta_box(“credits_metaportfolio”, “Design & Build Credits”, “credits_metaportfolio”, “portfolio”, “normal”, “low”);
}function year_completedportfolio(){
global $post;
$custom = get_post_custom($post->ID);
$year_completedportfolio = $custom[“year_completedportfolio”][0];
?>
<label>Year:</label>
<input name=”year_completed” value=”<?php echo $year_completedportfolio; ?>” />
<?php
}function credits_metaportfolio() {
global $post;
$custom = get_post_custom($post->ID);
$designers = $custom[“designers”][0];
$developers = $custom[“developers”][0];
$producers = $custom[“producers”][0];
?>
<p><label>Designed By:</label>
<textarea cols=”50″ rows=”5″ name=”designers”><?php echo $designers; ?></textarea></p>
<p><label>Built By:</label>
<textarea cols=”50″ rows=”5″ name=”developers”><?php echo $developers; ?></textarea></p>
<p><label>Produced By:</label>
<textarea cols=”50″ rows=”5″ name=”producers”><?php echo $producers; ?></textarea></p>
<?php
}add_action(‘save_post’, ‘save_detailsportfolio’);
function save_detailsportfolio(){
global $post;update_post_meta($post->ID, “year_completedportfolio”, $_POST[“year_completedportfolio”]);
update_post_meta($post->ID, “designers”, $_POST[“designers”]);
update_post_meta($post->ID, “developers”, $_POST[“developers”]);
update_post_meta($post->ID, “producers”, $_POST[“producers”]);
}add_action(“manage_posts_custom_column”, “portfolio_custom_columns”);
add_filter(“manage_edit-portfolio_columns”, “portfolio_edit_columns”);function portfolio_edit_columns($columns){
$columns = array(
“cb” => “<input type=\”checkbox\” />”,
“title” => “Portfolio Title”,
“description” => “Description”,
“year” => “Year Completedportfolio”,
“skills” => “Skills”,
);return $columns;
}
function portfolio_custom_columns($column){
global $post;switch ($column) {
case “description”:
the_excerpt();
break;
case “year”:
$custom = get_post_custom();
echo $custom[“year_completedportfolio”][0];
break;
case “skills”:
echo get_the_term_list($post->ID, ‘Skills’, ”, ‘, ‘,”);
break;
}
}#FILMES
/**
* Adicionamos uma acção no inicio do carregamento do WordPress
* através da função add_action( ‘init’ )
*/
add_action( ‘init’, ‘create_post_type_film’ );/**
* Esta é a função que é chamada pelo add_action()
*/
function create_post_type_film() {/**
* Labels customizados para o tipo de post
*
*/
$labels = array(
‘name’ => _x(‘Films’, ‘post type general name’),
‘singular_name’ => _x(‘Film’, ‘post type singular name’),
‘add_new’ => _x(‘Add New’, ‘film’),
‘add_new_item’ => __(‘Add New Film’),
‘edit_item’ => __(‘Edit Film’),
‘new_item’ => __(‘New Film’),
‘all_items’ => __(‘All Films’),
‘view_item’ => __(‘View Film’),
‘search_items’ => __(‘Search Films’),
‘not_found’ => __(‘No Films found’),
‘not_found_in_trash’ => __(‘No Films found in Trash’),
‘parent_item_colon’ => ”,
‘menu_name’ => ‘Films’
);/**
* Registamos o tipo de post film através desta função
* passando-lhe os labels e parâmetros de controlo.
*/
register_post_type( ‘film’, array(
‘labels’ => $labels,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘has_archive’ => ‘films’,
‘rewrite’ => array(
‘slug’ => ‘films’,
‘with_front’ => false,
),
‘capability_type’ => ‘post’,
‘has_archive’ => true,
‘hierarchical’ => false,
‘menu_position’ => null,
‘supports’ => array(‘title’,’editor’,’author’,’thumbnail’,’excerpt’,’comments’)
)
);/**
* Registamos a categoria de filmes para o tipo de post film
*/
register_taxonomy( ‘film_category’, array( ‘film’ ), array(
‘hierarchical’ => true,
‘label’ => __( ‘Film Category’ ),
‘labels’ => array( // Labels customizadas
‘name’ => _x( ‘Categories’, ‘taxonomy general name’ ),
‘singular_name’ => _x( ‘Category’, ‘taxonomy singular name’ ),
‘search_items’ => __( ‘Search Categories’ ),
‘all_items’ => __( ‘All Categories’ ),
‘parent_item’ => __( ‘Parent Category’ ),
‘parent_item_colon’ => __( ‘Parent Category:’ ),
‘edit_item’ => __( ‘Edit Category’ ),
‘update_item’ => __( ‘Update Category’ ),
‘add_new_item’ => __( ‘Add New Category’ ),
‘new_item_name’ => __( ‘New Category Name’ ),
‘menu_name’ => __( ‘Category’ ),
),
‘show_ui’ => true,
‘show_in_tag_cloud’ => true,
‘query_var’ => true,
‘rewrite’ => array(
‘slug’ => ‘films/categories’,
‘with_front’ => false,
),
)
);/**
* Esta função associa tipos de categorias com tipos de posts.
* Aqui associamos as tags ao tipo de post film.
*/
register_taxonomy_for_object_type( ‘tags’, ‘film’ );}
What must the films, products and portfolio are visible on the site.
Well it looks like you’ve setup your CPTs correctly, but remember that WP will not *by default* display Custom Post Types in the standard Loop – you need to add that yourself by either adding templates for those CPTs and/or modifying the Loop (for your homepage) as shown in the example here from the codex (scroll down until you see “Querying by Post Type”):
https://codex.wordpress.org/Post_Types
When you modify the Loop, you can specify ONLY the CPT you want in the ‘post_type’ attribute OR you can create an array of multiple post types if you want more than just Products returned.
When you create custom templates (e.g. single-product.php, achive-product.php, taxonomy-product.php) then WP will understand that it’s supposed to return that post type.
I not yet understand I created the pages single-product.php, achive-product.php but as chamos them in the home, for example by displaying the products with price, details?
In the search appears but only the name and a photo.I will try this
$args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo ‘<div class=”entry-content”>’;
the_content();
echo ‘</div>’;
endwhile;I did, put this code in the index
$ Args = array ( ‘post_type’ => ‘products’, ‘posts_per_page’ => 10);
$ Loop = new WP_Query ($ args);
while ($ loop-> have_posts ()): $ loop-> the_post ();
the_title ();
echo ‘<div class = “entry-content”>’;
the_content ();
echo ‘</ div>’;
endwhile;He gave the loop but it came on home without a link to access the visualization of the page, as show the attributes of posttypes
example:
product has price, details etc.Hi @hyper-pixel,
Sorry I’ve not been back in the forum here lately.
OK so I understand you want to display some of your products’ ‘meta data’ (stored in the Post’s custom fields) – you will need to modify your template files that display the single product and the archived products to do that…..
SO you will have to decide exactly *where* to place the PHP in the template, either above or below ‘the_content()’ which is whatever you put in the main ‘write’ box on the Post, but you first have to setup the post data to get at the info.
Below is just an example – read this page to learn more:
https://developer.wordpress.org/reference/functions/get_post_meta/Setting up the variables to hold the data:
$price = get_post_meta(‘price’,$post->ID,true);
(the can go anywhere inside the loop…..in place of ‘price’ use the actual name of your key/custom field, you use ‘true’ to indicate a single value, false indicates an array)To display that data:
The price for this product is: <?php echo $price; ?>This will display the *value* of that field. Repeat for any custom fields for which you want to display data.
In your archive page, you’ll generally find a ‘while have posts’ loop or sometimes a ‘foreach’….you need to setup your variable for each one in that part of the loop so it knows from which post to pull the value.
I hope this helps!
The topic ‘view post types on the site’ is closed to new replies.