显示wordpress的第一个帖子

我才刚刚开始使用wordpress,所以对于你们中的一些人来说,我的问题听起来有点简单,但是我找不到如何使它起作用的方法。

我正在wordpress上构建博客页面,我想以不同于其他文章的方式显示第一篇文章,然后显示一些静态文本,然后继续第二篇文章的帖子循环。

我的第二个问题是我需要将缩略图以绝对位置放置在div内(现在,当我调整浏览器大小时,它正在怪异地缩小)。在我的引导程序原型上,我将图像放置在div中,并使用background属性导入了图像。用wordpress替换该行为的最佳方法是什么?

我为此做了一个简单的草图:

http://img.mukewang.com/60b0a57600015f3709510934.jpg

我已经搜索了stackoverflow并尝试了一些代码片段,但我无法使它们全部正常工作。

顺便说一句,我正在使用UNDERSTRAP主题作为样板。


沧海一幻觉
浏览 138回答 3
3回答

喵喔喔

您需要忘记默认的WordPress循环。请改用WP_Query类查询您的帖子。$query = new WP_Query([   ‘post_type’ => ‘post’,   ‘posts_per_page => -1,]); // Get the first post$firstElement = array_shift($query->posts); // Get the other posts exect first element$otherPosts = $query->posts;现在,您需要在模板中循环以创建帖子网格。

饮歌长啸

此过程是将标签的类别更改为全角。有很多方法可以做到这一点,但我发现这很简单。首先,从content.php中取出标签并将其放在index.php中。这是为了检查并更改article标签内的类。<div class="site-main" id="main"><div class="row no-gutters"><?php if ( have_posts() ) : ?>&nbsp; &nbsp; <?php /* Start the Loop */ ?>&nbsp; &nbsp; <?php&nbsp;&nbsp; &nbsp; // Required variables&nbsp; &nbsp; $post = $posts[0]; $c=0; ?>&nbsp; &nbsp; <?php while ( have_posts() ) : the_post(); ?>&nbsp; &nbsp; &nbsp; &nbsp; <article class="col p-0 <?php $c++; if($c == 1) { echo 'col-12'; }else{ echo 'col-4'; } ?>" <?php post_class(); ?> id="post-<?php the_ID(); ?>">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /*&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * Include the Post-Format-specific template for the content.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * If you want to override this in a child theme, then include a file&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * called content-___.php (where ___ is the Post Format name) and that will be used instead.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get_template_part( 'loop-templates/content', get_post_format() );&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ?>&nbsp; &nbsp; &nbsp; &nbsp; </article>&nbsp; &nbsp; <?php endwhile; ?><?php else : ?>&nbsp; &nbsp; <?php get_template_part( 'loop-templates/content', 'none' ); ?><?php endif; ?></div>
打开App,查看更多内容
随时随地看视频慕课网APP