php – wordpress fishpig magento安装 – getPostListHtml()

前端之家收集整理的这篇文章主要介绍了php – wordpress fishpig magento安装 – getPostListHtml()前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用第三方模块fishpig在我的magento商店安装了wordpress.

我有一个名为list.phtml的页面,它使用$this-> getPostListHtml()发布了一个类别中的所有内容.我添加了另一个div并复制了它,但现在它只是将第一个div中的帖子复制到第二个div中.如何创建一个独特的第二个div,所以当在后端发布帖子时,它只会发布到同一页面上的第二个div.目前我通过slug和post collection获得分类,然后设置顺序(asc),然后我循环通过类别和骑手为每个页面拉动相似的内容.我有几个页面,但在每个车手页面上,它仍然必须在Team下面有Team 2的帖子.我希望这是有道理的.

CPT /团队/ list.phtml

<?PHP
/**
 * Team (Rider) - Landing Page
 */
/* @var $this test_wordpress_Block_Cpt_Type_View */

/* @var $helper test_wordpress_Helper_Data */
$helper = $this->helper('wordpress');
/* @var $postType Fishpig_wordpress_Addon_CPT_Model_Type */
$postType = $this->getPostType();
$categorySlug = $this->getCurrentCategorySlug();
$allCategories = $helper->getAllCategories();

$instagramHandles = array(
    'skate' => 'testskate','surf' => 'testsurf','snow' => 'testsnow','mx' => 'testmx','testunity' => 'testunity','girls' => 'testgirls',);

$textRider = ($categorySlug == 'testunity') ? 'Ambassador' : 'Rider';
$htmlRiderPicks = $this->getChildHtml('picks');
$hasEvents = ($events = $this->getChild('events') && $this->getChild('events')->getTotal());
$_theseRiders = array();
?>
<?PHP if($categorySlug): ?>
    <?PHP $curCategory = $helper->getCategoryBySlug($categorySlug) ?>
    <?PHP $riders = $curCategory->getPostCollection()->addPostTypeFilter($postType->getPostType())->setOrder('menu_order','asc'); ?>
    <div class="team-header row">
        <div class="columns">
            <h1 class="team-page-title"><?PHP echo $this->__('Team'); ?></h1>

            <ul class="team-categories j-team-category-list">
                <?PHP foreach($helper->getTeamCategories() as $category): /* @var $category Fishpig_wordpress_Model_Post_Category */ ?>
                    <li  class="j-team-title <?PHP if($category->getSlug() == $categorySlug): ?>active<?PHP endif; ?>">
                        <a href="<?PHP echo $this->getCategoryUrl($category) ?>"><?PHP echo $helper->escapeHtml($category->getName()) ?></a>
                        <?PHP $riders = $category->getPostCollection()->addPostTypeFilter($postType->getPostType())->setOrder('menu_order','asc'); ?>
                            <div class="riders-names-list j-riders-names-list only-mobile-show">
                                <ul>
                                    <?PHP foreach($riders as $rider): /* @var $rider Fishpig_wordpress_Model_Post */ ?>
                                        <li>
                                            <a href="<?PHP echo $rider->getPermalink() ?>"><?PHP echo $helper->escapeHtml($rider->getPostTitle()) ?></a>
                                        </li>

                                    <?PHP endforeach; ?>
                                </ul>
                            </div>

                    </li>
                    <?PHP
                        if ($category->getSlug() == $categorySlug) {
                            $_theseRiders = $riders;
                        }
                    ?>
                <?PHP endforeach; ?>
            </ul>
            <div class="riders-names-list mobile-hide">
                <ul>
                    <?PHP foreach($_theseRiders as $rider): /* @var $rider Fishpig_wordpress_Model_Post */ ?>
                        <li>
                            <a href="<?PHP echo $rider->getPermalink() ?>"><?PHP echo $helper->escapeHtml($rider->getPostTitle()) ?></a>
                        </li>
                    <?PHP endforeach; ?>
                </ul>
            </div>
        </div>
    </div>

    <div id="team-panel" class="team-panel">
        <div class="riders-panel" id="Rider">
            <div class="riders-list team-riders-list">
                <div class="row">
                    <?PHP echo $this->getPostListHtml() ?>
                </div>
            </div>
        </div>
    </div>

    <br><br>
    <div class="team-header row">

    <div class="columns">
    <h1 class="team-page-title"><?PHP echo $this->__('Second Team'); ?></h1>

    <div id="second-team-panel" class="second-team-panel">
        <div class="second-riders-panel" id="Second_Rider">
            <div class="riders-list team-riders-list-second">
                <div class="row">
                    <?PHP echo $this->getPostListHtml() ?>
                </div>
            </div>
        </div>
    </div>
</div></div>
/**
     * Generates and returns the collection of posts
     *
     * @return Fishpig_wordpress_Model_MysqL4_Post_Collection
     */
    protected function _getPostCollection()
    {
        return Mage::getResourceModel('wordpress/post_collection');
    }

    /**
     * Returns the HTML for the post collection
     *
     * @return string
     */
    public function getPostListHtml()
    {
        return $this->getPostListBlock()->toHtml();
    }

    /**
     * Gets the post list block
     *
     * @return Fishpig_wordpress_Block_Post_List
     */
    public function getPostListBlock()
    {
        if (is_null($this->_postListBlock)) {
            if (($block = $this->getChild($this->_postListBlockName)) === false) {
                $block = $this->getLayout()
                    ->createBlock('wordpress/post_list',$this->_postListBlockName . rand(1111,9999))
                    ->setTemplate($this->getPostListTemplate());
            }

            $block->setWrapperBlock($this);

            $this->_postListBlock = $block;
        }

        return $this->_postListBlock;
    }

CPT /团队/渲染/ list.phtml

<?PHP
/**
 * Team (Riders) - List View Renderer
 */
/* @var $this Fishpig_wordpress_Block_Post_List_Renderer */

/* @var $helper test_wordpress_Helper_Data */
$helper = $this->helper('wordpress');
/* @var $post Fishpig_wordpress_Model_Post */
$post = $this->getPost();
$featuredImage = $post->getFeaturedImage();
/** @var test_wordpress_Helper_Image $teamHelper */
$imageHelper = $this->helper('test_wordpress/image');
$background = $imageHelper->getBackground($post);
?>
<div class="m-grid-6 columns">
    <div class="rider-list-item fade-item">
        <a class="rider-info" href="<?PHP echo $post->getPermalink() ?>" title="<?PHP echo $this->escapeHtml($post->getPostTitle()) ?>">
             <span class="post-img">
            <img class="rider-background fade-image" src="<?PHP echo $background; ?>" alt="test Riders" />
            <?PHP if ($featuredImage): ?>
                <img class="rider-photo " src="<?PHP echo $featuredImage->getImageByType('thumb-240x220') ?>" alt="<?PHP echo $this->escapeHtml($post->getPostTitle()) ?>">
            <?PHP endif; ?>
                 </span>
            <span class="rider-list-name"><?PHP echo $this->escapeHtml($post->getPostTitle()) ?></span>
        </a>
    </div>
</div>

CPT /团队/渲染/ view.phtml

<?PHP
/**
 * Team (Riders) - Post View Renderer
 *
 */
/* @var $this Fishpig_wordpress_Block_Post_View */

/* @var $helper test_wordpress_Helper_Data */
$helper = $this->helper('wordpress');
/* @var $post Fishpig_wordpress_Model_Post */
$post = $this->getPost();
$nextPost = $post->getNextPost();
$prevPost = $post->getPrevIoUsPost();
/* @var $postType Fishpig_wordpress_Addon_CPT_Model_Type */
$postType = $helper->getPostTypeByPost($post);
/* @var $parent Fishpig_wordpress_Model_Post_Category */
$parent = $post->getParentCategory();
/** @var test_wordpress_Helper_Team $teamHelper */
$teamHelper = $this->helper('test_wordpress/team');
$textRider = ($parent->getSlug() == 'testunity') ? 'Ambassador' : 'Rider';
$layoutType = $post->getCustomField('details_layout');

?>
<div class="row">
    <div class="column">
        <div class="categories-dropdown riders-dropdown">
            <div class="selectBox">
                <select onChange="setLocation(this.value);">
                    <?PHP foreach($helper->getTeamCategories() as $category): /* @var $category Fishpig_wordpress_Model_Post_Category */ ?>
                        <?PHP $selected = ($category->getId() == $parent->getId()) ? ' selected="true"' : '' ?>
                        <option value="<?PHP echo $helper->getCategoryUrl($postType,$category) ?>"<?PHP echo $selected ?>><?PHP echo $helper->escapeHtml($category->getName()) ?></option>
                    <?PHP endforeach; ?>
                </select>
            </div>
            <div class="selectBox">
                <select onChange="setLocation(this.value);">
                    <option value="<?PHP echo $helper->getCategoryUrl($postType,$parent) ?>"><?PHP echo $helper->__('All '.$textRider.'s') ?></option>
                    <?PHP $riders = $parent->getPostCollection()->addPostTypeFilter($post->getPostType());?>
                    <?PHP foreach($riders as $rider): /* @var $rider Fishpig_wordpress_Model_Post */ ?>
                        <?PHP $selected = ($rider->getId() == $post->getId()) ? ' selected="true"' : '' ?>
                        <option value="<?PHP echo $rider->getPermalink() ?>"<?PHP echo $selected ?>><?PHP echo $helper->escapeHtml($rider->getPostTitle()) ?></option>
                    <?PHP endforeach; ?>
                </select>
            </div>
        </div>
    </div>
</div>
    <div class="row artists-arrows">
        <div class="columns">
            <?PHP if ($prevPost instanceof Fishpig_wordpress_Model_Post && $prevPost->getId()): ?>
                <a href="<?PHP echo $prevPost->getPermaLink(); ?>" class="artist-prevIoUs">
                    <i class="icon-arrow-left"></i><?PHP echo $helper->__('PrevIoUs') ?>
                </a>
            <?PHP endif; ?>
            <?PHP if ($nextPost instanceof Fishpig_wordpress_Model_Post && $nextPost->getId()): ?>
                <a href="<?PHP echo $nextPost->getPermaLink(); ?>" class="artist-next">
                    <i class="icon-arrow-right"></i><?PHP echo $helper->__('Next') ?>
                </a>
            <?PHP endif; ?>
        </div>
    </div>

<div class="rider-main-info-wrapper wide-panel">
    <div class="backgrounds">
        <div class="item item_2">
            <?PHP echo $this->getLayout()->createBlock('test_wordpress/slider')->setPost($post)->toHtml(); ?>
        </div>
    </div>
    <div class="rider-main-info row">
        <div class="team-rider-details column">
            <?PHP $featuredImage = $post->getFeaturedImage();?>
            <?PHP if ($featuredImage): ?>
                <img src="<?PHP echo $featuredImage->getImageByType('thumb-240x220') ?>" class="detail-rider-image detail-thumbnail" alt="<?PHP echo $this->escapeHtml($post->getPostTitle()) ?>" />
            <?PHP endif; ?>
            <div class="team-rider-info">
                <h1 class="dark rider-name"><?PHP echo $helper->escapeHtml($post->getPostTitle()) ?></h1>
                <p class="rider-details-info">
                    <?PHP if($post->getCustomField('hometown')): ?>
                        <span><?PHP echo $helper->__('From:') ?> <?PHP echo $helper->escapeHtml($post->getCustomField('hometown')) ?></span>
                    <?PHP endif; ?>
                    <?PHP if ($post->getCustomField('birthdate') && $helper->getAgeByBirthdate($post->getCustomField('birthdate'))): ?>
                        <span><?PHP echo $helper->__('Age:') ?> <?PHP echo $helper->escapeHtml($helper->getAgeByBirthdate($post->getCustomField('birthdate'))) ?></span>
                    <?PHP endif;?>
                </p>
            </div>
        </div>
    </div>
</div>
    <div class="more-info-wrapper">
        <div class="more-info-content row">
            <div class="columns">
                <div class="rider-arrow-show js-more-content">
                    <i class="icon-arrow-down"></i>
                    <span class="more-text"><?PHP echo $helper->__('more info') ?></span>
                    <span class="less-text"><?PHP echo $helper->__('less info') ?></span>
                    <span class="more-text-mobile"><?PHP echo $helper->__('more') ?></span>
                    <span class="less-text-mobile"><?PHP echo $helper->__('less') ?></span>
                </div>
                <div class="rider-social-icons">
                    <a href="http://facebook.com/<?PHP echo $helper->escapeHtml($helper->__($post->getCustomField('facebook_handle'))); ?>" target="_blank"><i class="icon-facebook-large"></i></a>
                    <a href="http://twitter.com/<?PHP echo $helper->escapeHtml($helper->__($post->getCustomField('twitter_handle'))); ?>" target="_blank"><i class="icon-twitter-small"></i></a>
                    <a href="http://instagram.com/<?PHP echo $helper->escapeHtml($helper->__($post->getCustomField('insta_handle'))); ?>" target="_blank"><i class="icon-instagram-large"></i></a>
                </div>
            </div>
        </div>
        <div class="rider-content-wrapper">
            <div class="viewport row">
                <div class="overview">
                    <?PHP if ($layoutType != 'left'): ?>
                        <div class="more-left m-grid-8 columns personal-info">
                            <?PHP if ($post->getCustomField('birthdate') && $helper->getAgeByBirthdate($post->getCustomField('birthdate'))): ?>
                                <div>
                                    <label><?PHP echo $helper->__('Birth Date:') ?></label>
                                    <?PHP echo $helper->formatDate($post->getCustomField('birthdate'),'m/d/y'); ?><br/>
                                </div>
                            <?PHP endif; ?>
                            <?PHP echo $post->getPostContent() ?>
                        </div>
                    <?PHP endif; ?>
                    <?PHP if ($layoutType != 'right'): ?>
                        <div class="more-right m-grid-4 columns">
                            <?PHP echo $post->getCustomField('extrastats'); ?>
                        </div>
                    <?PHP endif; ?>

                </div>
            </div>
        </div>
    </div>
<?PHP $instagramContent = $teamHelper->getInstagramBlock($post); ?>
<?PHP if($instagramContent): ?>
    <div class="rider-thumb row">
            <?PHP echo $instagramContent; ?>
    </div>
<?PHP endif; ?>

<?PHP echo $this->getLayout()->createBlock('test_wordpress/products')->setPost($post)->setTitle($helper->__('%s Wears',$post->getPostTitle()))->toHtml(); ?>

<?PHP
$isShowNews = false;
$blockNews = $this->getChild('news.related');
if ($blockNews) {
    $blockNews->setTag($post->getPostTitle());
    $blockNews->setCategory($parent->getSlug());
    if ($blockNews->getPostCollection()->count()) {
        echo $blockNews->toHtml();
        $isShowNews = true;
    }
}
if (!$isShowNews) {
    $blockNews = $this->getChild('news.resent');
    if ($blockNews) {
        $blockNews->setCategory($parent->getSlug());
        echo $blockNews->toHtml();
    }
}
根据您部分发布的代码,我只能给您一个概念性答案.

根据您现在发布的内容,您可以通过两种方式合成新旧帖子之间的唯一区别:

>通过post_date,您可以调用几乎相同的函数,但最后显示的帖子的post_date作为参数,以便您可以过滤具有较新post_date的新结果.在setOrder(…)之前或之后添加一个新的闭包,或者通过更改wpQuery;
>或通过抵消.考虑到您没有回溯帖子,所有新帖子的偏移量都与初始帖子数量相等.所以你必须要setOffset($oldCount);这样您就可以从上一个显示的帖子开始获得最新帖子.

您只需要使用所需参数更新wp查询,或者找到以其他方式标记帖子的方法

> Eaiser方式是在数组$displayed_post_ids中跟踪显示的帖子ID,而不是使用post__not_in查询,如下例所示:

$args = array(
‘post_type’=> “后”,
// ……其他的args
‘post__not_in’=> array($displayed_post_ids)//不显示此帖子
);

>另一个替代方案可能是post_Meta字段.您可以通过这种方式获得更多控制权,并且您也可以将相同的旧类别用于新帖子.
您可以添加不会显示页面中的post_Meta信息,如果您的帖子已显示在第一个div中,则会跟踪这些信息.考虑更容易改变你已经拥有的帖子,你可以添加一个post_Meta _wasDisplayed(使用类似update_post_Meta($post_id,’_ wasDisplayed’,true);当你在第一个div中显示帖子也可以做到这一点)

您可以为创建时的所有帖子设置该post_Meta值的默认false值.这将有助于您进行查询.
在第二个div上,您将调用生成函数并检查您的帖子是否具有post_Meta以及它是否为false.

如果需要,您也可以稍后重置post_Meta值.

对于实现,还需要知道您打算显示多少帖子,如果您使用分页和其他可能使您的工作更复杂的小细节.

注意 – 此案例解决方案:

5.由于您的业务逻辑似乎更多地与类别相关,因此有一个更直接的解决方案:
添加新帖子的支持流程上,为每个新帖子分配一个附加类别(称为“新未显示帖子”),此类别将用作第二个div中的过滤器参数.
考虑到你必须从你从第一个div调用getPostListHtml()时发布的所有帖子中删除此类别,否则你将在第二个div中有不需要的帖子.

您可以使用wp查询对象的类别参数之一在包装函数中实现此目的:

Category Parameters

显示与特定类别相关的帖子.

cat (int) - use category id.
category_name (string) - use category slug.
category__and (array) - use category id.
category__in (array) - use category id.
category__not_in (array) - use category id.

希望能帮助到你,Codrut,KMM

原文链接:https://www.f2er.com/php/137038.html

猜你在找的PHP相关文章