Je débute en PHP, et mon code me parait bien lourd. Prenons ces 2 fonctions (j'en ai 12 au total), et examinons les différences :
Code : Tout sélectionner
function get_my_content_grid_11() {
if ( have_posts() ) :
while ( have_posts() ) : the_post();
$my_current_type_in_use = get_post_type( $post );
echo'<section class="grid-11 ', $my_current_type_in_use, ' primary-section">
<article class="', $my_current_type_in_use, ' primary-section-article">
<header class="', $my_current_type_in_use, ' primary-section-article-header">
<h1 class="', $my_current_type_in_use, ' primary-section-article-header-title">', the_title(), '</h1></header>
<div class="', $my_current_type_in_use, ' primary-section-article-content">', the_content(), '</div>
</header>
</article>';
endwhile;
if ( comments_open() || '0' != get_comments_number() )
echo'<article class="', $my_current_type_in_use, ' primary-section-article-comments">'
, comments_template( '', true );
echo'</article></section>';
endif;
}
function get_my_content_grid_12() {
if ( have_posts() ) :
while ( have_posts() ) : the_post();
$my_current_type_in_use = get_post_type( $post );
echo'<section class="grid-12 ', $my_current_type_in_use, ' primary-section">
<article class="', $my_current_type_in_use, ' primary-section-article">
<header class="', $my_current_type_in_use, ' primary-section-article-header">
<h1 class="', $my_current_type_in_use, ' primary-section-article-header-title">', the_title(), '</h1></header>
<div class="', $my_current_type_in_use, ' primary-section-article-content">', the_content(), '</div>
</header>
</article>';
endwhile;
if ( comments_open() || '0' != get_comments_number() )
echo'<article class="', $my_current_type_in_use, ' primary-section-article-comments">'
, comments_template( '', true );
echo'</article></section>';
endif;
}Code : Tout sélectionner
echo'<section class="grid-12 'Ma question va vous parraitre bête, mais y a-t-il un moyen a base de n+1 qui me permettrait (1) de dynamiquement créer une série de fontions
Code : Tout sélectionner
"get_my_content_grid_n(+1)"Code : Tout sélectionner
<section class="grid-n+1''PS : Joli forum cela dit en passant... c'est propre, clean, et ergonomique