Home > posts > recent posts for different categories

recent posts for different categories

June 20Hits:1
Advertisement

I'm developing a theme that will have two recent posts section on the home page- one section for recent portfolio updates and the other for recent blog posts. I'm struggling with implementing these functions in the theme; I know it's something to do with wp_query, I'm just not entirely sure how to go about this. Any and all help is greatly appreciated.

HTML:

    <div id="recent">         <div id="recent-work">                 <p><span>Recent Work</span></p>                 <a href="#"><img src="http://lorempixel.com/130/130/" alt="Click for more information" /></a>                 <a href="#"><img src="http://lorempixel.com/130/130/" alt="Click for more information" /></a>                 <a href="#"><img src="http://lorempixel.com/130/130/" alt="Click for more information" /></a>                         <div class="next"><a href="#"><img src="img/next.png" alt="Click for more information" /></a></div>         </div><!-- end recent-work -->         <div class="divider">                 <img src="img/divider.png" alt="Section divider" />         </div><!-- end divider -->         <div id="recent-blog">                 <p><span>Recent Blog</span></p>                 <a href="#"><img src="http://lorempixel.com/130/130/" alt="Click for more information" /></a>                 <a href="#"><img src="http://lorempixel.com/130/130/" alt="Click for more information" /></a>                 <a href="#"><img src="http://lorempixel.com/130/130/" alt="Click for more information" /></a>                         <div class="next"><a href="#"><img src="img/next.png" alt="Click for more information" /></a></div>         </div><!-- end recent-blog --> </div><!-- end recent --> 

CSS

#recent {     border-top: 1px solid #202020;     padding-bottom: 40px;     padding-top: 40px; }  #recent .divider {     display: block;     float: left;     margin-left: 20px;     padding-bottom: 20px; }  #recent #recent-work {     display: block;     float: left;     position:relative; }  #recent #recent-work p {     padding-bottom: 20px; }  #recent #recent-work p span {     font-family: nevis-webfont;     font-size: 112.5%;     font-weight: normal;     letter-spacing: 1px;     text-transform: uppercase; }  #recent #recent-work a {     padding-bottom: 40px;     padding-right: 20px; }  #recent #recent-blog {     display: block;     float: right;     position:relative; }  #recent #recent-blog p {     padding-bottom: 20px; }  #recent #recent-blog p span {     font-family: nevis-webfont;     font-size: 112.5%;     font-weight: normal;     letter-spacing: 1px;     padding-left: 20px;     text-transform: uppercase; }  #recent #recent-blog a {     padding-bottom: 40px;     padding-left: 20px; }  #recent .next {     position: absolute;     bottom: -40px;     right: 0px; } 

Answers

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 id="recent">
    <div id="recent-work">
            <p><span>Recent Work</span></p>
            <?php while ( $portfolio_query->have_posts() ) : $portfolio_query->the_post(); ?>
            <a href="<?php the_permalink(); ?>"><img src="http://lorempixel.com/130/130/" alt="Click for more information" /></a>
            <?php endwhile; ?>
                    <div class="next"><a href="#"><img src="img/next.png" alt="Click for more information" /></a></div>
    </div><!-- end recent-work -->
<?php endif; ?>
    <div class="divider">
            <img src="img/divider.png" alt="Section divider" />
    </div><!-- end divider -->

<?php // repeat the whole if clause here for the blog posts, just replace $blog_query with $portfolio_query ?>

