WordPress.org

Ready to get started?Download WordPress

Forums

Carousel for custom fields images sequence (1 post)

  1. denaxus
    Member
    Posted 1 year ago #

    Hi,
    I'm very clumsy with Php and it's also for this that I like WP ;)
    Coming to the point: I am customizing the theme Max Magazine and would like to view a sequence of images from custom fields instead of the usual thumbnail in each post. I've tried all sorts but having Carousel already in issue at the end I'm trying to modify it to display images instead of the post.
    So I duplicate 'includes / carousel.php', I renamed 'slide_preview' and I called in content.php (which I specially modified for the grid view) as follows:

    <?php get_template_part('includes/slide_preview'); ?>

    and so far so good, is displayed.
    The problem is him projecting my images inserted as custom fields in the post instead of the post itself.
    The code slide_preview.php:

    <?php
    $carousel_cat_id = max_magazine_get_option('carousel_category');
    //if no category is selected for carousel, show latest posts
    if ( $carousel_cat_id == 0 ) {
    $post_query = 'posts_per_page=10';
    } else {
    $post_query = 'cat='.$carousel_cat_id.'&posts_per_page=10';
    }
    ?>
    
    <div id="carousel">
    <div class="title">
    <div class="cat">
    <h3>
    <?php
    if ($carousel_cat_id == 0 ) {
    _e('Latest Posts', 'max-magazine');
    } else {
    $carousel_cat_name = get_cat_name($carousel_cat_id);
    $carousel_cat_url = get_category_link( $carousel_cat_id );
    ?>
    " ><?php echo $carousel_cat_name; ?>
    <?php
    }
    ?>
    
    </h3>
    </div>
    <div class="carousel-posts">
    
    <?php query_posts( $post_query ); if( have_posts() ) : while( have_posts() ) : the_post(); ?>
    qui c'era il contenuto del post
    <?php endwhile; endif;?>
    <?php wp_reset_query();?>
    
    </div>
    </div>

    and 4 images (which are likely to grow more) entered as custom field that I were projected for each post:

    <?php $prev_img01 = get_post_meta($post->ID, 'prev_img01', true); ?>
    <img src="<?php echo $prev_img01; ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?>" />
    
    <?php $prev_img02 = get_post_meta($post->ID, 'prev_img02', true); ?>
    <img src="<?php echo $prev_img02; ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?>" />
    
    <?php $prev_img03 = get_post_meta($post->ID, 'prev_img03', true); ?>
    <img src="<?php echo $prev_img03; ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?>" />
    
    <?php $prev_img04 = get_post_meta($post->ID, 'prev_img04', true); ?>
    <img src="<?php echo $prev_img04; ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?>" />

    I hope not too much to ask, I guess that there are also other ways to make it easier. But I will treasure every board!
    Thanks in advance,
    Den

Topic Closed

This topic has been closed to new replies.

About this Topic