v2.5.2
Giriş yap

infinite scroll hakkında

kreawich
421 defa görüntülendi

Merhabalar, eklenti kullanarak wordpress'te infinite scroll özelliğini yapmaya çalışıyorum, fakat takıldığım bir nokta var,

sitede 20 kategori var ise tamamu gösteriliyor, ve aşağı kaydırdıkça aynı 20 kategori tekrar ediyor.

20 kategoriyi kendi içerisinde parçayalarak infinite scroll edemiyorum. Kullandığım eklenti benden, Tekrarlayıcı şablonu istiyor.

Aşağıdaki kodu nasıl parçayabilirim.

website

Kaynak kodu;

    // <?php
$quotes_cat_id      = get_category_by_slug( 'quotes' )->term_id;
$categories         = get_categories( array( 'parent' => $quotes_cat_id ) );
$categories_ids     = [];
$categories_objects = [];
foreach ( $categories as $category ) {
	$categories_objects[] = $category;
}
// Get Categories IDs
foreach ( $categories_objects as $category ) {
	$categories_ids[] = $category->term_id;
}
// Get Posts
$all_posts      = new WP_Query( array(
	'category__in'   => $categories_ids,
	'post_status'    => 'publish',
	'show_option_all'     => '2',
	'posts_per_page' => - 1,
) );
$all_posts      = $all_posts->posts;
$filtered_posts = [];
foreach ( $categories_objects as $category ) {
	$posts   = [];
	$counter = 1;
	foreach ( $all_posts as $index => $post ) {
		if ( $counter > 4 ) {
			break;
		}
		$post_categories = get_the_category( $post->ID );
		$cats_ids        = [];
		foreach ( $post_categories as $cat ) {
			$cats_ids[] = $cat->term_id;
		}

		$result = in_array( $category->term_id, $cats_ids );
		if ( $result ) {
			$posts[] = $post;
			//unset( $all_posts[ $index ] );
			$counter ++;
		}
	}
	$category->posts = $posts;
} ?>

	<?php
	foreach ( $categories_objects as $category ) { ?>
        <div class="c-card">
            <p class="c-card__desc">
                <a class="c-card__name" href="<?php echo get_term_link( $category->term_id ) ?>"><?php echo $category->name; ?></a>
                <span class="c-card__name__share">- Share our beautiful quote pictures on <a href="<?php echo "https://www.facebook.com/sharer.php?u=" . get_term_link( $category->term_id ); ?>" class="highlight">Facebook</a>, <a href="<?php echo "https://twitter.com/intent/tweet?url=" . get_term_link( $category->term_id ) . "&title=" . $category->name; ?>" class="highlight">Twitter</a>, and <a href="<?php echo "https://www.linkedin.com/sharing/share-offsite/?url=" . get_term_link( $category->term_id ); ?>" class="highlight">Linkedin</a></span>
            </p>
            <div class="c-card__posts">
				<?php foreach ( $category->posts as $post ) {
				    $image_alt = get_post_meta(get_post_thumbnail_id($post->ID), '_wp_attachment_image_alt', TRUE) ? get_post_meta(get_post_thumbnail_id($post->ID), '_wp_attachment_image_alt', TRUE) : get_the_title();
				    ?>
                    <div class="c-card c-card__small">
                        <div class="c-card__main">
                            <div class="c-card__thumbnail">
                                <a aria-label="<?php echo $image_alt; ?>" title="<?php echo $image_alt; ?>" href="<?php echo get_permalink( $post->ID ) ?>">
                                    <img width="297" height="167" alt="<?php echo $image_alt; ?>" class="c-card__thumbnail__img" src="<?php echo get_the_post_thumbnail_url( $post->ID, 'card-img' ) ?>" />
                                </a>
                            </div>
                            <div class="c-card__share">
                                <div class="c-social-share">
									<?php vitathemes_share_links(); ?>
                                </div>
                            </div>
                        </div>
                    </div>
				<?php } ?>
            </div>
        </div>
		<?php
	} ?>

Cevap yaz
Cevaplar (0)
Henüz kimse cevap yazmadı. İlk cevap yazan sen ol!