Wsparcie » Zaawansowane » Co drugi post pobiera złą miniature

  • Rozwiązano vertisan

    (@vertisan)


    Witam,
    Ogólnie posiadam następujący kod podstrony:

    <?php
    if ( wp_get_attachment_url( get_post_thumbnail_id($post->ID) ) ) {
        $PostThumbnail = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    } else {
        $PostThumbnail = 'http://placehold.it/1920x500';
    }
    
    ?>
    
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <header style="background: url( <?php echo $PostThumbnail; ?> );">
            <div class="container">
                <div class="page-title">
                    <h1>
                        <span><?php the_title(); ?></span>
                    </h1>
                </div><!-- /.page-title -->
            </div><!-- /.container -->
        </header>
    <?php endwhile; ?>
    <?php endif; ?>
    
    <?php $countOffers = wp_count_posts( 'offer' )->publish; ?>
    <?php $counter = 1; ?>
    <section class="offer-list">
        <div class="container">
            <?php
                $args = array( 'post_type' => 'offer', 'posts_per_page' => 50 );
                $the_query = new WP_Query( $args );
            ?>
            <?php while ( $the_query->have_posts() && $counter <= $countOffers ) : $the_query->the_post(); ?>
    
                <?php if ( $counter % 2 != 0 ): ?>
                    <?php get_template_part( 'template-parts/Offer/content', 'left' ); ?>
                <?php else: ?>
                    <?php get_template_part( 'template-parts/Offer/content', 'right' ); ?>
                <?php endif ?>
    
                <?php ++$counter; ?>
            <?php endwhile; ?>
            <?php wp_reset_postdata(); ?>
        </div><!-- /.container -->
    </section>

    A tutaj kod podstrony content-xxx.php – w obu szablonach zmienia się jedynie układ, ale problem jest tylko w szablonie ładowanym w 'else’.

    <div class="offer-item right-side">
        <div class="row vertical-align">
            <div class="col-lg-7 col-md-7 col-sm-12 col-xs-12">
                <div class="item-content">
                    <div class="item-heading">
                        <h1><?php the_title(); ?></h1>
                    </div><!-- /.item-heading -->
                    <div class="item-description">
                        <blockquote>
                            <?php the_content(); ?>
                        </blockquote>
                    </div><!-- /.item-description -->
                    <div class="item-offer-range">
                        <h3>Zakres usług</h3>
                        <ul>
                            <?php query_posts('cat=' . get_field( "offer_service-category" ) . ''); ?>
                            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                                <li>
                                    <a href="<?php echo get_permalink(); ?>" title="<?php the_title(); ?>">
                                        <?php the_title(); ?>
                                    </a>
                                </li>
                            <?php endwhile; endif; ?>
                            <?php wp_reset_query(); ?>
                        </ul>
                    </div><!-- /.item-offer-range -->
                </div><!-- /.item-content -->
            </div><!-- /.col-lg-7 col-md-7 col-sm-12 col-xs-12 -->
            <div class="col-lg-5 col-md-5 col-sm-12 col-xs-12">
                <?php var_dump( get_field( "offer_thumbnail" ) ); ?>
                <img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ); ?>" alt="" class="img-responsive pull-left" />
            </div><!-- /.col-lg-5 col-md-5 col-sm-12 col-xs-12 -->
        </div><!-- /.row -->
    </div><!-- /.offer-item -->

    Teraz w czym problem – otóż w szablonie, który jest ładowany w 'else’, pobierana jest zła miniatura wpisu, a dokładniej nie tego wpisu co trzeba ale nagłówka strony, tutaj jak to wygląda w praktyce:
    http://client.vrs-factory.pl/Evarno-pl/_cms/oferta/

    Wie ktoś może dlaczego tak się dzieje?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Wklej jeszcze kod tego content-xxx.php, gdzie się dobrze wyświetla, tak dla porównania

    Thread Starter vertisan

    (@vertisan)

    Proszę, choć jak wspomniałem – dzieje się tak tylko w przypadku, gdy warunek nie jest spełniony [else] (gdy zamienię ścieżki między sobą, to znowu jest odwrotna sytuacja, czyli prawidłowo się wyświetla po prawej a źle po lewej), więc podejrzewam, że gdzieś na poziomie query leży problem ale go nie widzę :/

    <div class="offer-item left-side">
        <div class="row vertical-align">
            <div class="col-lg-5 col-md-5 col-sm-12 col-xs-12">
                <img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ); ?>" alt="" class="img-responsive pull-right" />
            </div><!-- /.col-lg-5 -->
            <div class="col-lg-7 col-md-7 col-sm-12 col-xs-12">
                <div class="item-content">
                    <div class="item-heading">
                        <h1><?php the_title(); ?></h1>
                    </div><!-- /.item-heading -->
                    <div class="item-description">
                        <blockquote>
                            <?php the_content(); ?>
                        </blockquote>
                    </div><!-- /.item-description -->
                    <div class="item-offer-range">
                        <h3>Zakres usług</h3>
                        <ul>
                            <?php query_posts('cat=' . get_field( "offer_service-category" ) . ''); ?>
                            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                                <li>
                                    <a href="<?php echo get_permalink(); ?>" title="<?php the_title(); ?>">
                                        <?php the_title(); ?>
                                    </a>
                                </li>
                            <?php endwhile; endif; ?>
                            <?php wp_reset_query(); ?>
                        </ul>
                    </div><!-- /.item-offer-range -->
                </div><!-- /.item-content -->
            </div><!-- /.col-lg-7 -->
        </div><!-- /.row -->
    </div><!-- /.offer-item -->
    Thread Starter vertisan

    (@vertisan)

    Może opiszę bardziej o co mi chodzi:

    Struktura kategorii/postów wygląda tak:
    Kategoria
    — Podkategoria #1
    — [ posty związane z tą kategorią ]
    — Podkategoria #2
    — [ posty związane z tą kategorią ]

    Poprzez CPT mam utworzone posty jako główne punkty oferty, a w każdym z postów poprzez ACF mam przypisane ID podkategorii, która zawiera usługi w formie postów (czyli ID 'Podkategoria #x’).

    Teraz chcę w pętli wyświetlić każdą z ofert, a każda z ofert ma w sobie drugą pętlę, za pomocą której pobiera usługi z kategorii na podstawie przypisanego ID.
    Czyli mniej więcej tak to wygląda schematycznie:

    WHILE ( pobierz główne punkty oferty ) {
    – – – – -[nazwa_oferty]
    – – – – -WHILE ( pobierz usługi danej oferty ) {
    – – – – – – – -[nazwa_usługi]
    – – – – -}
    }

    <?php $recovery_post_id = $post->ID; ?>
    <div class="offer-item right-side">
    	<div class="row vertical-align">
    		<div class="col-lg-7 col-md-7 col-sm-12 col-xs-12">
    			<div class="item-content">
    				<div class="item-heading">
    					<h1><?php the_title(); ?></h1>
    				</div><!-- /.item-heading -->
    				<div class="item-description">
    					<blockquote>
    						<?php the_content(); ?>
    					</blockquote>
    				</div><!-- /.item-description -->
    				<div class="item-offer-range">
    					<h3>Zakres usług</h3>
    					<ul>
    						<?php query_posts('cat=' . get_field( "offer_service-category" ) . ''); ?>
    						<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    							<li>
    								<a href="<?php echo get_permalink(); ?>" title="<?php the_title(); ?>">
    									<?php the_title(); ?>
    								</a>
    							</li>
    						<?php endwhile; endif; ?>
    						<?php wp_reset_query(); ?>
    					</ul>
    				</div><!-- /.item-offer-range -->
    			</div><!-- /.item-content -->
    		</div><!-- /.col-lg-7 col-md-7 col-sm-12 col-xs-12 -->
    		<div class="col-lg-5 col-md-5 col-sm-12 col-xs-12">
    			<?php //var_dump( get_field( "offer_thumbnail" ) ); ?>
    			<img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id( $recovery_post_id ) ); ?>" alt="" class="img-responsive pull-left" />
    		</div><!-- /.col-lg-5 col-md-5 col-sm-12 col-xs-12 -->
    	</div><!-- /.row -->
    </div><!-- /.offer-item -->

    sprawdź

    jak pomoże to przerób query:

    <?php
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query(array(
    	'cat' => get_field( "offer_service-category" )
    ));
    ?>
    <?php if(!$wp_query->have_posts()): ?><?php endif; ?>
    <?php while ($wp_query->have_posts()) : $wp_query->the_post() ?>
    	<li>
    		<a href="<?php echo get_permalink(); ?>" title="<?php the_title(); ?>">
    			<?php the_title(); ?>
    		</a>
    	</li>
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
    Thread Starter vertisan

    (@vertisan)

    Działa super!
    Już doszedłem gdzie był błąd, dzięki za pomoc 😉

Viewing 6 replies - 1 through 6 (of 6 total)
  • Temat ‘Co drugi post pobiera złą miniature’ jest zamknięty na nowe odpowiedzi.