forked from colin/SimpleTracking
Update simple-rss.php
This commit is contained in:
parent
8f541c7e79
commit
89a3371df6
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
Plugin Name: Simple RSS Embedder
|
||||||
|
Description: A simple plugin to embed RSS feeds via shortcode.
|
||||||
|
Version: 1.0
|
||||||
|
Author: Your Name
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Function to fetch and display the RSS feed
|
||||||
|
function simple_rss_display($atts) {
|
||||||
|
$atts = shortcode_atts(
|
||||||
|
array(
|
||||||
|
'url' => '', // RSS feed URL
|
||||||
|
'items' => 5 // Number of items to display
|
||||||
|
),
|
||||||
|
$atts,
|
||||||
|
'simple_rss'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (empty($atts['url'])) {
|
||||||
|
return '<p>No RSS feed URL provided.</p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$rss = fetch_feed($atts['url']);
|
||||||
|
|
||||||
|
if (is_wp_error($rss)) {
|
||||||
|
return '<p>Unable to fetch the RSS feed.</p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$maxitems = $rss->get_item_quantity($atts['items']);
|
||||||
|
$rss_items = $rss->get_items(0, $maxitems);
|
||||||
|
|
||||||
|
if ($maxitems == 0) {
|
||||||
|
return '<p>No items found in the RSS feed.</p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = '<ul>';
|
||||||
|
foreach ($rss_items as $item) {
|
||||||
|
$output .= '<li>';
|
||||||
|
$output .= '<a href="' . esc_url($item->get_permalink()) . '">' . esc_html($item->get_title()) . '</a>';
|
||||||
|
$output .= '<p>' . esc_html($item->get_date('j F Y | g:i a')) . '</p>';
|
||||||
|
$output .= '</li>';
|
||||||
|
}
|
||||||
|
$output .= '</ul>';
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register the shortcode [simple_rss]
|
||||||
|
function simple_rss_shortcode() {
|
||||||
|
add_shortcode('simple_rss', 'simple_rss_display');
|
||||||
|
}
|
||||||
|
add_action('init', 'simple_rss_shortcode');
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
Plugin Name: Simple Tracking
|
|
||||||
Description: Embeds tracking code into your WordPress site.
|
|
||||||
Version: 1.0
|
|
||||||
Author: Colin
|
|
||||||
Author URI: https://git.nixc.us/colin/SimpleTracking.git
|
|
||||||
*/
|
|
||||||
|
|
||||||
function add_simple_tracking_code() {
|
|
||||||
$tracking_code_path = plugin_dir_path(__FILE__) . 'tracking-code.php';
|
|
||||||
if (file_exists($tracking_code_path)) {
|
|
||||||
include $tracking_code_path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add_action('wp_head', 'add_simple_tracking_code');
|
|
Loading…
Reference in New Issue