Skip to content

Instantly share code, notes, and snippets.

// Doğru kullanım
$foo = array(
'echo' => false,
'include' => 1,
);
$bar = esc_html__( 'Test Yazı', 'text-domain' );
test_fonksiyon( $foo, $bar );
// Yanlış kullanım
test_fonksiyon( array( echo => false, include => 1 ), esc_html__( 'Test Yazı', 'text-domain' ) );
// Doğru kullanım
$args = array(
'echo' => false,
'include' => array( 1, 2 ),
);
// Yanlış kullanım
$args = [
'echo' => false,
'include' => [ 1, 2 ],
<?php if ( have_posts() ) : ?>
<div class="hfeed">
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID() ?>" class="<?php post_class() ?>">
<!-- ... -->
</article>
<?php endwhile; ?>
</div>
<?php endif; ?>
// Doğru kullanım
if( condition ) {
action1();
action2();
} elseif( condition2 && condition3 ) {
action3();
action4();
} else {
defaultaction();
}
switch( $type ) {
case 'foo':
some_function();
break;
case 'bar':
some_function();
break;
}
// Doğru kullanım
$args = array(
'post_type' => 'page',
'post_author' => 123,
'post_status' => 'publish',
);
// Yanlış kullanım
$args = array(
'post_type' => 'page',
// Tek ögeli dizi için tek satır kullanılmalı.
$query = new WP_Query( array( 'ID' => 123 ) );
// Birden fazla ögeli dizilerde $args gibi değişkene atanarak
// her bir öge için ayrı satır oluşturulmalı.
$args = array(
'post_type' => 'page',
'post_author' => 123,
'post_status' => 'publish',
);
// foreach için örnek
foreach( $items as $item ) {
echo $item[ 'title' ];
echo $item[ 'url' ];
echo $item[ 'description' ];
}
// if else için örnek
if( have_posts() ) {
echo 'Yazı Bulundu!';
echo '<a href="' . esc_attr( $link ) . '">Test</a>';
// Burada herangi bir değişken olmadığı için tek tırnak kullandık.
echo '<a href="#test">Test</a>';
// Değişken kullanmak istiyorsanız çift tırnak kullanın.
echo "<a href='$link'>Test</a>";