¿Necesito las etiquetas 'html' y 'cuerpo' en una plantilla de página de WordPress?

I'm creating a Page Template for a Sitio de WordPress.

In the file newpagetemplate.php I currently have this code, and this code only:

Template Name: Salespage
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <?php the_title(); ?>
        <?php the_content(); ?> 
    <?php endwhile; endif; ?>

I'll need to make amendments, to set values for margins, fonts etc.

In the above code, do I need the 'html' and 'body' tags?

(If I take those tags out, a page with this page template applied still displays ok.)

preguntado el 31 de julio de 12 a las 15:07

It MAY be displayed fine...one some browsers, not all. Best to stick with proper standards. -

@Diodeus - an HTML page without those tags follows the standards just fine. There is nothing at all non-standard about omitting those tags. -

@Diodeus, that's nonsense. Doing one does not mean you are doing the other. You're just trying to find a way to justify your misconceptions. -

I think almost everyone here has completely misunderstood the question. I think this is “help me build my WP theme”. I'm fairly certain this isn't a scientific “Regardless of best practice, will this render properly?” type of question. -

5 Respuestas

I don't know why you're receiving so many theoretical answers. That to me seems like an uninteresting waste of time.

La respuesta simple es No.

From the code you provided, it looks as though you're trying to build a custom Wordpress theme. You'll want to place the doctype and opening html/body tags in header.php, and close those tags in footer.php. You then pull in the header and footer templates from your ‘Salespage’ template. It may look a little something like this:

// header.php

<!DOCTYPE html>
    <title>Your Title</title>

    <?php wp_head(); ?>

// newpagetemplate.php

<?php get_header(); ?>

<div class="yourContent">
    <?php if (have_posts()) : ?>
        <?php while (have_posts()) : the_post(); ?>
            <?php the_title(); ?>
            <?php the_content(); ?> 
        <?php endwhile; ?> 
    <?php endif; ?>

<?php get_footer(); ?>

// footer.php

<?php wp_footer(); ?>

Respondido 31 Jul 12, 16:07

+1 for actually understanding what he was asking about. Good explanation on how the structure should look like as well. - Bonio

This is the exact answer. All others are giving answer regarding an HTML page. +1 :) - Libin

Si hablas de un Página template and not a Página web template, then you do not need to have the html or body tags within the page template itself since it will be wrapped within the Página web plantilla.

Respondido 31 Jul 12, 15:07

prueba este

if you have use wordpress and create new template page

then you code is below

This is new page templates "Salespage"

        <div id="container" class="one-column">
            <div id="content">


            /* Run the loop to output the page.
             * If you want to overload this in a child theme then include a file
             * called loop-page.php and that will be used instead.

             get_template_part( 'loop', 'salespage' );

            </div><!-- #content -->
        </div><!-- #container -->

<?php get_footer(); ?>

// and you loop page is loop-salespage.php

and your code is

 * The loop that displays a page.
 * The loop displays the posts and the post content.  See
 * http://codex.wordpress.org/The_Loop to understand it and
 * http://codex.wordpress.org/Template_Tags to understand
 * the tags used in it.
 * This can be overridden in child themes with loop-page.php.
 * @package WordPress
 * @subpackage Twenty_Ten
 * @since Twenty Ten 1.2

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

                <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <?php if ( is_front_page() ) { ?>
                        <h2 class="entry-title"><?php the_title(); ?></h2>
                    <?php } else { ?>
                        <h1 class="entry-title"><?php the_title(); ?></h1>
                    <?php } ?>

                    <div class="entry-content">
                        <?php the_content(); ?>
                        <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
                        <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
                    </div><!-- .entry-content -->
                </div><!-- #post-## -->

                <?php //comments_template( '', true ); ?>

<?php endwhile; // end of the loop. ?>

Respondido 31 Jul 12, 15:07

Yes, you still need the <html> y <body> tags, since your page is rendered as HTML. All valid HTML includes these tags. Also don't forget to add <!DOCTYPE html> at the top of the page, again for valid HTML, and to avoid triggering what is called quirksmode on newer browsers. This is usually triggered as a preventative measure due to poorly structured HTML, and often easy for a developer to correct. ;)

Respondido 31 Jul 12, 15:07

Wrong: The only HTML tag that is required to be present in the text of all pages is title. - williham totland

Wrong, both of you. @spryno724: The <html> y <body> tags should not be in the code snippet that Richard provided. @Williham Totland: What technically will be understood by a browser is irrelevant. It's pretty obvious that isn't what Richard is asking. - Jezén Thomas

@JezenThomas: No, the standard explicitly marks body and head as optional, and tells implementers how to deal with them not being there. The only tag that is required in any and all HTML documents is title. Browsers that don't treat the head and body elements as always being present and containing the correct elements are non-conformant. - williham totland

@WillihamTotland: Did you read what I wrote? I said it's “irrelevant”. Did you read the original question? It has nothing to do with the point you're arguing. In all seriousness... Did you read cualquier cosa?! - Jezén Thomas

@JezenThomas, it's not irrelevant. The tags are there with the intent that they make it into the final output. If the tags aren't needed in the final output, they aren't needed full stop. Thus whether they are necessary in the final output is completely relevant. - Jim

No. The opening and closing tags for the <html> y <body> element types are optional. If the browser doesn't see them, they are implied.

Here is the definition for the <html> tipo de elemento. Note that both start and end tags are optional.

Here is the definition for the <body> tipo de elemento. Note that both start and end tags are optional.

Respondido 31 Jul 12, 15:07

They are implied, but are not considered valid HTML without them, and should always be included. - Oliver Spryn

@spryno724, that's simply not true. Check in a validator yourself. - Jim

@WillihamTotland True, although it may pass the validator, I believe standards and best practices truly govern how HTML documents should be structured. All "good" and well formed HTML includes these tags. - Oliver Spryn

@spryno724, again, that's simply not true. There is nothing non-standard or malformed about omitting those tags. - Jim

@spryno724: The validator tells you if a document is structured according to the standards. If a document passes validation, it is, by the very definition of it, well formed. - williham totland

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.