studgate Posted June 24, 2007 Share Posted June 24, 2007 can someone explain that code to me I need to understand it so I can expand it. Thank you in advance. <?php $prev_id = get_previous_post(TRUE); $prevpost = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID={$prev_id->ID}", 'ARRAY_A'); $prev_date = strtotime($prevpost['post_date']); ?> Quote Link to comment Share on other sites More sharing options...
bigbob Posted June 24, 2007 Share Posted June 24, 2007 Ok. lets walk you through it. <?php $prev_id = get_previous_post(TRUE); $prevpost = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID={$prev_id->ID}", 'ARRAY_A'); $prev_date = strtotime($prevpost['post_date']); ?> First part: $prev_id = get_previous_post(TRUE); this saves a variable called $prev_id as the result of a function called get_previous_post. It saves the value as either TRUE or FALSE. In this case, you are defining it as "TRUE". Second part: $prevpost = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID={$prev_id->ID}", 'ARRAY_A'); This puts a MySQL query command into a variable. I am not sure why you would want to put "$wpdb->" in front, but there it assigns the value "TRUE" or "FALSE" to a variable called wpdb AND prevpost. This is not necessary. Consider revising. Third: $prev_date = strtotime($prevpost['post_date']); This outputs the command STRING TO TIME. It converts a string into time and saves it into a variable called prevpost. I do not know why there is a ['post_date'] inside it. Consider revising to: $prev_date = strtotime($_COOKIE['post_date']); or $prev_date = strtotime($_SESSION['post_date']); or $prev_date = strtotime($post_date); Quote Link to comment Share on other sites More sharing options...
studgate Posted June 24, 2007 Author Share Posted June 24, 2007 Thanks bigbob for the explanation. What I was trying to do was to call upon the previous post in a wordpress database, so I need the previous post information from the current one. So if I have post 3, I want to call upon the content from the 2nd post. Somehow I am getting an error message. WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1] SELECT * FROM wic_posts WHERE ID= Any help is welcome. Quote Link to comment Share on other sites More sharing options...
bigbob Posted June 24, 2007 Share Posted June 24, 2007 hmm. can u show me ur code? Quote Link to comment Share on other sites More sharing options...
studgate Posted June 24, 2007 Author Share Posted June 24, 2007 Here it is: <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php $prev_id = get_previous_post(TRUE); $prevpost = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID={$prev_id->ID}", 'ARRAY_A'); $prev_date = strtotime($prevpost['post_date']); ?> <h2><?php previous_post_link('%link') ?></h2> <small>Posted: <?php echo date('l, F jS, Y', $prev_date); ?></small><br /> <?php echo $prevpost['post_content']; ?> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> Quote Link to comment Share on other sites More sharing options...
bigbob Posted June 26, 2007 Share Posted June 26, 2007 here ya go all fixed up: <?php if ( have_posts() ){ while ( have_posts() ) { the_post(); } } $prev_id = get_previous_post(TRUE); $prevpost = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID={$prev_id->ID}", 'ARRAY_A'); $prev_date = strtotime($prevpost['post_date']); ?> <h2><?php previous_post_link('%link') ?></h2> <small>Posted: <?php echo date('l, F jS, Y', $prev_date); ?></small><br /> <?php echo $prevpost['post_content']; ?> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> Try and see if it works =D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.