How to add a recent post function to a text widget I created for practice?

In the function widget( $args, $instance ), which generates the widget output, add the following code before the echo $after_widget; line: // The Query $the_query = new WP_Query( array( ‘post_type’ => ‘page’, ‘posts_per_page’ => ‘3’ ) ); // The Loop while ( $the_query->have_posts() ) : $the_query->the_post(); echo ‘<li>’ . get_the_title() . ‘</li>’; endwhile; Additional information … Read more

Homepage custom recent news

Assuming this is the default main query, see the example for pre_get_posts, which shows how to exclude a category from the main query: function wpa78465_exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘cat’, ‘-1,-1347’ ); // IDs of categories to exclude } } add_action( ‘pre_get_posts’, ‘wpa78465_exclude_category’ );

Manual excerpt length on recent posts slider

The line below the one you edited computes the edited words based on the height and width of the slider box. The value you added is changed on the next line. Avoid editing the plugin file. Next time you update the plugin your changes will be lost. You should be able to change the Excerpt … Read more

Where to add offset?

<?php $recent = new WP_Query( array( ‘tag’ => get_option(‘gd_slider_tags’), ‘posts_per_page’ => get_option(‘gd_slider_num’), ‘offset’ => 1) ); while($recent->have_posts()) : $recent->the_post();?>

Showing recent post of category in page

Here is a start. This is how I display related posts from the category the post are in. You will just need to add your own loop and CSS Create a template called content-related.php Inside that paste the following code <?php /** * The default template for displaying realted posts * * @package WordPress * … Read more

Problem with Front-Page.php loading recent posts

You have to reset every instance of a custom query, otherwise you will get unexpected output from any other query there after Simply use wp_reset_postdata() after every custom query. Example <?php $args = array( ‘numberposts’ => ‘1’, ‘meta_key’=>’_thumbnail_id’ ); $recent_posts = wp_get_recent_posts( $args ); foreach($recent_posts as $post) : ?> <?php get_template_part( ‘content’, ” ); ?> … Read more

Adding a badge to new blog post titles

You want to edit the title, and not the content. Check this for filters you want to use. If you want to edit your title you should add_filter to it and modify it(the_title). Like so: add_filter(‘the_title’, ‘addBadge2Title’); function addBadge2Title($title) { $seconds = strtotime(“now”) – strtotime(get_the_date(“Y/m/d”)); $badge = get_stylesheet_directory_uri() . ‘/library/images/new_ribbon.gif’; if ($seconds < 10950400) { … Read more

Get x recent posts by author?

The function you are using, get_most_recent_post_of_user, won’t work as it only retrieves the latest post from the author. It cannot retieve a list of posts Walks through each of a user’s blogs to find the post with the most recent post_date_gmt. You will most probably be better of using either WP_Query or get_posts to achieve … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)