WordPress.org

Support

Support » Plugins and Hacks » random excerpt mod help needed

random excerpt mod help needed

  • I am using this plugin:

    Plugin Name: Random Excerpt
    Plugin URI: http://www.w-a-s-a-b-i.com/archives/2004/05/27/wordpress-random-posts-plugin/
    Description: Display random excerpt. Usage: random_excerpt();. Made specifically for photoblogs that place thumbnails in the excerpt field.
    Version: 1.0
    Author: Alexander Malov
    Author URI: http://www.w-a-s-a-b-i.com/

    I have posts that contain text and posts with images. I only want random thumbs of those pics posts showing up so I would have to modify the query below from the plugin to only show thumbs from the category pictures or not to show anything from category miscellaneous. can you help me with the sql query please?

    function random_excerpt ($limit = 5, $before = ‘

  • ‘, $after = ‘
  • ‘) {
    global $wpdb, $tableposts;
    $sql = “SELECT ID, post_title, post_excerpt FROM $tableposts WHERE post_status = ‘publish’ ORDER BY RAND() LIMIT $limit”;
    $results = $wpdb->get_results($sql);
    $output = ”;
    foreach ($results as $result) {
    $post_title = stripslashes($result->post_title);
    $permalink = get_permalink($result->ID);
    $post_excerpt = ($result->post_excerpt);
    $output .= $before . ‘‘ . $post_excerpt . ‘‘ . $after;
    }
    echo $output;

Viewing 2 replies - 1 through 2 (of 2 total)
  • anyone please?

    I am playing around with this:

    [code]$sql = “SELECT ID, post_title, post_excerpt FROM $tableposts WHERE post_status = ‘publish’ AND ID in (SELECT post_id FROM $wpdb->post2cat WHERE category_id != 1;) ORDER BY RAND() LIMIT $limit”;[/code]

    but the MYSQL Syntax near the SELECT command is somehow wrong…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘random excerpt mod help needed’ is closed to new replies.
Skip to toolbar