0
votes

I need to display multiple styles of posts; News1 and News2. The problem i am having is that i need to display each post in a different style. IE for posts that are in News1 they need to have date and share buttons but for News2 i don't need this.

I have a custom field set up to section News2 off called "Archive Category" and can use the get_post_meta for this.

My problem is just the conditional statements that should be in the posts file.

If anyone can help it would be greatly appreciated.

Thanks

1

1 Answers

0
votes

In single.php, get the custom field value, then according to the value, call different template part:

get_template_part( 'prefix', 'other-parts-of-the-file-except-extension' );

In the template part files, layout the single post/page differently.

To elaborate, the actual layout code shall be written in template part files. The single.php only checks the custom field value, and call different template part file according to the value.

Pseudo-code would be (in single.php or single-post.php or single-customposttype.php, whichever you're using):

<php
  $value=get the custom field value; // replace this with your function to get the value
  if($value=='News 1')
    get_template_part('template', 'news1'); // then you'll put layout in template-news1.php
  else
    get_template_part('template', 'news2'); // layout in template-news2.php
?>