Related Articles

  • query recent posts from several categoriesMarch 8

    i'd like to list my 10 most recent posts but from certain categories only - anyone can tell me how to do this? thanks --------------Solutions------------- simply add this above your loop $args = array( 'posts_per_page' => 10, 'category__in' => array

  • recent posts for different categoriesJune 20

    I'm developing a theme that will have two recent posts section on the home page- one section for recent portfolio updates and the other for recent blog posts. I'm struggling with implementing these functions in the theme; I know it's something to do

  • WordPress query for most recent posts from multiple categoriesJanuary 8

    I have 5 categories. I want to query each category and get a list of the most recent posts from them. I also only want single post from each category, with no duplicates. Is there a way to do this without writing 5 queries? Can it be done with one qu

  • Show recent ads from certain categoriesJune 4

    I ask you to help experts, the problem is: I'm using a template classified, are shown on the home for the latest upload, but I would like to show ads in different categories. Let me explain, I would like to display the latest in a given category. Thi

  • Create a list of recent Custom Post Types postsOctober 26

    I've been using this snippet to generate a list of recent posts from particular categories in a widget. I'm currently restructuring the site using custom post types and taxonomies and want to generate a list of recent posts from 3 custom post types,

  • Display one latest post from multiple categoriesAugust 26

    This should be very easy, however for some reason I can't find a working snippet anywhere on the web.. I basically need to display one latest post from 6 categories (can be changed to 7,8, etc etc) using one loop. this should be the output: (just a d

  • Get most recent posts by category that aren't first overall September 14

    Possible Duplicate: Duplicate posts I'm trying to create a home page, in which there is a top posts section that displays the three most recent posts (for all categories), and category subsections that display the most recent posts for that category

  • change recent posts based on categoryNovember 5

    I am writing a code to display the recent posts of different categories. On clicking category 1, I want to display the recent posts from cat1 and on clicking cat 2 the recent posts from cat2 and so on. The code I have written was displaying the same

  • Add description to custom text widget and display the 5 recent post titlesDecember 14

    I am running into a problem where I have no idea where to add in a description so it will show up on the widget dashboard. It just keeps displaying the title. Something else I would love some help with is to add functionality to display the 5 most re

  • Exclude most recent posts from specific category in wp_query()November 6

    I have a featured posts slider, which uses the 'featured' tag. I have a query for this which grabs the 3 most recent posts with this tag and shows them in the slider. Below this, I have a list of 10 or so most recent posts across all categories. How

  • Child categories by post dateJune 2

    I have created a parent category called " Shows " and have 8 different programs under it. I want to display the most recent post from all categories on first block of my template page. The code I am using right now. <ul> <?php $categori

  • Why would in_category only return one post in a specific category?May 14

    So... what I'm trying to do is simple - get the post content for all posts, but only in a given category. Simple - filter the loop using in_category. So I did this (this is actually a stripped version of the loop I used to try to troubleshoot this):

  • Custom field outside the loop and inside an arrayFebruary 21

    I am trying to use a custom field inside a widget so it's therefore outside the loop. Taking it a step further, the theme I have is using an array to generate listings which makes it hard for me to understand. Basically, the theme uses a feature imag

  • Plugin suggestion: Find broken links May 22

    I recently changed a few categories, so I know I have a bunch of broken links now. Instead of spending hours going through previous posts and fix them manually, I want to use a plugin that can do that for me. My friend Google told me about the "Broke

  • WordPress v Joomla: Introduction and Content Structures

    WordPress v Joomla: Introduction and Content StructuresJuly 13

    WordPress v Joomla WordPress v Joomla: Introduction and Content Structures WordPress v Joomla: Templates and Themes WordPress v Joomla: Plugins, Extensions, and Customization WordPress v Joomla: Search Engine Optimization WordPress v Joomla: Support

  • Multiple Loops Breaking PagesMay 31

    I'm new to WordPress, and I'm having an issue with "The Loop." I have a sidebar on the left side of a page that's supposed to show recent posts from two categories. In the middle of the page, there should be content for that specific page. In th

  • Change display wp post type to wp custom post typeJune 3

    i have this code below to display wp post based on category but what i want to display wp custom post called 'wiki' based on its category. CPT wiki is from plugin, so i think already defined. class Pyre_Homepage_1col_Widget extends WP_Widget { functi

  • Displaying Post Featured Images on All PagesJune 3

    First, let me start off by saying I'm very new to WordPress. I've only ever done basic themes before, this is my first big project. I'm working on a design that has two sidebars on every page. Each sidebar displays the most recent post from two categ

  • Archives and category of authorsJuly 10

    Description of the problem: I should make a blog with, let's say 4 authors (may be more). The blog shoud have a page 'blog-page-1' (without sidebar) on which will be the last post of each author and a page 'blog-page-2' (with sidebar) on which will b

  • Are Git branches, in fact, "homeomorphic endofunctors mapping submanifolds of a Hilbert space"?September 16

    As we all know: Git gets easier once you understand branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space Which seems like jargon, but on the other hand, All told, a monad in X is just a monoid in the category of endofunctors

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.381 s.