Help with “Recent Posts” Loop that is specific to a topic

Put this in your sidebar template where you want the listing to show up. Alternatively, you could use a plugin that allows you to run php in widgets and then place directly in a widget box, but that’s not always wise. <?php $categories = get_the_category(); $category = $categories[0]; $category_id = $category->cat_ID; $args = array(‘category__in’ => … Read more

How to display posts on template

$args = array( ‘posts_per_page’=>-1, ‘number_posts’=>-1, ‘category’=>9, ‘orderby’=>’post_date’, ‘order’ => ‘DESC’, ‘post_type’=>’post’, ‘post_status’=>’publish’ ); $posts = get_posts($args); foreach($posts as $post): $id= $post->ID; $permalink = get_permalink( $id ); $title = $post->post_title; $content = $post->post_content; $image = wp_get_attachment_url(get_post_thumbnail_id($id)); endforeach;

WordPress Recent post only showing title

Have a look at the WP_Widget_Recent_Posts class in wp-includes/default-widgets.php to see how it is structured. You can even copy and paste the class in your functions.php, rename it to something else and modify the class to display your images. And don’t forget to add a register_widget(‘NameOfYourClassHere’); hooked to widgets_init.

Small intro before latest blog posts

Two methods: Edit the template file: Find the template file that renders your posts (most likely index.php) and find the place where the post loop starts. Something like: <?php if (have_posts()) : while (have_posts()) : the_post(); ?> Any content added before this code will be shown before your blog posts. Insert via hook: add_action( ‘loop_start’, … Read more

Display recent post by tag

<div class=”page-loop”> <?php while (have_posts()) : the_post(); $page_title = strtolower(get_the_title()); the_title(‘<h1>’,'</h1>’); ?> <p><?php the_content(); ?><p> <?php endwhile;?> </div> <!– Get the most recent post that has been tagged with the page title –> <div class=”related-posts”> <?php $args = array( ‘tag’ => $page_title, ‘posts_per_page’ => 1, ); $query = new WP_Query($args); if ($query->have_posts()) : while ($query->have_posts()) … 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

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