Php 自定义post类型循环
我需要一些关于这个剧本的指导 我正在处理一个自定义的post类型循环,但我一直在研究如何将这个静态html转换为php循环Php 自定义post类型循环,php,wordpress,custom-post-type,Php,Wordpress,Custom Post Type,我需要一些关于这个剧本的指导 我正在处理一个自定义的post类型循环,但我一直在研究如何将这个静态html转换为php循环 <?php $loop = new WP_Query(array('post_type' => 'project', 'posts_per_page' => -1)); $count =0; ?> <!--Text Sliders--> <div class="ps-contentwrapper">
<?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 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>
<?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>