Forums

[resolved] How to display random post with some text (6 posts)

  1. cbogdan
    Member
    Posted 2 years ago #

    I am trying to find a solution to this problem. I checked some plugins, i found one that is special, because is simple, and seams to function for showing one single rondom post. That is great!
    So, i have this function :

    function single_random_post() {
    
    		    global $wpdb;
    		    $query = "SELECT id, post_title, post_name FROM $wpdb->posts WHERE ((post_status='publish') AND (post_type = 'post') AND ($wpdb->posts.post_password = '')) ORDER BY RAND() LIMIT 1";
    		    $randompost = $wpdb->get_results($query);
    		    $post = $randompost[0];
    		    $post_title = htmlspecialchars(stripslashes($post->post_title));
    		    $showpost .= "<a href=\"" . get_permalink($post->id) . "\" title=\"". $post_title ."\">" . $post_title ."</a>\n";
    		    echo $showpost;	
    
    }

    What i try to do is to resolve my issue. I wanna show some text not just the post title.
    Can help me someone with that?

  2. doc4
    Member
    Posted 2 years ago #

    cbogdan,

    Add the_content() similar to what this function is doing with the post_title().

  3. cbogdan
    Member
    Posted 2 years ago #

    I`m not a developer, i dont know verry good to work with the code.Can u tell me more about what i can do with the code?

  4. Shane G
    Member
    Posted 2 years ago #

    Hi,

    Have a check with this plugin:

    http://wordpress.org/extend/plugins/random-post-list/

    Thanks,

    Shane G.

  5. cbogdan
    Member
    Posted 2 years ago #

    Thanks Share G, but this plugin doesn`t have nothing to do with the content of call function.
    That is the problem, all the plugins seams to show only links, not text from the post that is calling in the page ...
    I just wanna show some text from the post that is called in the random post function ..
    doc4 seams to have a good idea and i`m waiting for his help.

  6. cbogdan
    Member
    Posted 2 years ago #

    I resolve this problem, i create a new plugin for that function.
    You can find the plugin at http://blog.121416.co.cc/en/wordpress/wordpress-plugin-single-random-post-with-text/

Topic Closed

This topic has been closed to new replies.

About this Topic