php 加载更多帖子模板#PHP #WordPress

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 加载更多帖子模板#PHP #WordPress相关的知识,希望对你有一定的参考价值。

<?php
/**
 * The main template file
 *
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package client-theme
 */

get_header(); ?>

	<main class="lvm-blog">
		<?php
		if ( is_home() && ! is_front_page() ) : ?>
			<header>
			</header>
				<section class="lvm-blog-posts">
					<?php
						$featured_query = new WP_Query( array('posts_per_page' => '1') );

						if( $featured_query->have_posts() ) :
							while( $featured_query->have_posts() ) : $featured_query->the_post(); ?>
							<article class="lvm-featured-post">
								<div class="featured-post-content-left">
									<h1 class="featured-post-title"><?= the_title();?></h1>
									<div class="featured-post-copy"><?php the_content('Continue reading');?></div>
									<div class="featured-post-date"><img alt="Clock" src="<?php bloginfo('template_directory');?>/images/icons/simple-clock.svg"><?php the_date('F d, Y');?></div>
								</div>
								<div class="featured-post-img">
									<?php if(has_post_thumbnail()) : $thumbnail = the_post_thumbnail(); endif; ?>
									<img src="<?php echo $thumbnail['url'];?>" alt="<?php $thumbnail['alt'];?>">
								</div>
							</article>
							<?php endwhile;
						endif;

						wp_reset_query();
					?>

					<section class="lvm-blog-articles grid" id="ajax-posts">
						<div class="grid-sizer"></div>
						<?php
						$general_query = new WP_Query( array('posts_per_page' => '6', 'offset' => '1') );
						if ( $general_query->have_posts() ) :
							/* Start the Loop */
							while ( $general_query->have_posts() ) : $general_query->the_post();

							if($wp_query->current_post !== 0) {
								get_template_part( 'template-parts/content', get_post_format() );
							} ?>


							<?php	/*
														 * Include the Post-Format-specific template for the content.
														 * If you want to override this in a child theme, then include a file
														 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
														 */


							endwhile;
							// the_posts_navigation();

							$quoteTile = get_field('quote_active', 'options');
							$lvmSubscribe = get_field('subscribe_form_active', 'options');
							$stayConnected = get_field('stay_connected_active', 'options');
							if( !empty($_COOKIE['subscribe']) ) : $subscribeCookie = $_COOKIE['subscribe']; else: $subscribeCookie = false; endif; ?>


							<?php if($quoteTile && $lvmSubscribe && $stayConnected) : ?>
								<?php $post_object = get_field('quote_post', 'options');
									if( $post_object ) :
										$post = $post_object;
										setup_postdata( $post );

								?>
									<a href="<?php the_permalink();?>">
										<div class="stamp lvm-quote-tile stamp-<?php the_field('quote_order', 'options');?>">
											<?php the_excerpt();?>
											<span><?php the_title();?></span>
										</div>
									</a>
								<?php wp_reset_postdata(); ?>
							<?php endif;?>

								<?php if(!$subscribeCookie) : ?>
									<div class="stamp lvm-stay-subscribe stamp-<?php the_field('subscribe_form_order', 'options');?>">
										<h5>Subscribe</h5>
										<p>And stay informed on the latest news!</p>
										<div class="subscribe-form-mailchimp">
											<?php echo do_shortcode( get_field('subscribe_form_shortcode', 'options') ); ?>
										</div>
									</div>
								<?php endif; ?>

								<div class="stamp lvm-stay-connected stamp-<?php the_field('stay_connected_order', 'options');?>">
									<h5>Stay Connected</h5>
								</div>
							<?php elseif($lvmSubscribe && $stayConnected && !$quoteTile) : ?>

								<?php if(!$subscribeCookie) : ?>
									<div class="stamp lvm-stay-subscribe stamp-<?php the_field('subscribe_form_order', 'options');?>">
										<h5>Subscribe</h5>
										<p>And stay informed on the latest news!</p>
										<div class="subscribe-form-mailchimp">
											<?php echo do_shortcode( get_field('subscribe_form_shortcode', 'options') ); ?>
										</div>
									</div>
								<?php endif; ?>

								<div class="stamp lvm-stay-connected stamp-<?php the_field('stay_connected_order', 'options');?>">
									<h5>Stay Connected</h5>
								
								</div>

							<?php elseif($quoteTile && $stayConnected && !$lvmSubscribe) : ?>
								<?php $post_object = get_field('quote_post', 'options');
									if( $post_object ) :
										$post = $post_object;
										setup_postdata( $post );

								?>
									<a href="<?php the_permalink();?>">
										<div class="stamp lvm-quote-tile stamp-<?php the_field('quote_order', 'options');?>">
											<?php the_excerpt();?>
											<span><?php the_title();?></span>
										</div>
									</a>
								<?php wp_reset_postdata(); ?>
							<?php endif;?>

								<div class="stamp lvm-stay-connected stamp-<?php the_field('stay_connected_order', 'options');?>">
									
								</div>

							<?php elseif($quoteTile && $lvmSubscribe && !$stayConnected) : ?>
								<?php $post_object = get_field('quote_post', 'options');
									if( $post_object ) :
										$post = $post_object;
										setup_postdata( $post );

								?>
									<a href="<?php the_permalink();?>">
										<div class="stamp lvm-quote-tile stamp-<?php the_field('quote_order', 'options');?>">
											<?php the_excerpt();?>
											<span><?php the_title();?></span>
										</div>
									</a>
								<?php wp_reset_postdata(); ?>
							<?php endif;?>

								<?php if(!$subscribeCookie) : ?>
									<div class="stamp lvm-stay-subscribe stamp-<?php the_field('subscribe_form_order', 'options');?>">
										<h5>Subscribe</h5>
										<p>And stay informed on the latest news!</p>
										<div class="subscribe-form-mailchimp">
											<?php echo do_shortcode( get_field('subscribe_form_shortcode', 'options') ); ?>
										</div>
									</div>
								<?php endif; ?>
							<?php endif;

						else :
							get_template_part( 'template-parts/content', 'none' );
						endif; ?>
					</section>

					<!-- Load More Ajax Btn -->
					<button id="more_posts" class="lvm-load-more-posts-btn">Load More</button>

				</section>


			<?php
		endif;
		?>
	</main>
<?php

get_footer();

以上是关于php 加载更多帖子模板#PHP #WordPress的主要内容,如果未能解决你的问题,请参考以下文章

使用 ajax 的重复帖子加载更多 wordpress

php 随机更多特定类别的帖子

php 自定义单个帖子模板

php 显示页面模板中的所有帖子

php Wordpress:自定义帖子模板

php 使用基于帖子格式的模板部件