Skip to content

Instantly share code, notes, and snippets.

@nextab
Created June 28, 2024 15:53
Show Gist options
  • Save nextab/86a94807f5c6892c12c539c9887f0adf to your computer and use it in GitHub Desktop.
Save nextab/86a94807f5c6892c12c539c9887f0adf to your computer and use it in GitHub Desktop.
// Output a simple blog post feed (list all tutorials)
function nxt_feed_function($atts, $content = null) {
$a = shortcode_atts([
'button' => 'yes',
'cat' => '',
'class' => '',
'order' => 'DESC',
'orderby' => 'date',
'post_status' => 'publish',
'post_type' => 'post',
'ppp' => 5,
's' => '',
'show_pagination' => 'no',
'tag_id' => '',
'tag__in' => '',
'tag__and' => '',
], $atts);
$feed_args = [
'cat' => $a["cat"],
'order' => $a["order"],
'orderby' => $a["orderby"],
'post_status' => $a["post_status"],
'post_type' => $a["post_type"],
'posts_per_page' => $a["ppp"],
's' => $a["s"],
'show_pagination' => $a["show_pagination"],
'tag_id' => $a["tag_id"],
'tag__in' => $a["tag__in"],
'tag__and' => $a["tag__and"],
];
if(isset($_POST['post_type'])) { $feed_args['post_type'] = $_POST['post_type']; }
$return_string = '';
// echo '<pre>'; print_r($feed_args); echo '</pre>';
$feed_query = new WP_Query($feed_args);
if ($feed_query->have_posts()) {
$return_string .= '<div class="trendy-eistee ' . $a["class"] . '">';
while ($feed_query->have_posts()) {
$feed_query->the_post();
$nxt_post_id = get_the_ID();
// Get category slugs so we can output them at the article container
$nxt_categories = [];
foreach (get_the_category($nxt_post_id) as $c) {
$cat = get_category($c);
array_push($nxt_categories, $cat->slug);
}
if (sizeOf($nxt_categories) > 0) {
$post_categories = implode(' ', $nxt_categories);
} else {
$post_categories = 'no-category';
}
$nxt_permalink = get_the_permalink();
$nxt_title = get_the_title();
$return_string .= '<article class="nxt_post_infini_scroll ' . $post_categories . '"><a class="thumbnail_container_link" href="' . $nxt_permalink . '" title="' . $nxt_title . '"><div class="featured-image-container" style="background-image: url(' . get_the_post_thumbnail_url() . ');"></div></a>';
$return_string .= '<div class="post_content"><h3 class="entry-title"><a href="' . $nxt_permalink . '" title="' . $nxt_title . '">' . $nxt_title . '</a></h3>';
$nxt_content = (has_excerpt()) ? get_the_excerpt() : nxt_truncate(get_the_content());
$return_string .= '<div class="post_excerpt">' . $nxt_content . '</div>';
if($a["button"] == 'yes') {
$return_string .= '<div class="et_pb_button_module_wrapper et_pb_module et_pb_button_alignment_"><a class="et_pb_button et_pb_module et_pb_bg_layout_dark" href="' . $nxt_permalink . '">Weiterlesen</a></div>';
}
$return_string .= '</div> <!-- .post_content --></article>';
}
if($a['show_pagination'] == 'yes' && $a['ppp'] < $feed_query->found_posts) {
$return_string .= '<div class="dt_pagination"><button id="load-more-posts" class="et_pb_button et_pb_bg_layout_dark" onclick="increasePosts(event)">Mehr anzeigen</button></div>';
}
wp_reset_postdata();
$return_string .= '</div> <!-- .trendy-eistee -->';
} else {
// echo "<!-- nxt debug - no posts found -->";
$return_string .= '<div><h2 class="no-results entry-title">Es wurden leider keine Tutorials für diese Suchkriterien gefunden</h2></div>';
}
return $return_string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment