php - Custom post type loop -
i need guidance on script.
i'm working on custom post type loop i'm stuck on how convert static html php loop
<?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 $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>
here tutorial i'm trying convert. demo.
what i'm trying figure out how line dynamically. if can point me right direction appreciate it.
my version of current code pasted above.
edit: here code after bit of research. i'm trying figure out how can match featured image appropriate post cycles through in script. div tag echos url needs loop many times loop , cycle appropriately.
<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-->
full code below:
<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>
use code previous next post image url:
<?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>
Comments
Post a Comment