Merhaba,
WP Yazıları içinde nasıl PHP kodu kullanabilirim?
WP Yazı İçinde PHP Kod Kullanma
4
●148
- 18-04-2023, 02:33:17shortcode ile yapabilirsiniz hocam;
örnek shortcode kullanımı
function my_shortcode_func( $atts ) { $atts = shortcode_atts( array( 'my_parameter' => 'default_value', ), $atts ); $param_value = $atts['my_parameter']; // burada yapılacak işlem // ... return $output; } add_shortcode( 'my_shortcode', 'my_shortcode_func' );daha sonra içeriğe [my_shortcode] şeklinde ekleyebilirsiniz dilerseniz. - 18-04-2023, 02:37:28Hocam chatGPT'den veri çekeceğim yeri yazılarda göstermek için shortcode yazmasını istedim. Yazdı ve ekledim ama bu sefer de yazılarda çektiğim veriler görünmüyor.metin_nn adlı üyeden alıntı: mesajı görüntüle

Yazılan kodlar:
Function.php dosyası
function koeri_deprem_listesi() { $url = 'http://www.koeri.boun.edu.tr/sismo/2/son-depremler/liste-halinde/'; $html = file_get_contents($url); $start = strpos($html, '<table class="earthquake">'); $end = strpos($html, '</table>', $start); $table = substr($html, $start, $end - $start + 8); return $table; } add_shortcode('koeri_deprem', 'koeri_deprem_listesi');Yazıya eklenen shortcode:
[koeri_deprem]
- 18-04-2023, 02:38:34Eklenti Adı : Ad Inserter.
Senin eklentin bu.
İstediğin php kodunu istediğin paragraf içinde yada altta üste veya farklı şekilde her türlü işleyebilirsin.
Php seçmen yeterli. - 18-04-2023, 03:02:39kodları kendinize göre düzenleyerek ilgili işlemi gerçekleştirebilirsiniz hocam
function depremVerileri() { $veri = simplexml_load_file("http://udim.koeri.boun.edu.tr/zeqmap/xmlt/son24saat.xml"); $array = array(); foreach ($veri as $eq) { $array[] = array( "date" => date('d.m.Y H:i:s', strtotime((string)$eq->tarih)), "latitude" => $eq->attributes()->lat, "longitude" => $eq->attributes()->lng, "depth" => $eq->attributes()->Depth, "magnitude" => $eq->attributes()->mag, "region" => $eq->attributes()->lokasyon ); } return $array; } function depremVerileriShortcode() { $earthquakes = depremVerileri(); ?> <ul> <?php foreach ($earthquakes as $eq) : ?> <li> <?php echo $eq['date']; ?> - M<?php echo $eq['magnitude']; ?> <?php echo $eq['region']; ?> (<?php echo $eq['depth']; ?> km) </li> <?php endforeach; ?> </ul> <?php } add_shortcode('depremler', 'depremVerileriShortcode');[depremler]
kısa kodunuda konu içerisine eklemek için kullanabilirsiniz.
Düzenleme
---------------
function depremler() { $veri = simplexml_load_file("http://udim.koeri.boun.edu.tr/zeqmap/xmlt/son24saat.xml"); $depremlerArray = array(); foreach ($veri as $eq) { $depremlerArray[] = array( "date" => date('d.m.Y H:i:s', strtotime((string)$eq->tarih)), "latitude" => $eq->attributes()->lat, "longitude" => $eq->attributes()->lng, "depth" => $eq->attributes()->Depth, "magnitude" => $eq->attributes()->mag, "region" => $eq->attributes()->lokasyon ); } echo '<ul>'; foreach ($depremlerArray as $eq) : echo '<li>'; echo $eq['date'] . '' . $eq['magnitude']; echo $eq['region'] . '' . $eq['depth'] . 'km'; echo '</li>'; endforeach; echo '</ul>'; } add_shortcode('depremler', 'depremler');şöyle daha derli toplu oldu kod bunu direk kullanabilirsiniz.
