Get content type post and display within a page template
-
Good day,
I don’t know if I could explain my question in the title, but I will describe below what I’m doing:
1. I created a new template (Week.php):
<?php /** * Template Name: Dia da Semana * * Description: Simples PHP para mostrar um texto por dia da semana. * * @package WordPress * @subpackage Twenty_Twelve * @since Twenty Twelve 1.0 */ get_header(); ?> <div id="primary" class="site-content"> <div id="content" role="main"> <?php get_template_part( 'content', 'page' ); ?> <? date_default_timezone_set('America/Sao_Paulo'); $fuso = 0; $fator = "+"; $diasemana[0] = "Conteúdo de Domingo"; $diasemana[1] = "Conteúdo de Segunda"; $diasemana[2] = "Conteúdo de Ter?a"; $diasemana[3] = "Conteúdo de Quarta"; $diasemana[4] = "Conteúdo de Quinta"; $diasemana[5] = "Conteúdo de Sexta"; $diasemana[6] = "Conteúdo de Sábado"; $timeadjust = ($fuso * 60 * 60); if ($fator == "+"){ $diasem = date("w",time() + $timeadjust); } if ($fator == "-"){ $diasem = date("w",time() - $timeadjust); } $datar = "$diasemana[$diasem]"; echo $datar; ?> </div><!-- #content --> </div><!-- #primary --> <?php get_sidebar( 'front' ); ?> <?php get_footer(); ?>
2. I created a new type post (functions.php):
//Adicionar Cardápio como Tipo de Publica??o add_action( 'init', 'codex_cardapio_init' ); /** * Register a cardapio post type. * * @link https://codex.www.ads-software.com/Function_Reference/register_post_type */ function codex_cardapio_init() { $labels = array( 'name' => _x( 'Cardápios', 'post type general name', 'your-plugin-textdomain' ), 'singular_name' => _x( 'Cardápio', 'post type singular name', 'your-plugin-textdomain' ), 'menu_name' => _x( 'Cardápios', 'admin menu', 'your-plugin-textdomain' ), 'name_admin_bar' => _x( 'Cardápio', 'add new on admin bar', 'your-plugin-textdomain' ), 'add_new' => _x( 'Adicionar Novo', 'cardapio', 'your-plugin-textdomain' ), 'add_new_item' => __( 'Adicionar Novo Cardápio', 'your-plugin-textdomain' ), 'new_item' => __( 'Novo Cardápio', 'your-plugin-textdomain' ), 'edit_item' => __( 'Editar Cardápio', 'your-plugin-textdomain' ), 'view_item' => __( 'Ver Cardápio', 'your-plugin-textdomain' ), 'all_items' => __( 'Todos os Cardápios', 'your-plugin-textdomain' ), 'search_items' => __( 'Buscar Cardápios', 'your-plugin-textdomain' ), 'parent_item_colon' => __( 'Cardápios Relacionados:', 'your-plugin-textdomain' ), 'not_found' => __( 'Nenhum cardápio encontrado.', 'your-plugin-textdomain' ), 'not_found_in_trash' => __( 'Nenhum cardápio na lixeira.', 'your-plugin-textdomain' ) ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'cardapio', 'with_front' => false ), 'capability_type' => 'post', 'has_archive' => 'cardapio', 'hierarchical' => false, 'menu_position' => null, 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ) ); register_post_type( 'cardapio', $args ); }
What do I do with these two codes is displaying the contents of a page created using the new type post within the new template.
Sample: When creating a page of type “cardapio” using the title “Sunday”, in the content will put a form containing the options for this day. Thus, within the code I created for my new template, I would like of knowing what I put in place of “Conteúdo de Domingo” to be able to display the contents of the “Sunday”.
Addendum: I’m testing in Twenty Twelve theme with WordPress 3.8.1. But the idea is to use another theme with WP 4.0.
- The topic ‘Get content type post and display within a page template’ is closed to new replies.