OPEN PROMPT PROJECT

Enter Feed URL

Get API Key Hide Cats Hide Favs
Open Prompt Project: Tags
Show Search

[-rss_feed_paginator_form]

example url: https://openpromptproject.com/prompts/Carpet-Recovery-Team/start/

 

 

 


function rss_feed_paginator_form() {
ob_start();
?>
<form method=”GET” action=”<?php echo esc_url($_SERVER[‘REQUEST_URI’]); ?>”>
<label for=”feed-url”>Enter Feed URL:</label>
<input type=”url” id=”feed-url” name=”feed_url” required>
<button type=”submit”>Start</button>
</form>
<?php
$feed_url = isset($_GET[‘feed_url’]) ? esc_url_raw($_GET[‘feed_url’]) : ”;

if ($feed_url !== ”) {


$step = isset($_GET[‘step’]) ? intval($_GET[‘step’]) : 0;
// Replace ‘start’ with $step in feed URL
$feed_url = str_replace(‘start’, $step, $feed_url);

// Load feed
$rss = simplexml_load_file($feed_url);

// Get total items
$totalItems = count($rss->channel->item);
echo ‘Total number of items in the feed: ‘ . $totalItems . ‘<br>’;

// Display pagination
echo ‘<div class=”pagination”>’;
if ($step > 0) {
echo ‘<a href=”?feed_url=’ . urlencode($feed_url) . ‘&step=’ . ($step – 1) . ‘”>Prev</a> ‘;
}
if ($step < $totalItems – 1) {
echo ‘ <a href=”?feed_url=’ . urlencode($feed_url) . ‘&step=’ . ($step + 1) . ‘”> Next</a>’;
}
echo ‘</div>’;

 


$segments = explode(‘/’, rtrim($feed_url, ‘/’)); // rtrim to remove trailing slash
array_pop($segments); // removes the last element
$newUrl = implode(‘/’, $segments);
$newUrl = $newUrl . ‘/’ . $step . ‘/’; // add trailing slash if necessary
$rss = simplexml_load_file($newUrl);

// Display current item
$item = $rss->channel->item;


$postString = $item->title;
$postArray = explode(‘ ‘, $postString, 2);

$postId = $postArray[0]; // This will contain ‘118894’
$postTitle = $postArray[1]; // This will contain ‘HTML Formatting Part II – Billy Mays Product Review Team’$titleArray = explode(‘–’, $postTitle, 2);


$step = get_post_meta($postId, ‘step’, true);
$who = get_post_meta($postId, ‘who’, true);
$what = get_post_meta($postId, ‘what’, true);
$why = get_post_meta($postId, ‘why’, true);
$category = get_post_meta($postId, ‘category’, true);
$task_name = get_post_meta($postId, ‘task_name’, true);
$agent_name = get_post_meta($postId, ‘agent_name’, true);


echo ‘Step: ‘ . $step . ‘<br>’;
echo ‘Title: ‘ . $postTitle . ‘<br>’;
echo ‘Agent: ‘ . $who . ‘<br>’;

echo ‘Prompt: ‘ . $what . ‘<br>’;
// Display pagination
echo ‘<div class=”pagination”>’;
if ($step > 0) {
echo ‘<a href=”?feed_url=’ . urlencode($feed_url) . ‘&step=’ . ($step – 1) . ‘”>Prev</a> ‘;
}
if ($step < $totalItems – 1) {
echo ‘ <a href=”?feed_url=’ . urlencode($feed_url) . ‘&step=’ . ($step + 1) . ‘”> Next</a>’;
}
echo ‘</div><hr>’;

// Display current item
echo ‘<h2>Feed Contents</h2>’;
echo ‘<ul class=”rss-items”>’;
foreach ($rss->channel->item as $item) {

echo ‘<h3><a href=”‘.$item->link.'” target=”_blank”>’.$item->title.'</a></h3>’;
echo ‘Author: ‘ . $item->author . ‘<br>’;

echo ‘Description: ‘ . $item->description . ‘<br>’;



}
echo ‘</ul>’;

// Display pagination
echo ‘<div class=”pagination”>’;
if ($step > 0) {
echo ‘<a href=”?feed_url=’ . urlencode($feed_url) . ‘&step=’ . ($step – 1) . ‘”>Prev</a> ‘;
}
if ($step < $totalItems – 1) {
echo ‘ <a href=”?feed_url=’ . urlencode($feed_url) . ‘&step=’ . ($step + 1) . ‘”> Next</a>’;
}
echo ‘</div>’;
}

return ob_get_clean();
}

add_shortcode(‘rss_feed_paginator_form’, ‘rss_feed_paginator_form’);

 

 

Adjust Writing Style, Writing Tone, and Language

Most popular

Most discussed

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.