Skip to content

Instantly share code, notes, and snippets.

@devuri
Last active July 4, 2023 17:04
Show Gist options
  • Select an option

  • Save devuri/65ff608508c1127c95f03d37fcbc2242 to your computer and use it in GitHub Desktop.

Select an option

Save devuri/65ff608508c1127c95f03d37fcbc2242 to your computer and use it in GitHub Desktop.

Revisions

  1. devuri revised this gist Jul 4, 2023. 1 changed file with 25 additions and 32 deletions.
    57 changes: 25 additions & 32 deletions most-recent-posts.php
    Original file line number Diff line number Diff line change
    @@ -1,49 +1,42 @@
    <?php
    <?php
    /*
    Plugin Name: Most Recent Posts
    Description: Lists posts based on categories and limits the number of returns
    */

    /**
    * list post based on categories and limit number of returns
    *******************************************************************/
    add_shortcode("most_recent_post", function ($atts)
    {
    function most_recent_posts_shortcode($atts) {
    $a = shortcode_atts(
    [
    "postnumber" => 3,
    "category" => 0,
    ],
    array(
    'postnumber' => 3,
    'category' => 0,
    ),
    $atts
    );

    ob_start();
    // php only
    $devuri_recent_posts = wp_get_recent_posts([
    "numberposts" => $a["postnumber"],
    "category" => $a["category"],
    "post_status" => "publish",
    ]);

    $devuri_recent_posts = wp_get_recent_posts(array(
    'numberposts' => $a['postnumber'],
    'category' => $a['category'],
    'post_status' => 'publish',
    ));

    foreach ($devuri_recent_posts as $devuri_recent) {
    echo '<div class="mrp-wrapper" style="padding: 2px;">';

    echo '<ul class="mrp-ul" style="padding: 8px; overflow: hidden; border-top: solid thin beige;"><li>';
    echo '<div class="mrp-featimage" style="padding-right: 12px;">';
    echo '<a href="' .
    get_permalink($devuri_recent["ID"]) .
    ' "> ' .
    get_the_post_thumbnail($devuri_recent["ID"], "medium") .
    "</a>";
    echo "</div>";
    //echo '<strong><a href="'. get_permalink($devuri_recent["ID"]) . ' "> ' . $a['postimage']. '</a>' ;
    echo ' <strong><a href="' .
    get_permalink($devuri_recent["ID"]) .
    ' "> ' .
    $devuri_recent[post_title] .
    "</a></strong>";
    echo "<br/>" . date("jS F, Y", strtotime($devuri_recent[post_date]));
    echo "</li></ul>";
    echo "</div>";
    echo '<a href="' . get_permalink($devuri_recent['ID']) . '"> ' . get_the_post_thumbnail($devuri_recent['ID'], 'medium') . '</a>';
    echo '</div>';
    echo ' <strong><a href="' . get_permalink($devuri_recent['ID']) . '"> ' . $devuri_recent['post_title'] . '</a></strong>';
    echo '<br/>' . date('jS F, Y', strtotime($devuri_recent['post_date']));
    echo '</li></ul>';
    echo '</div>';
    }

    wp_reset_query();
    $output_mrp_obj = ob_get_contents();
    ob_end_clean();
    return $output_mrp_obj;
    });
    }
    add_shortcode('most_recent_post', 'most_recent_posts_shortcode');
  2. devuri revised this gist Jul 4, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion most-recent-posts.php
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    /**
    * list post based on categories and limit number of returns
    *******************************************************************/
    add_shortcode("most_recent_post", function mrp_shrtfunc($atts)
    add_shortcode("most_recent_post", function ($atts)
    {
    $a = shortcode_atts(
    [
  3. devuri created this gist Jul 4, 2023.
    49 changes: 49 additions & 0 deletions most-recent-posts.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    <?php

    /**
    * list post based on categories and limit number of returns
    *******************************************************************/
    add_shortcode("most_recent_post", function mrp_shrtfunc($atts)
    {
    $a = shortcode_atts(
    [
    "postnumber" => 3,
    "category" => 0,
    ],
    $atts
    );

    ob_start();
    // php only
    $devuri_recent_posts = wp_get_recent_posts([
    "numberposts" => $a["postnumber"],
    "category" => $a["category"],
    "post_status" => "publish",
    ]);

    foreach ($devuri_recent_posts as $devuri_recent) {
    echo '<div class="mrp-wrapper" style="padding: 2px;">';

    echo '<ul class="mrp-ul" style="padding: 8px; overflow: hidden; border-top: solid thin beige;"><li>';
    echo '<div class="mrp-featimage" style="padding-right: 12px;">';
    echo '<a href="' .
    get_permalink($devuri_recent["ID"]) .
    ' "> ' .
    get_the_post_thumbnail($devuri_recent["ID"], "medium") .
    "</a>";
    echo "</div>";
    //echo '<strong><a href="'. get_permalink($devuri_recent["ID"]) . ' "> ' . $a['postimage']. '</a>' ;
    echo ' <strong><a href="' .
    get_permalink($devuri_recent["ID"]) .
    ' "> ' .
    $devuri_recent[post_title] .
    "</a></strong>";
    echo "<br/>" . date("jS F, Y", strtotime($devuri_recent[post_date]));
    echo "</li></ul>";
    echo "</div>";
    }
    wp_reset_query();
    $output_mrp_obj = ob_get_contents();
    ob_end_clean();
    return $output_mrp_obj;
    });