Wordpress kategori adı ve açıklamalarında değişken kullanmak
9
●256
- 02-09-2019, 00:02:24Merhaba benim epey bir kategorim var bin üstü diyelim ben bu kategorilerimin 900'ünün sonuna bir tarih eklemek istiyorum atıyorum 2019, 2020'ye geçince de 2020 tarihini ekleyeceğim. Ve bunu tek tek yapmak yerine functions.php ya da benzeri bir dosyada tanımlama yaptırsam kategori sonuna %%yil%% vb. bir şey eklediğimde. funtcions.php de %%yill%% karşılığını ne yaparsam o çıksın gibi bir şey istiyorum. Bu durumu kategori açıklamaları için de yapmak istiyorum. Bilen yol yordam gösterebilecek bir arkadaş olursa minnettar olurum. Teşekkürler.
- 02-09-2019, 10:21:56get_the_archive_title() fonksiyonuna filtre ekleyerek yapabilirsiniz.
function kategori_title_degister( $title ) { $son_ek = 'test'; // Sonuna eklenmesini istediğiniz metni tırnak içerisine yazın. $title = $title . ' ' . $son_ek; return $title; } add_filter( 'get_the_archive_title', 'kategori_title_degister' );Detaylı bilgi için buraya bakın. - 02-09-2019, 12:49:50Hocam öncelikle teşekkürler. Dediğiniz gibi functions.php'ye attım kodu .Test yerine eklenecek yılı da yazdım fakat kategori isimlerinde bir değişiklik olmadı hocam. Ek olarak ben tüm kategorilerin ismini değil istediğim kategorilerin adının sonuna ve kategori açıklamalarına bir tarih değişkeni eklemek istiyorum.bilimokur adlı üyeden alıntı: mesajı görüntüle
- 02-09-2019, 12:58:44İşe yaraması için category.php veya archive.php dosyalarında kategori adının the_category() veya get_the_category() şekline çağrılmış olması lazım.
Belirli kategoriler için de şu şekilde yapabilirsiniz.
function kategori_title_degister( $title ) { $son_ek = ''; if( is_category( 2 ) ) { // 2 yerine gösterilecek kategori ID'si yazılacak. $son_ek = 'ID si 2 olan kategori'; } if( is_category( 3 ) ) { // 3 yerine gösterilecek kategori ID'si yazılacak. $son_ek = 'ID si 3 olan kategori'; } $title = $title . ' ' . $son_ek; return $title; } add_filter( 'get_the_archive_title', 'kategori_title_degister' );Açılama sonuna eklemek için de şunu yapabilirsiniz.
function kategori_aciklama_degistir( $description ) { $son_ek = ''; if( is_category( 2 ) ) { // 2 yerine gösterilecek kategori ID'si yazılacak. $son_ek = 'ID si 2 olan kategori'; } if( is_category( 3 ) ) { // 3 yerine gösterilecek kategori ID'si yazılacak. $son_ek = 'ID si 3 olan kategori'; } $description = $description . ' ' . $son_ek; return $description; } add_filter( 'get_the_archive_description', 'kategori_aciklama_degistir', 10, 1 );Tabi bunun da işe yaraması için archive veya category.php dosyasında kategori açıklamasının the_archive_description() fonksiyonu ile çağrılmış olması gerekiyor. Kullandığınız tema nedir? - 02-09-2019, 14:32:55theme junkie teması olan daily temasını kullanıyorum hocam. category.php'de <?php echo category_description(); ?> şeklinde çağrılmış hocam. Hocam id girme durumunda bin üstü kategoriyi tek tek girmem gerekecek. Benim istediğim:
Kategori başlığı: http://prntscr.com/p0p40j bu şekilde bir şey hocam.
Kategori açıklaması için de böyle hocam.: http://prntscr.com/p0p4vf - 02-09-2019, 15:15:02O zaman şu şekilde yapabilirsiniz.
function kategori_title_degister( $title ) { $bul = '%%yil%%'; $degistir = 'test'; $title = str_replace( $bul, $degistir, $title ); return $title; } add_filter( 'get_the_archive_title', 'kategori_title_degister' );function kategori_aciklama_degistir( $description ) { $bul = '%%yil%%'; $degistir = 'test'; $description = str_replace( $bul, $degistir, $description ); return $description; } add_filter( 'get_the_archive_description', 'kategori_aciklama_degistir' );Fakat yukarıda belirttiğim gibi başlığı the_archive_title() açıklamayı da the_archive_description() fonksiyonu ile çağırmalısınız. Zaten doğru olan da bu. - 02-09-2019, 15:40:30Olmadı hocam maalesef. Kod bu category.php
<?php get_header(); ?> <?php $category = get_category( get_query_var( 'cat' ), false ); $layout = get_tax_meta( $category->term_id, 'daily_cat_layout', false ); if ( empty( $layout ) ) { $layout = 'classic'; } ?> <section id="primary" class="content-area column"> <?php get_template_part( 'content', 'featured' ); ?> <?php if ( of_get_option( 'daily_archive_ads' ) ) : ?> <div class="archive-ad"> <?php echo stripslashes( of_get_option( 'daily_archive_ads' ) ); ?> </div> <?php endif; ?> <main id="main" class="content-loop category-box <?php echo esc_attr( daily_archive_page_classes() ); ?> column" role="main" <?php hybrid_attr( 'content' ); ?>> <?php if ( have_posts() ) : ?> <header class="page-header"> <h3 class="widget-title"><strong><?php single_cat_title( __( 'daily' ) ); ?></strong></h3> </header><!-- .page-header --> <div class="wpu-desc"> <?php echo category_description(); ?> </div> <?php $cur_cat = get_query_var('cat'); if ( has_term_have_children( get_queried_object_id() ) ) : $new_cats = wp_list_categories('echo=0&child_of=' . $cur_cat .'&depth=1&title_li=&&show_count=0&hide_empty=0'); echo '<ul class="wpu-subcategory">' . $new_cats . '</ul>'; endif; ?> <?php /* Start the Loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php if ( 'standard' === $layout ) : ?> <?php get_template_part( 'content', get_post_format() ); ?> <?php elseif ( 'classic' === $layout ) : ?> <?php get_template_part( 'content', 'classic' ); ?> <?php elseif ( 'grid' === $layout ) : ?> <?php get_template_part( 'content', 'grid' ); ?> <?php endif; ?> <?php endwhile; ?> <div class="clearfix"></div> <?php get_template_part( 'loop', 'nav' ); // Loads the loop-nav.php template ?> <?php else : ?> <?php get_template_part( 'content', 'none' ); ?> <?php endif; ?> </main><!-- #main --> <?php get_sidebar( 'secondary' ); ?> </section><!-- #primary --> <?php get_sidebar(); ?> <?php get_footer(); ?>Kod yapısı farklı belki de bilemiyorum hocam. Uğraştırdım sizi de. - 02-09-2019, 15:49:56
<?php get_header(); ?> <?php $category = get_category( get_query_var( 'cat' ), false ); $layout = get_tax_meta( $category->term_id, 'daily_cat_layout', false ); if( empty( $layout ) ) { $layout = 'classic'; } ?> <section id="primary" class="content-area column"> <?php get_template_part( 'content', 'featured' ); ?> <?php if( of_get_option( 'daily_archive_ads' ) ) : ?> <div class="archive-ad"> <?php echo stripslashes( of_get_option( 'daily_archive_ads' ) ); ?> </div> <?php endif; ?> <main id="main" class="content-loop category-box <?php echo esc_attr( daily_archive_page_classes() ); ?> column" role="main" <?php hybrid_attr( 'content' ); ?>> <?php if( have_posts() ) : ?> <header class="page-header"> <?php the_archive_title( '<h3 class="widget-title"><strong>', '</strong></h3>' ); ?> </header><!-- .page-header --> <div class="wpu-desc"> <?php the_archive_description(); ?> </div> <?php $cur_cat = get_query_var( 'cat' ); if( has_term_have_children( get_queried_object_id() ) ) : $new_cats = wp_list_categories( 'echo=0&child_of=' . $cur_cat . '&depth=1&title_li=&&show_count=0&hide_empty=0' ); echo '<ul class="wpu-subcategory">' . $new_cats . '</ul>'; endif; ?> <?php /* Start the Loop */ ?> <?php while( have_posts() ) : the_post(); ?> <?php if( 'standard' === $layout ) : ?> <?php get_template_part( 'content', get_post_format() ); ?> <?php elseif( 'classic' === $layout ) : ?> <?php get_template_part( 'content', 'classic' ); ?> <?php elseif( 'grid' === $layout ) : ?> <?php get_template_part( 'content', 'grid' ); ?> <?php endif; ?> <?php endwhile; ?> <div class="clearfix"></div> <?php get_template_part( 'loop', 'nav' ); // Loads the loop-nav.php template ?> <?php else : ?> <?php get_template_part( 'content', 'none' ); ?> <?php endif; ?> </main><!-- #main --> <?php get_sidebar( 'secondary' ); ?> </section><!-- #primary --> <?php get_sidebar(); ?> <?php get_footer(); ?>Sayfa böyle olacak aynı zamanda verdiğim kodları kullanacaksınız. - 02-09-2019, 15:57:02Bunu olduğu gibi category.php'deki kodu silip bunu kullandım. functions.php'de sizin kodları ekledim. Değiştirmedi hocam maalesef.

http://prntscr.com/p0qfsb
Sonuç: http://prntscr.com/p0qgt1
