grimesd
grimesd

Reputation: 111

Trying to understand how to add a separate blog to a word press site

This may seem more like informational question rather than a coding question but I may be wrong.

Let's say I have a site, www.xyz.com. This site is built in wordpress from a custom template. (That I will put together).

The site will showcase products with each product being input through individual posts. SO techincally speaking, It's already using the "blog" feature of wordpress.

Now I want to add a blog into my site. Let's say www.xyz.com/blog/

I could create a custom page in my theme folder called

page-blog.php

in which that would work fine.

But here is were im stumped. I want to show blog posts here that are not found on the original xyz.com page. If I use the wordpress loop on the blog page, it will show all my posts that are on the xyz page. I want to show separate posts on my blog page then the ones I show on my main page.

So my main page would have lets say, a 1000 posts of products, each product being a different post.

For my blog, I want to run the loop but not show the products posts, but show regular "blog" posts, not products. Like information, etc, etc...

I'm stumped on how I can run the loop on the blog page and have it pull in different posts that are not on my main page. Would I have to install a separate wordpress installation? I believe this would be a major hit on site performance, and also caching would be more difficult i think.

Upvotes: 0

Views: 31

Answers (2)

Savan
Savan

Reputation: 307

I understood your concern and I can say no need for extra WordPress setup and it is easily achived by creating category for example you can create category blog or product.

Now let's start with main site , if you want to show all post then nothing to do on that.

Secondly on blog you just need to get post having blog category, and this can be achieved easily by wp_query if you are writing your custom loop otherwise best way to use hook. You can use pre get post action as below,

function exclude_category( $query ) {    if ( $query->is_home() &&    $query->is_main_query() ) {    $query->set( 'cat', '-1,-1347' );  }     }
    add_action( 'pre_get_posts', 'exclude_category' );

Upvotes: 1

jaswrks
jaswrks

Reputation: 1285

So you have 'products' and you have 'posts'. Two different post types. See: https://wordpress.org/plugins/custom-post-type-ui/

  • Create a new Post Type for products.
  • Enhance your WordPress theme so it displays products differently. Note that some themes come equipped to handle custom post types automatically, while others may require you to make some minor adjustments or add additional template files.

Refer to the article at WordPress regarding Template Hierarchy.

See also: The Complete Guide to Custom Post Types

Upvotes: 1

Related Questions