view the latest post
-
hi
The code to view the latest content Want
tnx
-
Um, dude, you gotta give us more to go on than that, right? Can you explain what you’re looking for? You sure get points for brevity. π
If I’m intuiting what you need, I think you might be looking for a function like: wp_get_recent_posts or some of the examples on that page.
I hope that helps.
bcworkz waves at Eric π
I intuit the same. The examples do not address some minor quirks, I would do it this way:global $post, $more; $myposts = get_posts( array('posts_per_page' => 1 )); foreach ( $myposts as $post_obj ) { $more = 1; //show full content in all contexts $post = $post_obj; setup_postdata( $post ); the_content(); } wp_reset_postdata();tnx
show related post . That is correct?:
<?php
$orig_post = $post;
global $post;
$tags = wp_get_post_tags($post->ID);if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
‘tag__in’ => $tag_ids,
‘post__not_in’ => array($post->ID),
‘posts_per_page’=>4, // Number of related posts to display.
‘caller_get_posts’=>1
);$my_query = new wp_query( ‘showposts=3’ );
while( $my_query->have_posts() ) {
$my_query->the_post();
?><!–content–>
<?php }
}
$post = $orig_post;
wp_reset_query();
?>
</div>Oh! Related, not latest? English can be so confusing!
Your code has a few problems, but it’s close. It must be inside a standard WP loop to work:
while ( have_posts() ) : the_post(); /* inside the WP loop */ endwhile;You don’t really need these lines, though they do no real harm:
$orig_post = $post; global $post; $post = $orig_post;Most important is to change the $my_query = line to this:
$my_query = new WP_Query( $args );Change
'caller_get_posts'=>1to'ignore_sticky_posts' => 1,
Set the maximum number of related posts to list on this line:
'posts_per_page'=>4, // Number of related posts to display.Finally, replace
<!--content-->with code to display what you want for each related post. It’s up to you what this is, you can start with this:
<a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a>It is possible for me to paste in the following codeIt is possible for me to paste in the following code
<?php
$orig_post = $post;
global $post;
$tags = wp_get_post_tags($post->ID);if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
‘tag__in’ => $tag_ids,
‘post__not_in’ => array($post->ID),
‘posts_per_page’=>4, // Number of related posts to display.
‘caller_get_posts’=>1
);$my_query = new wp_query( ‘showposts=3’ );
while( $my_query->have_posts() ) {
$my_query->the_post();
?>
<div class=”col-xs-12 col-md-4″>
” class=”thumbnail recent”>
<?php the_post_thumbnail(‘related’); ?>
<h4><?php the_title(); ?></h4>
</div>
<?php }
}
$post = $orig_post;
wp_reset_query();
?>When you post code, please surround it with backticks: `code_here`, otherwise the forum’s parser can mangle it. I cannot really tell if the loop content you added is correct because of this.
Let us assume that is OK. The main problem remains this line:
$my_query = new wp_query( 'showposts=3' );Please change it to this:
$my_query = new wp_query( $args );ok?
<?php
$orig_post = $post;
global $post;
$tags = wp_get_post_tags($post->ID);if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
‘tag__in’ => $tag_ids,
‘post__not_in’ => array($post->ID),
‘posts_per_page’=>3, // Number of related posts to display.
‘caller_get_posts’=>1
);$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
$my_query->the_post();
?>
<div class=”col-xs-12 col-md-4″>
” class=”thumbnail recent”>
<?php the_post_thumbnail(‘related’); ?>
<h4><?php the_title(); ?></h4>
</div>
<?php }
}
$post = $orig_post;
wp_reset_query();
?>Looks OK, should be working for you now. For good measure please change
'caller_get_posts'=>1to'ignore_sticky_posts'=>1– ‘caller_get_posts’ is deprecated.I’m still not 100% sure about your content
<div class="col-xs-12 col-md-4">...</div>but it’s probably OK. You need to use the ‘code’ button or backticks when posting code, not the ‘b-quote’ button π
The topic ‘view the latest post’ is closed to new replies.