【发布时间】:2017-10-03 22:42:46
【问题描述】:
我的网站上有这个页面(我从另一个开发者那里继承的)-http://ideedev.co.uk/newseed/brand/
如果您向下滚动到粉色条之外,您将看到“我们的作品”部分。这是一个投资组合自定义帖子类型。
目前实现这些的代码是这样的:
<section id="scroll-target" class="wrapper">
<?php
$portfolio_args = array(
'post_type' => 'portfolio',
'portfolio-category' => get_field('category_to_show'),
'posts_per_page' => -1
);
$portfolio = new WP_Query($portfolio_args);
while($portfolio->have_posts()) {
$portfolio->the_post();
$post = new SeedPost(get_the_ID());
$post->display(true);
}
wp_reset_query();
?>
</section>
投资组合项目显示为类实现的两个连续:'item--two'
我希望通过将每个项目的类更改为“item--three”来以 3 行显示这些项目,这在我在浏览器中编辑它时会起作用...
问题是,我在我的代码中找不到这个类的分配位置!我在浏览器中看到它,但正如您从顶部的代码中看到的那样 - 那里没有类。
我检查了 .js 文件,看看我是否可以看到它是动态分配的,但我根本看不到它在哪里......有人有什么想法吗?
更新...
我认为它可能来自这里,但我不确定在哪里更改以更改投资组合以显示在三列中...
<?php
class SeedPost {
public $post_id;
public $post_type;
function __construct($post_id) {
$this->post_id = $post_id;
$this->post_type = get_post_type($this->post_id);
}
function display($twocol = false) {
global $post;
$post = get_post($this->post_id);
$cols = $twocol ? 'two' : 'three';
setup_postdata($post);
if($this->post_type == 'portfolio') {
$overlay_class = 'item__overlay--portfolio';
} else {
$overlay_class = 'item--cat-' . SeedHelpers::first_category();
}
?>
<div class="item item--<?php echo $cols; ?>">
<?php
if(has_post_thumbnail()) {
the_post_thumbnail('news-archive', array('class' => 'item--three__child'));
}
?>
<a href="<?php the_permalink(); ?>">
<div class="item__overlay <?php echo $overlay_class; ?>">
<span class="item__cat-title item__cat-title--overlay"><?php echo SeedHelpers::first_category($this->post_type); ?></span>
<h4 class="item__title"><?php the_title(); ?></h4>
<div class="item__brief">
<?php the_excerpt(); ?>
</div>
<p class="item__link"> Read </p>
</div>
</a>
</div>
<?php
wp_reset_postdata();
}
static function load_more() {
if(!isset($_GET['load_more_posts'])) {
return;
}
check_ajax_referer('load_more_posts', 'load_more_posts');
$offset = sanitize_text_field($_GET['offset']);
$posts_per_page = get_option('posts_per_page');
$query_args = array(
'post_type' => 'post',
'offset' => $offset
);
$posts = new WP_Query($query_args);
ob_start();
while($posts->have_posts()) {
$posts->the_post();
$post = new SeedPost(get_the_ID());
$post->display();
}
$output = ob_get_contents();
ob_end_clean();
$posts_used = (int)$offset + (int)$posts_per_page;
$remaining = $posts->found_posts > $posts_used ? $posts->found_posts - $posts_used : 0;
$response = array(
'posts_remaining' => $remaining,
'html' => $output
);
echo json_encode($response);
die();
}
}
【问题讨论】:
-
嗨,检查
SeedPost类中发生了什么 - 特别是该类的display()方法。我的猜测是这个类正在呼应你需要修改的标记。 -
谢谢你 - 我刚刚用一个文件更新了这个问题,我想我也缩小了范围......它看起来像在里面吗?我可以看到两个、三个、投资组合等!!
标签: javascript html css wordpress class