1 . sayfa (Toplam 1 sayfa)
etiket yayınlama eklentisi
Gönderilme zamanı: Sal Şub 18, 2025 12:23 pm
gönderen muratca61
WORDPRESS uygulaması yapalım uygulama ile kullanıcı admin panelinden ekleme çıkarma yapacak. eklediği her satırda aktif onay kutusu olsun. 3 tane de tet box olsun. bunlardan birisi eklenecek etiket olacak diğer textbox bu etiketin hangi kategorilerde yayınlanacağı virgüllü olarak girilecek. son textbox da ise bu etiketin hangi etiket içeren yazıların altına ekleneceği yine virgülle belirlensin. buradaa girilen etiket girilen kategori veya kategorilerde yazının en altında yayınlanacak. veya belirtilen etiketlerin geçtiği sayfalarda yayınlanacak
Re: etiket yayınlama eklentisi
Gönderilme zamanı: Sal Şub 18, 2025 12:23 pm
gönderen muratca61
Kod:Tümünü seç Kopyala
<?php
/*
Plugin Name: Custom Tag Inserter
Description: Yazılara, belirlenen kategori veya etiketlere göre özel etiket ekler.
Version: 1.0
Author: Örnek Yazar
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Direkt erişim engellensin.
}
class CustomTagInserter {
private $option_name = 'cti_rules';
public function __construct() {
// Yönetici menüsüne ekle
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
// Ayar kaydetme işlemleri için
add_action( 'admin_init', array( $this, 'admin_init' ) );
// Yazı içeriğine etiket ekleme
add_filter( 'the_content', array( $this, 'append_custom_tag' ) );
}
// Yönetici menüsüne eklenti sayfası ekleme
public function add_admin_menu() {
add_menu_page(
'Custom Tag Inserter',
'Tag Inserter',
'manage_options',
'custom-tag-inserter',
array( $this, 'settings_page' ),
'dashicons-tag'
);
}
// Ayarların kaydedilebilmesi için
public function admin_init() {
register_setting( 'cti_settings_group', $this->option_name );
}
// Yönetici panelindeki ayar sayfası
public function settings_page() {
// Form gönderildiyse ayarları güncelleyelim.
if ( isset( $_POST['cti_rules'] ) ) {
check_admin_referer( 'cti_update', 'cti_nonce' );
update_option( $this->option_name, $_POST['cti_rules'] );
echo '<div class="updated"><p>Ayarlar kaydedildi.</p></div>';
}
$rules = get_option( $this->option_name, array() );
?>
<div class="wrap">
<h1>Custom Tag Inserter Ayarları</h1>
<form method="post">
<?php wp_nonce_field( 'cti_update', 'cti_nonce' ); ?>
<table class="widefat">
<thead>
<tr>
<th>Aktif</th>
<th>Eklenecek Etiket</th>
<th>Kategoriler (virgülle ayrılmış)</th>
<th>Etiket içeren yazılar (virgülle ayrılmış)</th>
<th>İşlem</th>
</tr>
</thead>
<tbody id="cti_rules_tbody">
<?php
if ( ! empty( $rules ) ) {
foreach ( $rules as $index => $rule ) {
?>
<tr>
<td>
<input type="checkbox" name="cti_rules[<?php echo $index; ?>][active]" value="1" <?php checked( 1, isset( $rule['active'] ) ? $rule['active'] : 0 ); ?> />
</td>
<td>
<input type="text" name="cti_rules[<?php echo $index; ?>][tag]" value="<?php echo esc_attr( $rule['tag'] ); ?>" />
</td>
<td>
<input type="text" name="cti_rules[<?php echo $index; ?>][categories]" value="<?php echo esc_attr( $rule['categories'] ); ?>" />
</td>
<td>
<input type="text" name="cti_rules[<?php echo $index; ?>][post_tags]" value="<?php echo esc_attr( $rule['post_tags'] ); ?>" />
</td>
<td>
<a href="#" class="cti_remove_rule">Sil</a>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<p>
<a href="#" id="cti_add_rule" class="button">Yeni Kural Ekle</a>
</p>
<?php submit_button(); ?>
</form>
</div>
<script>
(function($) {
$(document).ready(function(){
var index = <?php echo count( $rules ); ?>;
// Yeni kural ekleme
$('#cti_add_rule').click(function(e){
e.preventDefault();
var newRow = '<tr>'+
'<td><input type="checkbox" name="cti_rules['+index+'][active]" value="1" /></td>'+
'<td><input type="text" name="cti_rules['+index+'][tag]" value="" /></td>'+
'<td><input type="text" name="cti_rules['+index+'][categories]" value="" /></td>'+
'<td><input type="text" name="cti_rules['+index+'][post_tags]" value="" /></td>'+
'<td><a href="#" class="cti_remove_rule">Sil</a></td>'+
'</tr>';
$('#cti_rules_tbody').append(newRow);
index++;
});
// Kural silme işlemi
$(document).on('click', '.cti_remove_rule', function(e){
e.preventDefault();
$(this).closest('tr').remove();
});
});
})(jQuery);
</script>
<?php
}
// Yazı içeriğine, kural geçerliyse ek etiket ekleme
public function append_custom_tag( $content ) {
if ( ! is_singular( 'post' ) ) {
return $content;
}
global $post;
$rules = get_option( $this->option_name, array() );
if ( empty( $rules ) ) {
return $content;
}
$append = '';
foreach ( $rules as $rule ) {
// Kuralın aktif olduğundan emin olalım
if ( empty( $rule['active'] ) ) {
continue;
}
$tag = trim( $rule['tag'] );
if ( ! $tag ) {
continue;
}
// Virgülle ayrılmış kategoriler ve etiketleri diziye çevirelim
$rule_categories = array_filter( array_map( 'trim', explode( ',', $rule['categories'] ) ) );
$rule_post_tags = array_filter( array_map( 'trim', explode( ',', $rule['post_tags'] ) ) );
$match = false;
// Yazının kategorileri ile kontrol
if ( ! empty( $rule_categories ) ) {
$post_categories = wp_get_post_categories( $post->ID, array( 'fields' => 'names' ) );
if ( array_intersect( $rule_categories, $post_categories ) ) {
$match = true;
}
}
// Eğer kategori eşleşmediyse, yazı etiketleri ile kontrol edelim
if ( ! $match && ! empty( $rule_post_tags ) ) {
$post_tags = wp_get_post_tags( $post->ID, array( 'fields' => 'names' ) );
if ( array_intersect( $rule_post_tags, $post_tags ) ) {
$match = true;
}
}
// Eşleşme varsa, etiketi ekle
if ( $match ) {
$append .= '<div class="custom-tag" style="margin-top:20px;">'.esc_html( $tag ).'</div>';
}
}
return $content . $append;
}
}
new CustomTagInserter();
Re: etiket yayınlama eklentisi
Gönderilme zamanı: Sal Şub 18, 2025 3:01 pm
gönderen muratca61
tek satır ekleme sorunu yenisinin eskisini silme sorunu giderilmişmiş
Kod:Tümünü seç Kopyala
<?php
/*
Plugin Name: Custom Tag Inserter
Description: Yazılara, belirlenen kategori veya etiketlere göre özel etiket ekler.
Version: 1.0
Author: Örnek Yazar
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Direkt erişim engellensin.
}
class CustomTagInserter {
private $option_name = 'cti_rules';
public function __construct() {
// Yönetici menüsüne ekle
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
// Ayar kaydetme işlemleri için
add_action( 'admin_init', array( $this, 'admin_init' ) );
// Yazı içeriğine etiket ekleme
add_filter( 'the_content', array( $this, 'append_custom_tag' ) );
}
// Yönetici menüsüne eklenti sayfası ekleme
public function add_admin_menu() {
add_menu_page(
'Custom Tag Inserter',
'Tag Inserter',
'manage_options',
'custom-tag-inserter',
array( $this, 'settings_page' ),
'dashicons-tag'
);
}
// Ayarların kaydedilebilmesi için
public function admin_init() {
register_setting( 'cti_settings_group', $this->option_name );
}
// Yönetici panelindeki ayar sayfası
public function settings_page() {
// Form gönderildiyse ayarları güncelleyelim.
if ( isset( $_POST['cti_rules'] ) ) {
check_admin_referer( 'cti_update', 'cti_nonce' );
update_option( $this->option_name, $_POST['cti_rules'] );
echo '<div class="updated"><p>Ayarlar kaydedildi.</p></div>';
}
$rules = get_option( $this->option_name, array() );
?>
<div class="wrap">
<h1>Custom Tag Inserter Ayarları</h1>
<form method="post">
<?php wp_nonce_field( 'cti_update', 'cti_nonce' ); ?>
<table class="widefat">
<thead>
<tr>
<th>Aktif</th>
<th>Eklenecek Etiket</th>
<th>Kategoriler (virgülle ayrılmış)</th>
<th>Etiket içeren yazılar (virgülle ayrılmış)</th>
<th>İşlem</th>
</tr>
</thead>
<tbody id="cti_rules_tbody">
<?php
if ( ! empty( $rules ) ) {
foreach ( $rules as $index => $rule ) {
?>
<tr>
<td>
<input type="checkbox" name="cti_rules[<?php echo $index; ?>][active]" value="1" <?php checked( 1, isset( $rule['active'] ) ? $rule['active'] : 0 ); ?> />
</td>
<td>
<input type="text" name="cti_rules[<?php echo $index; ?>][tag]" value="<?php echo esc_attr( $rule['tag'] ); ?>" />
</td>
<td>
<input type="text" name="cti_rules[<?php echo $index; ?>][categories]" value="<?php echo esc_attr( $rule['categories'] ); ?>" />
</td>
<td>
<input type="text" name="cti_rules[<?php echo $index; ?>][post_tags]" value="<?php echo esc_attr( $rule['post_tags'] ); ?>" />
</td>
<td>
<a href="#" class="cti_remove_rule">Sil</a>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<p>
<a href="#" id="cti_add_rule" class="button">Yeni Kural Ekle</a>
</p>
<?php submit_button(); ?>
</form>
</div>
<script>
(function($) {
$(document).ready(function(){
// Mevcut satır sayısına göre index değerini belirle
var index = $('#cti_rules_tbody tr').length;
// Yeni kural ekleme
$('#cti_add_rule').click(function(e){
e.preventDefault();
var newRow = '<tr>'+
'<td><input type="checkbox" name="cti_rules['+index+'][active]" value="1" /></td>'+
'<td><input type="text" name="cti_rules['+index+'][tag]" value="" /></td>'+
'<td><input type="text" name="cti_rules['+index+'][categories]" value="" /></td>'+
'<td><input type="text" name="cti_rules['+index+'][post_tags]" value="" /></td>'+
'<td><a href="#" class="cti_remove_rule">Sil</a></td>'+
'</tr>';
$('#cti_rules_tbody').append(newRow);
index++; // Her eklemede index'i artırıyoruz
});
// Kural silme işlemi
$(document).on('click', '.cti_remove_rule', function(e){
e.preventDefault();
$(this).closest('tr').remove();
});
});
})(jQuery);
</script>
<?php
}
// Yazı içeriğine, kural geçerliyse ek etiket ekleme
public function append_custom_tag( $content ) {
if ( ! is_singular( 'post' ) ) {
return $content;
}
global $post;
$rules = get_option( $this->option_name, array() );
if ( empty( $rules ) ) {
return $content;
}
$append = '';
foreach ( $rules as $rule ) {
// Kuralın aktif olduğundan emin olalım
if ( empty( $rule['active'] ) ) {
continue;
}
$tag = trim( $rule['tag'] );
if ( ! $tag ) {
continue;
}
// Virgülle ayrılmış kategoriler ve etiketleri diziye çevirelim
$rule_categories = array_filter( array_map( 'trim', explode( ',', $rule['categories'] ) ) );
$rule_post_tags = array_filter( array_map( 'trim', explode( ',', $rule['post_tags'] ) ) );
$match = false;
// Yazının kategorileri ile kontrol
if ( ! empty( $rule_categories ) ) {
$post_categories = wp_get_post_categories( $post->ID, array( 'fields' => 'names' ) );
if ( array_intersect( $rule_categories, $post_categories ) ) {
$match = true;
}
}
// Eğer kategori eşleşmediyse, yazı etiketleri ile kontrol edelim
if ( ! $match && ! empty( $rule_post_tags ) ) {
$post_tags = wp_get_post_tags( $post->ID, array( 'fields' => 'names' ) );
if ( array_intersect( $rule_post_tags, $post_tags ) ) {
$match = true;
}
}
// Eşleşme varsa, etiketi ekle
if ( $match ) {
$append .= '<div class="custom-tag" style="margin-top:20px;">'.esc_html( $tag ).'</div>';
}
}
return $content . $append;
}
}
new CustomTagInserter();
Re: etiket yayınlama eklentisi
Gönderilme zamanı: Sal Şub 18, 2025 3:08 pm
gönderen muratca61
olmadı tekrar denendi
bu olduuuuuuuuu
Kod:Tümünü seç Kopyala
<?php
/*
Plugin Name: Custom Tag Inserter
Description: Yazılara, belirlenen kategori veya etiketlere göre özel etiket ekler.
Version: 1.0
Author: Örnek Yazar
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Direkt erişim engellensin.
}
class CustomTagInserter {
private $option_name = 'cti_rules';
public function __construct() {
// Yönetici menüsüne ekle
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
// Ayar kaydetme işlemleri için
add_action( 'admin_init', array( $this, 'admin_init' ) );
// Yazı içeriğine etiket ekleme
add_filter( 'the_content', array( $this, 'append_custom_tag' ) );
}
// Yönetici menüsüne eklenti sayfası ekleme
public function add_admin_menu() {
add_menu_page(
'Custom Tag Inserter',
'Tag Inserter',
'manage_options',
'custom-tag-inserter',
array( $this, 'settings_page' ),
'dashicons-tag'
);
}
// Ayarların kaydedilebilmesi için
public function admin_init() {
register_setting( 'cti_settings_group', $this->option_name );
}
// Yönetici panelindeki ayar sayfası
public function settings_page() {
// Form gönderildiyse ayarları güncelleyelim.
if ( isset( $_POST['cti_rules'] ) ) {
check_admin_referer( 'cti_update', 'cti_nonce' );
update_option( $this->option_name, $_POST['cti_rules'] );
echo '<div class="updated"><p>Ayarlar kaydedildi.</p></div>';
}
$rules = get_option( $this->option_name, array() );
?>
<div class="wrap">
<h1>Custom Tag Inserter Ayarları</h1>
<form method="post">
<?php wp_nonce_field( 'cti_update', 'cti_nonce' ); ?>
<table class="widefat">
<thead>
<tr>
<th>Aktif</th>
<th>Eklenecek Etiket</th>
<th>Kategoriler (virgülle ayrılmış)</th>
<th>Etiket içeren yazılar (virgülle ayrılmış)</th>
<th>İşlem</th>
</tr>
</thead>
<tbody id="cti_rules_tbody">
<?php
if ( ! empty( $rules ) ) {
foreach ( $rules as $index => $rule ) {
?>
<tr>
<td>
<input type="checkbox" name="cti_rules[<?php echo $index; ?>][active]" value="1" <?php checked( 1, isset( $rule['active'] ) ? $rule['active'] : 0 ); ?> />
</td>
<td>
<input type="text" name="cti_rules[<?php echo $index; ?>][tag]" value="<?php echo esc_attr( $rule['tag'] ); ?>" />
</td>
<td>
<input type="text" name="cti_rules[<?php echo $index; ?>][categories]" value="<?php echo esc_attr( $rule['categories'] ); ?>" />
</td>
<td>
<input type="text" name="cti_rules[<?php echo $index; ?>][post_tags]" value="<?php echo esc_attr( $rule['post_tags'] ); ?>" />
</td>
<td>
<a href="#" class="cti_remove_rule">Sil</a>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<p>
<a href="#" id="cti_add_rule" class="button">Yeni Kural Ekle</a>
</p>
<?php submit_button(); ?>
</form>
</div>
<script>
(function($) {
$(document).ready(function(){
// Mevcut satır sayısına göre index değerini belirle
var ruleIndex = $('#cti_rules_tbody tr').length;
// Yeni kural ekleme
$('#cti_add_rule').click(function(e){
e.preventDefault();
var newRow = '<tr>'+
'<td><input type="checkbox" name="cti_rules['+ruleIndex+'][active]" value="1" /></td>'+
'<td><input type="text" name="cti_rules['+ruleIndex+'][tag]" value="" /></td>'+
'<td><input type="text" name="cti_rules['+ruleIndex+'][categories]" value="" /></td>'+
'<td><input type="text" name="cti_rules['+ruleIndex+'][post_tags]" value="" /></td>'+
'<td><a href="#" class="cti_remove_rule">Sil</a></td>'+
'</tr>';
$('#cti_rules_tbody').append(newRow);
ruleIndex++; // Her eklemede index'i artırıyoruz
});
// Kural silme işlemi
$(document).on('click', '.cti_remove_rule', function(e){
e.preventDefault();
$(this).closest('tr').remove();
});
// Form gönderilmeden önce satırları yeniden indeksle
$('form').submit(function(){
$('#cti_rules_tbody tr').each(function(index){
$(this).find('input').each(function(){
var name = $(this).attr('name');
// Mevcut index değerini yeni index ile değiştir
name = name.replace(/cti_rules\[\d+\]/, 'cti_rules['+index+']');
$(this).attr('name', name);
});
});
});
});
})(jQuery);
</script>
<?php
}
// Yazı içeriğine, kural geçerliyse ek etiket ekleme
public function append_custom_tag( $content ) {
if ( ! is_singular( 'post' ) ) {
return $content;
}
global $post;
$rules = get_option( $this->option_name, array() );
if ( empty( $rules ) ) {
return $content;
}
$append = '';
foreach ( $rules as $rule ) {
// Kuralın aktif olduğundan emin olalım
if ( empty( $rule['active'] ) ) {
continue;
}
$tag = trim( $rule['tag'] );
if ( ! $tag ) {
continue;
}
// Virgülle ayrılmış kategoriler ve etiketleri diziye çevirelim
$rule_categories = array_filter( array_map( 'trim', explode( ',', $rule['categories'] ) ) );
$rule_post_tags = array_filter( array_map( 'trim', explode( ',', $rule['post_tags'] ) ) );
$match = false;
// Yazının kategorileri ile kontrol
if ( ! empty( $rule_categories ) ) {
$post_categories = wp_get_post_categories( $post->ID, array( 'fields' => 'names' ) );
if ( array_intersect( $rule_categories, $post_categories ) ) {
$match = true;
}
}
// Eğer kategori eşleşmediyse, yazı etiketleri ile kontrol edelim
if ( ! $match && ! empty( $rule_post_tags ) ) {
$post_tags = wp_get_post_tags( $post->ID, array( 'fields' => 'names' ) );
if ( array_intersect( $rule_post_tags, $post_tags ) ) {
$match = true;
}
}
// Eşleşme varsa, etiketi ekle
if ( $match ) {
$append .= '<div class="custom-tag" style="margin-top:20px;">'.esc_html( $tag ).'</div>';
}
}
return $content . $append;
}
}
new CustomTagInserter();