Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9089915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:15:18+00:00 2026-06-16T22:15:18+00:00

Hey guys I am making a Widget to display a posts title, and excerpt

  • 0

Hey guys I am making a Widget to display a posts title, and excerpt from that post, and its date. The code I have is here:

public function widget( $args, $instance ) {


        extract( $args );

        $headline = $instance['headline'];
        $category = $instance['category'];
        $numberposts = $instance['numberposts'];
        $readmore = $instance['readmore'];


        echo $before_widget;

        echo $before_title;

        echo "<p class=\"headline\">$headline</p>";

        echo $after_title;

        $args = array( 'numberposts' => $numberposts, 'category_name' => $category );
        $recent_posts = wp_get_recent_posts( $args );
        foreach( $recent_posts as $recent ){
        echo '<a href="' . get_permalink($recent["ID"]) . '" title=" '.esc_attr($recent["post_title"]).'" >' .   $recent["post_title"].'</a> ';
        echo the_time('F j, Y');
        echo the_excerpt();

        }

As you can see I am trying to call the time and the excerpt from the post. It is working but it is only displaying the date and and excerpt from the very first post that is called welcome. I want it to display the Date and excerpt from each individual post. I will post a link to the site with the widget in the side bar. Sorry if I am not being clear enough or if more info is needed I am very new to this.

http://www.modmacro.us/wpsandbox/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:15:19+00:00Added an answer on June 16, 2026 at 10:15 pm

    First thing: the_excerpt(), is already an echo statement. Not a return statement. It’s the same with the_date(). Prefix them with “get_”, and they will return the information you need, or you can get rid of the echo command preceding it.

    Second thing: In order for those functions to work, they need to be used in a WordPress loop.

    Since we’re already in a loop, we just have to make sure it changes the WordPress Globals appropriately to reflect the information you need..

    foreach( $recent_posts as $recent ){
        setup_postdata(get_post($recent['ID']));
        echo '<a href="' . get_permalink() . '" title=" '.esc_attr(get_the_title()).'" >' .   get_the_title().'</a> ';
        echo get_the_time('F j, Y', $recent['ID']);
        the_excerpt();
    }
    wp_reset_postdata();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey guys i have a situation here. i have a code that out puts
Hey guys I'm making a chat program and I have a parent MessagePacket class
Hey guys I have a problem with an app I'm making. The thing is
Hey guys I have an array of dictionaries plist file that I am reading
Hey guys. I have a method that gets called each second which I want
Hey Guys I Am really new to making apps and this a error that
hey guys, I have no luck making a simple background image animation working without
Hey guys, here's my requirement: I have one central App which receives requests from
Hey guys, I am making an application using C# in Visual Studio that minifies
Hey guys, I'm making a javascript rock, paper, scissors game! So the code is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.