• Hello – I have a blog which displays the latest 6 “posts”, which is great, but I’d also like it to show the latest “recipes” which is a custom post type on my website.

    Just be clear, I want the latest 6 blog posts, whether that’s a post or recipe to be shown.

    This is the code I currently have on my index.php. But it only shows “posts”, any idea how to add “recipes” to this too?

    <div id="left-area" class="clearfix">
                            		<?php
    									if (have_posts()):
    										while (have_posts()) :
    											the_post(); 
    
    											$post_type = get_post_type( $post->ID );
    											if($post_type = 'recipe')
    											{
    												get_template_part( 'inc/recipe-post' );
    											}
    											else
    											{
    												get_template_part( 'inc/standard-post' );
    											}
    
    										endwhile;
    									else :
    								?>
    					                               <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
    										<h2 class="post-title"><?php _e('No Post Found !', 'FoodRecipe') ?></h2>
    								</div><!-- end of post div -->
    
    								<?php endif; ?>
    
    								<?php
    									// Pagination
    									theme_pagination( $wp_query->max_num_pages);
    								?>
    						</div>

    Thank you

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter hpwg

    (@hpwg)

    I’ve also removed the side bar php and would like to center the latest blog posts, at the moment they are all justified left, with a large white space on the ride for the side bar.

    Is there an easy way to center the latest post feed and increase their width?

    Thank you.

    Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this in your theme’s functions.php:

    function my_post_queries( $query ) {
      // not an admin page and is the main query
      if (!is_admin() && $query->is_main_query()){
        // query the home page
        if(is_home()){
          $query->set('post_type', array('post','recipe'));
        }
      }
    }
    add_action( 'pre_get_posts', 'my_post_queries' );

    Is there an easy way to center the latest post feed and increase their width?

    Not without a link to your site.

    Thread Starter hpwg

    (@hpwg)

    THank you so much for that, I’ll try it now.

    Here is the site to help with the blog.

    https://onehandedcooks.com.au/hg

    Basically with the blog, when there are widgets down the side bar, they are too close to the blog posts and it feel crammed.

    Is there a way to left align the blog posts with the left of the nivo slider. And right align the widgets to the right hand side of the nivo slider.

    I’ve attached a rough mockup of what I mean here with lines to show where I’m trying to align.

    Thanks so much.

    Moderator keesiemeijer

    (@keesiemeijer)

    Change this in your theme’s stylesheet style.css:

    #left-area { width: 592px; float: left; margin: 0px 0px 0px 31px; padding: 25px 0px 0px; }

    to this:

    #left-area { width: 592px; float: left; margin: 0px 0px 0px 0px; padding: 25px 0px 0px; }

    And change this:

    #content #sidebar { width: 302px; float: right; margin: 0px 31px 0px 0px; padding: 41px 0px 0px; }

    to this:

    #content #sidebar { width: 302px; float: right; margin: 0px 0px 0px 0px; padding: 41px 0px 0px; }

    Thread Starter hpwg

    (@hpwg)

    Thank you, I really I appreciate that. Both codes work perfectly.

    It looks like I can finally launch my site. I was wondering if you could help me with these final points which I can move onto?

    ? How do I match the widget text size, to those of the blog post titles?
    ? I would like to add a header above the first blog post “Blog”, where would I write this code?
    ? I’m having some spacing issues with the blog posts, the end page numbers and horizontal lines. I’ve added <p> code, but can you recommend anything else to get consistent spacing between each post?

    Thank you for all your help.

    Thread Starter hpwg

    (@hpwg)

    Sorry – how do I make the side bar appear only on the main page, and not the other pages, for example – https://onehandedcooks.com.au/hg/?recipe_type=textured-food

    Moderator keesiemeijer

    (@keesiemeijer)

    I’m sorry but I don’t have time right now. Create new topics for all these new questions.
    https://www.ads-software.com/support/forum/how-to-and-troubleshooting#postform

    Thread Starter hpwg

    (@hpwg)

    Sure – thanks for all your help – really got us going in the right direction.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Adding custom post types to blog.’ is closed to new replies.