php 在WordPress中使用Timber:并不是所有的帖子都显示取决于使用的浏览器

omqzjyyz  于 2022-12-17  发布在  PHP
关注(0)|答案(1)|浏览(133)

我有一个显示问题,使用木材在WordPress网站。一切都显示正确的Chrome浏览器,我可以添加文章,并有良好的显示在前端。但当我切换到火狐或Safari浏览器,最新的文章不显示。我检查了代码,以确定如果有什么东西是不是去的方式,但我没有能够找到。我试图清除缓存...没有变化。
如果有人有一个关于起源的想法,这将是伟大的。下面是我的主题的示例代码:
news-list.twig

{% import '_macros/global.twig' as global %}

{% for key, value in posts %}
    <div data-kira-timeline>
        {{ global.actu({
        'cta': options.read_more,
        'title': value.title,
        'link': value.link,
        'date': value.post_date|date('d.m.Y'),
        'content': value.content|truncate(10, true, '??')
        }) }}
    </div>
{% endfor %}
{% if limit | length < 1 %}
    <div>
        <div class="no-more-post"></div>
    </div>
{% endif %}

NewsController.php

<?php
/**
* Class name: NewsController()
*
* A controller class is composed of methods suffixed with "Action", and responsibles for the following tasks:
* - Render the correct Twig/Timber template for the current page
* - Do the business logic associated to the current page
* - Provide the datas to the Twig/Timber templates
*
*/

namespace Controllers;

use \Timber;
use \Timber\PostQuery;
use \TimberPost;

class NewsController extends AppController
{
    /**
     * __Constructor:
    *
    * Call AppController::__construct to inherit AppController useful methods
    *
    * @return void
    */
    public function __construct(){
        parent::__construct();
    }

    /**
     * Method called by Router::routing()
    *
    * ArchiveAction() method renders <news/archive.twig> and provide it some datas
    *
    * @return void
    */
    public function archiveAction(){
        $this->render('news/archive.twig', array(
            'post' => new TimberPost(),
            'posts' => new Timber\PostQuery(array('posts_per_page' => 9))
        ));
    }

    /**
     * Method called by Router::routing()
    *
    * SingleAction() method renders <news/single.twig> and provide it some datas
    *
    * @return void
    */
    public function singleAction(){
        $this->render('news/single.twig', array(
            'post' => new TimberPost()
        ));
    }

    /**
     * Method called by Router::routing()
    *
    * CategoryAction() method renders <news/category.twig> and provide it some datas
    *
    * @return void
    */
    public function categoryAction(){
        $this->render('news/category.twig', array(
            'posts' => new Timber\PostQuery(),
            'title' => single_cat_title('', false)
        ));
    }

    /**
     * Method called by Router::routing()
    *
    * tagAction() method renders <news/tag.twig> and provide it some datas
    *
    * @return void
    */
    public function tagAction(){
        $this->render('news/tag.twig', array(
            'posts' => Timber::get_posts(),
            'title' => single_tag_title('', false)
        ));
    }

    /**
     * Method called by Router::routing()
    *
    * findAllAjax() method renders all posts
    *
    * @return void
    */
    public function findAllAjax(){
        $this->ajaxRender('news/render/news-list.twig', array(
                'posts' => new Timber\PostQuery(array(
                'post_type' => 'post'
            ))
        ));
    }

    /**
     * Method called by Router::routing()
    *
    * findOneAjax() method renders one post
    *
    * @param int  $id   Post ID
    *
    * @return void
    */
    public function findOneAjax($id){
        $this->ajaxRender('news/render/news-list.twig', array(
                'posts' => new Timber\PostQuery(array(
                'post_type' => 'post',
                'p' => $id
            ))
        ));
    }

    /**
     * Method called by Router::routing()
    *
    * findByCategoryAjax() method renders list of posts of a specific category
    *
    * @param string  $category   Category slug
    *
    * @return void
    */
    public function findByCategoryAjax($category){
        $this->ajaxRender('news/render/news-list.twig', array(
                'posts' => new Timber\PostQuery(array(
                'post_type' => 'post',
                'category_name' => $category
            ))
        ));
    }

    /**
     * Method called by Router::routing()
    *
    * loadMorePostsAjax() method renders more posts from offset
    *
    * @param string  $offset   Actual number of posts
    *
    * @return void
    */
    public function loadMorePostsAjax($offset){

        $args = array(
            'offset' => $offset,
            'posts_per_page' => 9
        );

        $argsLimit = array(
            'offset' => $offset + 9 + 1,
            'posts_per_page' => 1,
        );

        $this->ajaxRender('news/render/news-list.twig', array(
            'posts' => new Timber\PostQuery($args),
            'limit' => new Timber\PostQuery($argsLimit)
        ));
    }
}
ggazkfy8

ggazkfy81#

听起来你的HTML-Output有问题,Chrome会忽略这个问题,FF和Safari则不会。不过你提供的代码片段在我看来还不错。可能是全局的一些bug。

相关问题