我需要有关此脚本的一些指导。
我正在开发一个自定义帖子类型循环,但我一直坚持如何将此静态 html 转换为 php 循环
<?php
$loop = new WP_Query(array('post_type' => 'project', 'posts_per_page' => -1));
$count =0;
?>
<!--Text Sliders-->
<div class="ps-contentwrapper">
<?php if ( $loop ) :
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
$terms = get_the_terms( $post->ID, 'tagproject' );
if ( $terms && ! is_wp_error( $terms ) ) :
$links = array();
foreach ( $terms as $term )
{
$links[] = $term->name;
}
$links = str_replace(' ', '-', $links);
$tax = join( " ", $links );
else :
$tax = '';
endif;
?>
<?php $infos = get_post_custom_values('_url'); ?>
<div class="ps-content">
<h2><?php the_title(); ?></h2>
<p><?php echo get_the_excerpt(); ?></p>
</div><!--end of ps-content-->
</div><!-- /ps-contentwrapper -->
<!--Image Sliders-->
<div class="ps-slidewrapper">
<div class="ps-slides">
<?php
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<div style="background-image: url(<?php echo $url; ?>);"></div>
</div>
<?php endwhile; else: ?>
<?php endif; ?>
<nav>
<a href="#" class="ps-prev" style="background-image: url(images/home/1.jpg);"></a>
<a href="#" class="ps-next" style="background-image: url(images/home/2.jpg);"></a>
</nav>
我想弄清楚的是如何动态排列所有内容。如果有人能指出我正确的方向,我将不胜感激。
我使用上面粘贴的当前代码的版本。
编辑:经过一番研究,这是我的代码。现在,我试图弄清楚如何将特色图像与适当的帖子相匹配,因为它在此脚本中循环播放。与 url 相呼应的 div 标签需要循环多次并适当地循环。
<div class="ps-slides">
<?php
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<div style="background-image: url(<?php echo $url; ?>);"></div>
</div><!--end of ps-slides-->
完整代码如下:
<div class="ps-contentwrapper">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="ps-content">
<h2><?php the_title(); ?></h2>
<p><?php echo get_the_excerpt(); ?></p>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div><!--end of contentwrapper-->
<!--Image Sliders-->
<div class="ps-slidewrapper">
<div class="ps-slides">
<?php
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<div style="background-image: url(<?php echo $url; ?>);"></div>
</div><!--end of ps-slides-->
<nav>
<?php
$prev_post = get_previous_post();
$id = $prev_post->ID ;
$permalink = get_permalink( $id );
$prev_url = wp_get_attachment_url( get_post_thumbnail_id($id) );
?>
<a href="#" class="ps-prev" style="background-image: url(<?php echo $prev_url; ?>);"></a>
<?php
$next_post = get_next_post();
$nid = $next_post->ID ;
$permalink = get_permalink($nid);
$next_url = wp_get_attachment_url( get_post_thumbnail_id($nid) );
?>
<a href="#" class="ps-next" style="background-image: url(<?php echo $next_url; ?>);"></a>
</nav>
</div>