Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misplacement of loop? #1582

Closed
vespakoen opened this issue Dec 8, 2015 · 4 comments
Closed

Misplacement of loop? #1582

vespakoen opened this issue Dec 8, 2015 · 4 comments

Comments

@vespakoen
Copy link

Hey there, it looks like this loop:
https://github.com/roots/sage/blob/master/templates/content-single.php#L1
should be moved to here:
https://github.com/roots/sage/blob/master/single.php#L1

Otherwise if the content-single is used in search.php or index.php, it will become an endless loop?

First days with wordpress so I am likely wrong...

@aaemnnosttv
Copy link
Contributor

Hello and welcome to the wonderful world of WordPress with Roots!

This isn't an issue with the theme :) Questions like this are best directed at the user forum over at discourse.roots.io. Reading the docs for get_template_part() may shed some light on it for you though.

@vespakoen
Copy link
Author

I am still wondering why for search, the loop is placed in the "main template" (lacking terminoligy here)
https://github.com/roots/sage/blob/master/search.php#L10

As well as in the page "main template"
https://github.com/roots/sage/blob/master/page.php#L1

But is moved to the "sub template" for single.

Seeing the loop in the "main template" for search.php and page.php made me assume it also had to be in single.php, so I added it there, not expecting it to loop again in the "sub template".

Now I have removed the loop from the "templates/content-single.php" and moved it to "single.php"
In this loop I have:

<?php while (have_posts()):
the_post();
if (has_category(2)) {
  get_template_part('templates/content-member', get_post_type());
} else if (has_category(4)) {
  get_template_part('templates/content-promotion', get_post_type());
} else {
  get_template_part('templates/content-single', get_post_type());
}
endwhile; ?>

So besides making it more similar to search.php and page.php, it also allows for using a different template based on some condition (which is what this theme is all about?)

Looking at the get_template_part function (thanks for the links btw) it seems that it should actually be something like this:

<?php while (have_posts()):
the_post();
if (has_category(2)) {
  get_template_part('templates/content', 'member');
} else if (has_category(4)) {
  get_template_part('templates/content', 'promotion');
} else {
  get_template_part('templates/content', 'single');
}
endwhile; ?>

Will use the discussion board for future questions.

Looking forward to your response.

@retlehs
Copy link
Member

retlehs commented Dec 9, 2015

thanks for bringing this up! this was changed for page templates in #1056 and #1080

we should do the same with single.php to be consistent. want to do a PR?

@retlehs
Copy link
Member

retlehs commented Dec 31, 2015

fixed in sage 9 b24eb36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants