[网页]:改造 Puock 主题时光轴效果

11次阅读
没有评论
时光圈是Puock主题的一个自定义页面模板,用于展示时间线风格的动态内容。template-moments.php:1-4

在现有主题时光圈功能的基础上,做了一丁点的倒腾。直接上效果演示,代码和实现过程如下:

修改之前记得先备份原文件,或创建子主题进行。

第一步:准备工作

具体操作:

  1. 在你的网站文件夹中找到 目录wp-content/themes/
  2. 创建一个新文件夹,命名为puock-child
  3. 在 文件夹中创建一个文件,命名为puock-childstyle.css
  4. 在 文件中粘贴以下内容:style.css
/*  
Theme Name: Puock Child Theme  
Template: puock  
*/

第二步:修改时光圈模板文件

你要做什么:
替换时光圈的显示方式,从原来的列表样式改成新的时间线样式。

具体操作:

  1. 找到文件wp-content/themes/puock/pages/template-moments.php
  2. 备份这个文件(复制一份到桌面,以防出错)
  3. 打开 文件template-moments.php
  4. 找到第30行到第69行的内容(就是有 的那一大段)foreach ($posts as $post)
  5. 把这部分内容替换成:
<div class="life-timeline-container">  
    <div class="timeline-line"></div>  
    <?php   
    $timeline_items = get_posts(array(  
        'post_type' => 'moments',  
        'posts_per_page' => 10,  
        'orderby' => 'date',  
        'order' => 'DESC'  
    ));  
    foreach ($timeline_items as $item):   
    ?>  
        <div class="timeline-item">  
            <div class="timeline-dot"></div>  
            <div class="timeline-card">  
                <h3 class="timeline-title"><?php echo get_the_title($item); ?></h3>  
                <p class="timeline-desc"><?php echo $item->post_content; ?></p>  
                <span class="timeline-date"><?php echo get_the_date('Y-m-d', $item); ?></span>  
            </div>  
        </div>  
    <?php endforeach; ?>  
</div>

第三步:添加新的CSS样式

你要做什么:
添加新的样式代码,让时光圈看起来像时间线。

具体操作:

  1. 在你之前创建的子主题文件夹 中wp-content/themes/puock-child/
  2. 打开 文件style.css
  3. 在已有内容下面,粘贴你提供的所有CSS代码(从 开始到最后一个 结束).life-timeline-container}

第四步:启用子主题

你要做什么:
告诉WordPress使用你的子主题。

具体操作:

  1. 登录WordPress后台
  2. 进入 “外观” → “主题”
  3. 你应该能看到一个名为 “Puock Child Theme” 的主题
  4. 点击 “启用” 按钮
正文完
 0
评论(没有评论)