Keep related stuff together.
Keep unrelated stuff apart.
Typical HTML layout:
<html> <head> ... </head> <body <?php body_class(); ?>> <div id="page"> <header id="branding" role="banner"> ... </header><!-- #branding --> <div id="main">
</div><!-- #main --> <footer id="colophon" role="contentinfo"> ... </footer><!-- #colophon --> </div><!-- #page --> <?php wp_footer(); ?> </body> </html>
<?php get_header(); ?> <div id="primary"> <div id="content" role="main"> ... </div><!-- #content --> </div><!-- #primary --> <?php get_sidebar(); ?> <?php get_footer(); ?>
<html> <head> ... </head> <body <?php body_class(); ?>> <div id="page"> <?php get_header(); ?> <div id="main"> <?php include app_template_path(); ?> </div><!-- #main --> <?php get_footer(); ?> </div><!-- #page --> <?php wp_footer(); ?> </body> </html>
<header id="branding" role="banner"> ... </header><!-- #branding -->
<footer id="colophon" role="contentinfo"> ... </footer><!-- #colophon -->
<div id="primary"> <div id="content" role="main"> ... </div><!-- #content --> </div><!-- #primary --> <?php get_sidebar(); ?>
Typical PHP layout:
add_filter( 'posts_where', 'my_posts_where', 10, 2 ); add_action( 'template_redirect', 'my_template_redirect', 10, 2 ); function my_posts_where( $sql, $wp_query ) { if ( $wp_query->is_main_query() && $wp_query->get( 'my_query_var' ) ) { $sql = ...; } return $sql; } function my_template_redirect() { global $wp_query; if ( $wp_query->is_main_query() && $wp_query->get( 'my_query_var' ) ) { wp_enqueue_script( ... ); } }
class My_View { function __construct() { add_filter( 'posts_where', array( $this, 'posts_where' ), 10, 2 ); add_action( 'template_redirect', array( $this, 'template_redirect' ), 10, 2 ); } function posts_where( $sql, $wp_query ) { if ( $wp_query->is_main_query() && $wp_query->get( 'my_query_var' ) ) { $sql = ...; } return $sql; } function template_redirect() { global $wp_query; if ( $wp_query->is_main_query() && $wp_query->get( 'my_query_var' ) ) { wp_enqueue_script( ... ); } } } new My_View;
class My_View extends APP_View { function condition() { return get_query_var( 'my_query_var' ); } function posts_where( $sql, $wp_query ) { $sql = ...; return $sql; } function template_redirect() { wp_enqueue_script( ... ); } } new My_View;
contact |
|
site: | scribu.net |
twitter+github: | @scribu |
/
#