Robin
Robin

Reputation: 87

How can I display posts in wordpress based on page category?

I would like to know how I can display single posts for a specific page.

ex. page url http://www.yourblog.com/services/single-service-post-title

I tried creating "single-service.php" but it redirects me to my static front page.

I have setup a page-services.php and that one works fine, but that page is designed to only show a summary of posts.

Upvotes: 0

Views: 56

Answers (1)

user1978550
user1978550

Reputation:

It's not entirely clear what you're looking for, since pages can't have single posts. They're two different things.

If you're looking for a way to create a template for a single custom post type, you can view an interactive version of the hierarchy here.

You have to name the file based on the id of the custom post type. So if the id of the post type is 'service', then 'single-service.php' would display the single post where post type equals service.

You can also place logic into your 'single.php' to say something like

if(get_post_type(get_the_ID()) == 'service'){
    // DO SERVICE-SPECIFIC STUFF HERE
}

This is usually for single custom post types that don't have their own template, but it can also be used as a fallback if that's something you're worried about.

Then you can use an else for regular post stuff and put stuff common to both outside of the if/else.

Upvotes: 1

Related Questions