php - Only the_excerpt seems to return anything -
when producing front page of website , trying grab 5 excerpts wordpress database produces excerpt, no problem, ignores the_title, get_the_id , the_date:
foreach( $post $posts) : setup_postdata($posts); echo "<hr><h1>" . the_title( false, false, false ) . "</h1>"; echo the_excerpt( ) . "<br />"; echo "<a href='./index.php?p=" . get_the_id( ) . "'><font color='white'>read more...</font></a><br />"; echo "published on: " . the_date( false, false, false, false ); endforeach;
which produces output:
http://i.stack.imgur.com/jnkxh.png
and such, 'read more...' directed './index.php?p='
i have defined get_posts statement follows:
$args = array( 'posts_per_page' => 5, 'numberposts' => 5, 'offset' => 0, 'category' => $c, 'order_by' => 'post_date', 'order' => 'desc', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_mime_type' => '', 'post_parent' => '', 'post_status' => 'publish', 'suppress_filters' => true ); $post = get_posts( $args );
any ideas on went wrong appreciated.
i think problem lies setup_postdata
function.
quote setup_postdata codex page:
important: must make use global $post variable pass post details function, otherwise functions the_title() don't work properly...
example codex page:
global $post; // assign post details $post (& not other variable name!!!!) $post = $post_object; setup_postdata( $post ); ...
so try renaming $post
$mypost
, use exact $post
variable in setup_postdata()
this:
foreach( $mypost $post) : setup_postdata($post);
Comments
Post a Comment