23 Kasım 2015 Pazartesi

Php cookie

Örnek:
1
2
3
4
5
6
7
<?php
 
setcookie("celal","1234",time()+3600);
 
echo $_COOKIE["celal"];
 
?>
Üstteki örnekte setcookie komutu ile celal isimli bir cookie oluşturduk. Cookie’nin değerini 1234 olarak tanımladık. Zaman aşımı olarak time() fonksiyonunu kullandık ve 3600 sn. yani 1 saat geçerli olacak şekilde belirttik. Son olarak echo komutu ile celal isimli cookie’nin değerini ekrana yazdırdık. Bu örneği test ettiğinizde ekrandaki çıktı 1234 olacaktır.
Cookie’nin tanımlı olup olmadığını kontrol etmek için isset() fonksiyonunu kullanabilirsiniz.
Örnek:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
 
if(isset($_COOKIE["celal"]))
{
echo "cookie tanımlanmış";
}
 
else
{
echo "cookie tanımlanmamış!";
}
 
?>
Cookie silme işlemi.
Örnek:
1
2
3
4
5
<?php
 
setcookie ("celal", "", time() - 3600);
 
?>
celal isimli cookie’nin değerini boş olarak ayarladık ve -3600 ile geçerliliğini yitirmesini sağladık.

22 Kasım 2015 Pazar

wiget oluşturma 2

1
2
3
4
5
6
7
8
9
10
11
<?php
if ( function_exists('register_sidebar') ) {
    register_sidebar(array(
        'name' => 'Sidebar Alani',
        'before_widget' => '<div class="sidebar-widget wide-widget">',
        'after_widget' => '</div>',
        'before_title' => '<h3 class="sidebar-widget-title">',
        'after_title' => '</h3>',
    ));
}
?>
Üstteki kodu functions.php sayfasına koyduktan sonra kaydet butonuna basabilirsiniz.
Devamında ise aşağıda vereceğim kodu, sidebar.php, single.php vs.. bileşenin nerede görünmesini istiyorsanız oraya koymanız gerekiyor.
1
2
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar Alani') ) : ?>
<?php endif; ?>
Hepsi bukadar artık bileşen destekli bir 

wiget oluşturma

<?php
$args = array(
    'name'          => 'Sidebar 1',
    'id'            => 'sidebar-1',
    'description'   => '',
    'before_widget' => '<div id="%1$s" class="BlockContent %2$s">',
    'after_widget'  => '</div>',
    'before_title'  => '<h2 class="widgettitle">',
    'after_title'   => '</h2>' );
if ( function_exists('register_sidebar') ) register_sidebar($args);
?>
<?php
$args = array(
    'name'          => 'Sidebar 2',
    'id'            => 'sidebar-2',
    'description'   => '',
    'before_widget' => '<div id="%1$s" class="BlockContent %2$s">',
    'after_widget'  => '</div>',
    'before_title'  => '<h2 class="widgettitle">',
    'after_title'   => '</h2>' );
if ( function_exists('register_sidebar') ) register_sidebar($args);
?>
in your 'old' sidebar.php, try:
<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(1) ) : else : ?>
and in sidebar-right.php, try:
<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(2) ) : else : ?>

u leave the existing line as it is,
and add a new
<?php get_sidebar('right'); ?>