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

Pagination does not work with new Timber\Post() #1992

Closed
ttsuru opened this issue May 10, 2019 · 3 comments
Closed

Pagination does not work with new Timber\Post() #1992

ttsuru opened this issue May 10, 2019 · 3 comments
Labels

Comments

@ttsuru
Copy link

ttsuru commented May 10, 2019

Expected behavior

{{ paged_content }} works with new Timber\Post()

Actual behavior

{{ paged_content }} with new Timber\Post() shows the full text of the article.

Steps to reproduce behavior

Don't work

// single.php
$context = Timber::context();
$context['post'] = new Timber\Post();
Timber::render('single.twig', $context);
{# single.twig #}
<article>
    <h1 class="headline">{{post.title}}</h1>
    <div class="body">
        {{post.paged_content}}
    </div>
</article>

Work

// single.php
$context = Timber::context();
$context['post'] = Timber::query_post();
Timber::render('single.twig', $context);
{# single.twig #}
<article>
    <h1 class="headline">{{post.title}}</h1>
    <div class="body">
        {{post.paged_content}}
    </div>
</article>

What version of WordPress, PHP and Timber are you using?

Timber 1.9.4

How did you install Timber? (for example, from GitHub, Composer/Packagist, WP.org?)

Composer/Packagist

@ttsuru
Copy link
Author

ttsuru commented May 10, 2019

I think global $page is not set with call new Timber\Post().

	/**
	 * @return string
	 */
	public function paged_content() {
		global $page;
		return $this->content($page, -1);
	}

@ttsuru ttsuru changed the title Pagination does not work properly with new Timber\Post() Pagination does not work with new Timber\Post() May 14, 2019
@aj-adl
Copy link
Contributor

aj-adl commented Jun 7, 2019

@ttsuru the pagination of content in the built-in WordPress way relies heavily on globals and WP_Query::setup_postdata(). For the 2.x branches (where get_post et al. will no longer exist), this is fixed with Timber\Post::setup(), but in this case, the easiest out is probably to continue using \Timber::query_post() for now on a 1.9.x project as this returns a QueryIterator that will handle all this for you automatically.

@gchtr / @jarednova / @palmiak Possibly a todo for the 2.x . docs? Paginated content works provided the users uses the 'magic' $context['post'], but the docs should probably mention that it calls Post::setup and that a developer should call this if they want parity in function.

@gchtr
Copy link
Member

gchtr commented Jun 7, 2019

@aj-adl The only place where Timber\Post::setup() is mentioned now is in https://github.com/timber/timber/blob/2.x/docs/guides/context.md#using-a-custom-post-class.

@Levdbas Levdbas added the docs label May 12, 2023
@Levdbas Levdbas closed this as completed Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants