gpt4 book ai didi

php - wordpress fishpig magento 安装 - getPostListHtml()

转载 作者:可可西里 更新时间:2023-11-01 12:38:37 25 4
gpt4 key购买 nike

我使用第 3 方模块 fishpig 在我的 magento 商店上安装了 wordpress。

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

cpt/team/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/team/renderer/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/team/renderer/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();
}
}

最佳答案

根据您部分发布的代码,我只能给您一个概念性的答案。

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

  1. 通过 post_date,您可以调用几乎相同的函数,但使用最后显示的帖子的 post_date 作为参数,因此您可以过滤具有较新 post_date 的新结果。在 setOrder(...) 之前或之后或通过更改 wpQuery;

  2. 添加新的闭包
  3. 或通过偏移。考虑到您不会有回溯的帖子,所有新帖子的偏移量都将等于初始帖子数。所以你必须 setOffset($oldCount); 这样你就可以从最后显示的帖子开始获得最新的帖子。

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

  1. 更简单的方法是在数组 $displayed_post_ids 中跟踪显示的帖子 ID,而不是使用 post__not_in 进行查询,如下例所示:


$参数=数组(
'post_type' => 'post',
//... 其他参数
'post__not_in' => array($displayed_post_ids)//不显示这篇文章
);

  1. 另一种选择可能是 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.

希望对你有帮助科德鲁特,KMM

关于php - wordpress fishpig magento 安装 - getPostListHtml(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39476229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com