我需要一些关于这个脚本的指导。
我正在开发一个自定义的帖子类型循环,但我仍然坚持如何将这个静态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>
我想弄清楚的是如何动态排列所有内容。如果有人能指出我正确的方向,我很感激。
我的version,其中包含我上面粘贴的当前代码。
编辑:经过一番研究,现在是我的代码。现在我想弄清楚如何将特色图像匹配到适当的帖子,因为它在此脚本中循环。回显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>
答案 0 :(得分:1)
使用您之前的下一个帖子图片网址的代码:
<?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>