How do I add recent posts to the menu?
How do I add recent posts to the menu?
How do I add recent posts to the menu?
The $wp_query object is used to store the main page query, so when you’re using $wp_query = new WP_Query( $args ); you’re wiping out the defaults. Hence, the wp_reset_query() has nothing to reset. To fix the problem, save your custom query object with a different name, maybe $mr_custom_query, and then when looping through it, use … Read more
If the blog / portfolio items are grouped into categories, you can do this at the top of your template file: <?php $portfolio_query = new WP_Query(‘posts_per_page=3&category_name=portfolio’); // note ‘portfolio’ is the category slug $blog_query = new WP_Query(‘posts_per_page=3&category_name=blog’); // note ‘blog’ is the category slug ?> Then in your markup: <?php if ($portfolio_query->have_posts()) : ?> <div … Read more
You should use posts_per_page=4 instead of showposts=4. Reference: WP_Query Pagination Parameters
Here’s the relevant part of your code that should work: // This will make a URL like http://yoursite.com/path/to/fallback.png $fallback_image = site_url( ‘/path/to/fallback.png’ ); $fallback_image = “<img src=”https://wordpress.stackexchange.com/questions/224740/{$fallback_image}” />”; foreach( $recent_posts as $recent ){ echo ‘<div class=”sidebar-entries”>’; $featured_image = get_the_post_thumbnail( $recent[‘ID’], ‘sidebar-thumb’, array( ‘class’ => ‘sidebar-image’ ) ); if ( ! strlen( $featured_image ) ) { … Read more
You’ll have to create your own but you can copy the code and customize from /wp-includes/default-widgets.php If you edit the defaults they’ll screw up when you update WP.
I wasn’t sure if i would answer or simply vote to close this topic, i feel i sufficiently asnwered the original topic you’re referring to, i’d only be repeating myself here. That said, here’s an upto date version you can use(only took me 2 mins), you only need implement your own code to truncate the … Read more
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <a href=”https://wordpress.stackexchange.com/questions/60224/<?php the_permalink(); ?>”><?php the_title(); ?></a> <?php the_excerpt() ?> <?php endwhile; else: ?> <p>Nothing to see here.</p> <?php endif; ?> This is the right syntax to show title and the excerpt on home page.
In the admin panel, Go to Settings > Reading and set Blog pages show at most to 1 post.
I would tend not to go with wp_get_recent_posts or even get_posts for custom queries like this. By default, template tags like the_excerpt() is not available to these functions, and you have to make use of setup_postdata($post) to have access to these template tags. I would personally use WP_Query in a case like this which is … Read more