dongrenshi0889 2018-10-11 17:13
浏览 48
已采纳

Wordpress Understrap在页面上显示帖子

I'm learning how to use wordpress API. I'm a newbie with this framework, so I've decided to install Understrap to use the Bootstrap 4 framework and create a simple portfolio website. After googling a bit, I've started experimenting with the code, but there are many aspects of this wordpress theme that are unclear to me. I want to display some posts on a page and style how they will appear using the bootstrap classes markup. Is there any valid tutorial about or anyone can suggest to me the correct modifications I need to make to the template theme files?

I've tried to create a page named postpage.php with this code inside, but it will not be recognized from wordpress as a template model for a page. CODE:

<?php

$args = array(
'posts_per_page' => 6,
'offset' => 0,
'category' => 'portfolio',
'category_name' => '',
'orderby' => 'date',
'order' => 'DESC',
'include' => '', 'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post', 'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'post_status' => 'publish',
'suppress_filters' => true
);

$myposts = get_posts( $args );

foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php
endforeach;
wp_reset_postdata();
?>
  • 写回答

2条回答 默认 最新

  • du12197 2018-10-11 17:28
    关注

    First you need to specify that this is a page template by adding the following code to the top of your file:

    <?php /* Template Name: Example Template */ ?>
    

    Then it will show up in your page template dropdown. More info about page templates here.

    In order to add Boostrap classes, you need to wrap the foreach statement in the Bootstrap containers and then change the ul to bootstrap columns:

    <div class="container">
      <div class="row">
        <?php foreach ( $myposts as $post ) : setup_postdata($post ); ?>
        <div class="col-sm-4">
          <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        </div>
        <?php endforeach; wp_reset_postdata(); ?>
      </div>
    </div>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)