Shortcode to display latest post from one category

Community Forums Forums Design Tips and Tricks Shortcode to display latest post from one category

This topic is: not resolved

This topic contains 1 reply, has 1 voice, and was last updated by  jodzeee 5 months, 1 week ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #102268

    jodzeee
    Participant
    Post count: 216

    I’m trying to display the most recent post from one category on a page. I thought I’d try to do it without a plugin and I’m close … but where do I define which category?

    add_shortcode('recent-posts', 'my_recent_posts_shortcode'); */
    
    function recent_posts_function() {
       query_posts(array('orderby' => 'date', 'order' => 'DESC' , 'showposts' => 1));
       if (have_posts()) :
          while (have_posts()) : the_post();
             $return_string = '<div class="current-offer">'.get_the_content().'</div>';
          endwhile;
       endif;
       wp_reset_query();
       return $return_string;
    }
    
    function register_shortcodes(){
       add_shortcode('recent-posts', 'recent_posts_function');
    }
    
    add_action( 'init', 'register_shortcodes');
    
    #102270

    jodzeee
    Participant
    Post count: 216

    Oops! Sorry for the duplicate post. Disregard this one!

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.