
Untitled
By: a guest on
May 1st, 2012 | syntax:
None | size: 1.86 KB | hits: 15 | expires: Never
Having trouble using the_title() and the_permalink() in a plugin
function slyd( $category, $slydcount ) {
global $post;
$tmp_post = $post; // Create $tmp_post to empty $post once Slyd is done with it
$args = array(
'category' => $category,
'numberposts' => $slydcount
);
$slydposts = get_posts( $args );
foreach( $slydposts as $post ) : setup_postdata($post);
$post_permalink = the_permalink(); // Get the post's permalink
$post_title = the_title(); // Get the post's title
$post_content = the_content(); // Get the post's content - will write code to get excerpt later
return '<h2><a href="' . $post_permalink . '">' . $post_title . '</a></h2>n'
. '<p>' . $post_content . '</p>';
endforeach;
$post = $tmp_post; // Empty $post once Slyd is done with it
}
// Create the shortcode
function slyd_shortcode( $atts ) {
// $atts ::= array of attributes
// examples: [slyd]
// [slyd category='slide']
// [slyd slydcount='5']
// [slyd theme='default']
/* Retrieve attributes set by the shortcode and set defaults for
unregistered attributes. */
extract( shortcode_atts( array(
'category' => '', // Which category(s) to display posts from
'slydcount' => '5', // How many Slyds to display
'theme' => 'default' // Which Slyd theme to use
), $atts ) );
return "<p>category = {$category}, count = {$slydcount}</p>"
. slyd( $category, $slydcount );
}
add_shortcode( 'slyd', 'slyd_shortcode' );
<?php the_title('', '', false); ?>
ob_start();
the_content();
$content = ob_get_clean();
$title = get_the_title()
$link = get_the_permalink()