Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 1.86 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Having trouble using the_title() and the_permalink() in a plugin
  2. function slyd( $category, $slydcount ) {
  3.     global $post;
  4.     $tmp_post = $post;                      // Create $tmp_post to empty $post once Slyd is done with it
  5.  
  6.     $args = array(
  7.         'category'      =>  $category,
  8.         'numberposts'   =>  $slydcount
  9.     );
  10.     $slydposts = get_posts( $args );
  11.     foreach( $slydposts as $post ) : setup_postdata($post);
  12.         $post_permalink = the_permalink();  // Get the post's permalink
  13.         $post_title = the_title();          // Get the post's title
  14.         $post_content = the_content();      // Get the post's content - will write code to get excerpt later
  15.         return '<h2><a href="' . $post_permalink . '">' . $post_title . '</a></h2>n'
  16.         . '<p>' . $post_content . '</p>';
  17.     endforeach;
  18.     $post = $tmp_post;                      // Empty $post once Slyd is done with it
  19. }
  20.  
  21. // Create the shortcode
  22. function slyd_shortcode( $atts ) {
  23.     // $atts        ::=     array of attributes
  24.     // examples:            [slyd]
  25.     //                      [slyd category='slide']
  26.     //                      [slyd slydcount='5']
  27.     //                      [slyd theme='default']
  28.  
  29.     /* Retrieve attributes set by the shortcode and set defaults for
  30.     unregistered attributes. */
  31.     extract( shortcode_atts( array(
  32.         'category'      =>  '',             // Which category(s) to display posts from
  33.         'slydcount'     =>  '5',            // How many Slyds to display
  34.         'theme'         =>  'default'       // Which Slyd theme to use
  35.     ), $atts ) );
  36.  
  37.     return "<p>category = {$category}, count = {$slydcount}</p>"
  38.     . slyd( $category, $slydcount );
  39. }
  40.  
  41. add_shortcode( 'slyd', 'slyd_shortcode' );
  42.        
  43. <?php the_title('', '', false); ?>
  44.        
  45. ob_start();
  46. the_content();
  47. $content = ob_get_clean();
  48.        
  49. $title = get_the_title()
  50.        
  51. $link = get_the_permalink()