RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-269155

Алексей's questions

Martin Hope
Алексей
Asked: 2020-04-21 12:16:35 +0000 UTC

转换在 Chrome 中不起作用:悬停在使用 CSS 变量样式的多色图标上

  • 3

有一个 svg 图标,使用<use>. 有必要使用 实现从一种颜色到另一种颜色的平滑过渡:hover。图标由几个元素组成,每个元素都应该将颜色更改为某个特定的颜色,因此表单的 css 构造在这里不起作用

svg { fill: #ddd; transition: .25s; }
svg:hover { fill: #ddd; }

下面实现了一个最小的示例。ps如果你用FF检查,那么一切正常,但在chrome和opera中这是一个问题

:root {
  --color: #33d;
  --color-bg: #99b;
}

svg {
  width: 30px;
  height: 30px;
}

circle, path {
  transition: 0.25s;
}

svg:hover {
  --color: #d33;
  --color-bg: #d99;
}
<div style="display: none;">
  <svg id="play" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
    <circle cx="11" cy="11" r="11" fill="var(--color)"/>
    <circle cx="11.0001" cy="11.0001" r="9.9" fill="var(--color-bg)"/>
    <path d="M8.7998 13.4619V8.4001C8.7998 7.61556 9.66199 7.13657 10.3281 7.55104L14.1245 9.91323C14.7308 10.2905 14.7577 11.1634 14.1757 11.5772L10.3793 14.2769C9.71725 14.7477 8.7998 14.2743 8.7998 13.4619Z" fill="var(--color)"/>
  </svg>
</div>

<svg>
  <use xlink:href="#play"></use>
</svg>

css
  • 1 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-02-07 17:19:02 +0000 UTC

如何按条件禁用对swiper js的滑动?

  • 1

有 swiper js,您可以在工作时更改参数。在这种情况下,如果所有幻灯片都适合容器,我需要关闭 `` 参数,否则将其打开。

const sounds = new Swiper('.sounds .tabs-list', {
    init: false,
    slidesPerView: 'auto',
    spaceBetween: 30,
    allowTouchMove: true,
});

sounds.on('init resize', () => {
    const tabs = sounds.el.querySelectorAll('.tabs-list__item');
    const widthSoundsTabs = [...tabs].reduce((total, tab) => total + tab.offsetWidth, 0) + (sounds.params.spaceBetween * (tabs.length - 1));

    if( widthSoundsTabs > sounds.el.offsetWidth && !sounds.params.allowTouchMove) {
        sounds.params.allowTouchMove = true;
    } 

    if(widthSoundsTabs <= sounds.el.offsetWidth && sounds.params.allowTouchMove) {
        sounds.params.allowTouchMove = false;
    }
});

sounds.init();

参数改变,但没有反应,更准确地说,滑块对鼠标或手指的滑动做出反应并做出反应

javascript
  • 1 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-10-17 10:25:30 +0000 UTC

在整页插件中禁用时如何在内部元素中保留滚动?

  • 2

整个页面是在fullpage插件上制作的。该页面有模态窗口,里面有滚动的块。现在,当打开一个模态窗口时,我相应地用 方法阻止了页面的滚动setAllowScrolling(),但是有了它,鼠标上的滚动通常被禁用,是否有可能以某种方式绕过这个时刻?

ps 尝试调用该方法destroy('all'),但正如预期的那样,一切都被重置并且页面滚动到最开始

const myFullpage = new fullpage('#fullpage', {});

$('.modal').on('show.bs.modal', () => {
  setTimeout(() => {
    myFullpage.setAllowScrolling(false);
  }, 10);
});

$('.modal').on('hide.bs.modal', () => {
  myFullpage.setAllowScrolling(true);
});
.section {
  text-align:center;
  font-size: 3em;
}

p {
  height: 200px;
  overflow-y: auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://rawgit.com/alvarotrigo/fullPage.js/master/dist/fullpage.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<div id="fullpage">
    <div class="section">
      <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
        Запустить модальное окно
      </button>
    </div>
    <div class="section">
        <div class="slide" data-anchor="slide1">Two 1</div>
        <div class="slide" data-anchor="slide2">Two 2</div>
    </div>
    <div class="section">
      <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
        Запустить модальное окно
      </button>
    </div>
    <div class="section">Four</div>
</div>

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <p>
        Lorem ipsum dolor sit amet consectetur, adipisicing elit. Libero, maiores! Quod eligendi distinctio, corporis dignissimos doloribus qui neque ipsum non magni, adipisci suscipit ullam sapiente facere odit? Atque, praesentium necessitatibus?
    Quam tenetur eaque, deserunt accusamus labore sunt ab! Provident tempora veritatis facere quibusdam ea a nam accusamus voluptas? Accusantium id ipsa omnis accusamus ab aliquid perspiciatis recusandae ipsum corporis dolor.
    Distinctio fugit esse enim hic consectetur fuga et perspiciatis corrupti tempora dolore nam officia nihil saepe quibusdam illum vero, sequi autem accusantium aliquid voluptatem iusto possimus minima iste architecto? Fugit.
        </p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

javascript
  • 2 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-10-01 17:46:50 +0000 UTC

在输入字段中输入前缀

  • 0

页面是vue写的,我想在输入框的时候输入纯文本,但是同时在同一个地方会自动替换一些常量。即,我开始输入,subdomain比方说,它已经出现在第一个字母之后的输入中subdomain.domain.io。同时,将插入符号放在我们替换的常量前面,这样我们就不会经常戳鼠标。我画了这个选项,我把它挂在输入事件上,但是我的马车跳到所需的点或结尾,最后出现了一个不需要的字母。

const textField = {
  props: {
    name: {
      type: String,
      required: true
    },
    type: {
      type: String,
      default: 'text'
    },
    label: String,
    value: { 
      required: false
    },
  },
  computed: {
    model: {
      get() {
        return this.value;
      },
      set(value) {
        this.$emit('input', value);
      },
    },
  },
  template: `
    <div class="form-group">
      <label class="form-control-label">{{ label }}</label>
      <div class="input-group input-group-merge">
        <input 
          :type="type" 
          class="form-control" 
          :id="'input-' + name" 
          v-model="model">
      </div>
    </div>`,
}

new Vue({
  el: '#app',
  components: {
    'text-field': textField,
  },
  data() {
    return {
      form: {
        slug: null,
      }
    }
  },
  methods: {
    inputSlug() {
      const slug = this.form.slug.split('.');
      if( slug[0] ) {
        this.form.slug = slug[0] + '.domain.io';
      } else {
        this.form.slug = null;
      }
      document.getElementById('input-slug').focus();
      document.getElementById('input-slug').setSelectionRange(slug[0].length, slug[0].length);
    },
  }
})
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.0"></script>
<div id="app">
  <text-field @input="inputSlug" name="slug" v-model="form.slug"/>
</div>

javascript
  • 1 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-10-01 13:57:05 +0000 UTC

在vue中的路由之间传递查询

  • 0

是否有可能以某种方式在路由之间传输查询字符串,即 在 ? 之后的 url 中的所有内容。例如,假设你第一次进入应用程序时有一个路由/route1?q=true,如果有q,我将它保存在商店中。现在我希望路线发生任何变化,我会留下 q (已经设置了其他参数的路线)。现在我是这样实现的,我在 App.vue 中注册了它

created() {
    this.$router.beforeEach((to, from, next) => {
    this.SET_LOADED(true);
        setTimeout(() => {
            const routeTo = {
                name: to.name,
                params: to.params,
                meta: to.meta,
                query: {
                    ...to.query,
                    debug: this.debug ? true : null,
                },
            }
            next(routeTo)
        }, 500);
    });
},

但正如预期的那样,它不起作用,会发生无休止的重定向(尽管我不明白为什么)。是否有可能以某种方式在整个项目的一个地方实现这一点,而不是为每个链接添加额外的参数

vue.js
  • 1 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-04-03 11:05:51 +0000 UTC

绘制渐变

  • 1

是否可以在这种元素上实现渐变

在此处输入图像描述

这里既有切角,有从暗到亮的线性渐变,也有颜色变化,线条重复 5 个像素。

或者根本不理会这些垃圾并将背景插入为png?

css
  • 1 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-07-27 13:49:56 +0000 UTC

延迟对象的工具提示

  • 5

附近有几个物体,指向它们中的每一个都会出现一个带有动画的提示(一个列表ul,它们li一个接一个地平滑出现)。由于有很多元素并且用户可以快速超越它们,我决定以debounce(f, 150ms). 但是现在,如果您将鼠标随机移动到对象上并且原则上不与任何东西交互,则会出现最后一个受影响对象的提示(这是合乎逻辑的),因为它的debounce工作时间比工作时间晚.stop().fadeOut(). 并且有时会出现一个bug,如果你拉手,例如从一个对象到另一个对象(我这里没有重新创建它,也许有人会弄清楚,如果没有,我会尝试举个例子),然后提示出现在光标下,但由于它与 object 重叠,这表明它立即消失并且鼠标再次位于对象上,提示出现并且一切都在循环中。

function debounce(f, ms) {
    let timer = null;
    return function (...args) {
        const onComplete = () => {
            f.apply(this, args);
            timer = null;
        }
        if (timer) {
            clearTimeout(timer);
        }
        timer = setTimeout(onComplete, ms);
    };
}

function renderHint() {
    $('#hint').stop().append('123').fadeIn('100');
}

let renderHintDebounce = debounce(renderHint, 150);
$('.block').on('mouseenter', function(e) {
  $('#hint').empty();
  $(this).mousemove(function(pos) {
    $("#hint")
      .css('left', (pos.pageX + 50)+'px')
      .css('top', (pos.pageY - 30)+'px');
  });
  renderHintDebounce();
});
$('.block').on('mouseleave', function(e) {
  $('#hint').stop().fadeOut(100).queue(function() {
    $(this).empty().dequeue();
  })
});
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 100vw;
}

.block {
  width: 100px;
  height: 100px;
  background: red;
}

#hint {
  position: absolute;
  display: none;
  background: #eee;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
  <div class="block"></div>
</div>
<div id="hint">123</div>

添加. 如果工具提示没有按位置添加,即 添加 50 和 30 像素,然后工具提示出现和消失的错误与我的错误相似。

javascript
  • 2 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-07-09 10:24:01 +0000 UTC

通过文件上传从表单中收集数据

  • 1

有必要从表单中收集有关文件的数据,以便通过 AJAX 将其进一步传输到服务器。

<form id="upload-docs" name="uploadDocs">
  <div class="field-upload">
    <label for="file1">Файл1:</label>
    <input id="file1" name="file1" type="file" accept=".xlsx,.xls,image/*,.doc, .docx,.ppt, .pptx,.txt,.pdf">
  </div>
  <div class="field-upload">
    <label for="file2">Файл 2:</label>
    <input id="file2" name="file2" type="file" accept=".xlsx,.xls,image/*,.doc, .docx,.ppt, .pptx,.txt,.pdf">
  </div>
  <input type="submit" value="Загрузить файлы">
</form>

我以这种方式收集数据

$('form#upload-docs input').each(function() {
   formData.append(this.name, $(this).prop('files')[0]);
});

如果您从每个输入中单独收集,即

formData.append('file1', $('file1').prop('files')[0]);
formData.append('file2', $('file2').prop('files')[0]);

这一切都有效。如果我通过each那么结果是错误的Uncaught TypeError: Cannot read property '0' of null。

理想情况下,您需要以对象的形式收集数据,以便服务器进行这样的调用files['file1'][name]。

javascript
  • 1 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-07-08 18:55:10 +0000 UTC

从表单中形成数据以通过 AJAX 提交

  • 2

有一个表格

<form id="upload-docs" name="uploadDocs">
  <div class="field-upload">
    <label for="file1">Файл1:</label>
    <input id="file1" name="file1" type="file" accept=".xlsx,.xls,image/*,.doc, .docx,.ppt, .pptx,.txt,.pdf">
  </div>
  <div class="field-upload">
    <label for="file2">Файл 2:</label>
    <input id="file2" name="file2" type="file" accept=".xlsx,.xls,image/*,.doc, .docx,.ppt, .pptx,.txt,.pdf">
  </div>
  <input type="submit" value="Загрузить файлы">
</form>

我正在尝试收集这样的数据

$('#upload-docs').on('submit', function(event){
  event.preventDefault();
  let formData = new FormData(document.forms.uploadDocs);
});

但变量formData仍然为空。我在哪里计算错了,或者我可以以其他方式从表单中收集数据吗?

javascript
  • 1 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-06-25 09:50:46 +0000 UTC

wordpress中的ajax

  • 1

我在 WordPress 中多次使用 ajax 请求。但最近我注意到它们需要很长时间才能完成。我测量了诸如 wp-ajax 和随后的 wp-load 之类的脚本的运行时间。我意识到查询执行时间的最大份额落在了他们身上(大约 80-85% 的时间)。由此,问题出现了,是否有可能在不使用标准 wp-ajax 的情况下以某种方式减少这个时间,绕过它,然后威胁什么?或者也许使用它,但也许以某种方式优化它的工作?

php
  • 1 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-06-21 12:42:16 +0000 UTC

通过 WP 中的过滤器从分类学中获取价值

  • 0

有 2 种自定义帖子类型,都附有相同的分类。是否有可能以某种方式获取特定帖子类型中使用的分类值。只想到乡下人代码 -> 获取所有帖子,按帖子 ID 获取类别,如果还没有,则将其添加到数组中。

php
  • 1 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-06-18 17:50:29 +0000 UTC

ajax 请求中止

  • 0

单击按钮时,会调用一个函数,在该函数中调用并执行 ajax 请求。理论上,还有另一个按钮应该重置此请求以及在成功/失败的情况下发生的所有事情。

let xhr;
$(document).on('click', '.object-item', function (e) {
    constructAppartmentModal($(e.target).closest('.object-item').attr('data-id-apartment'));    
});

function constructAppartmentModal(id) {
    destructAppartmentModal();
    dataRequest = {
    idAppartment: id
};
dataRequest = JSON.stringify(dataRequest);
dataAjax = {
    action: 'wp_construct_appartment',
    dataRequest: dataRequest
}
xhr = $.get(ajax_object.ajax_url, dataAjax).then((response) => {
    // success
}, (response) => {
    //  error
});

$('body').on('click', '.close', function() {
    xhr.abort();
})

此代码不起作用,如何进行中断?

javascript
  • 1 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-06-07 18:51:00 +0000 UTC

解析svg文件

  • 0

有几个svg文件,格式如下

<svg version="1.1" id="floor" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1170 689" style="enable-background:new 0 0 1170 689;" xml:space="preserve">
    <path fill="#bbbbbb" id="1_1" stroke="none" opacity="1" d="M336,81 336,45 176,45 176,103 176,299 289,299 311,299 336,299 440,299 440,81Z"/>
    <path fill="#bbbbbb" id="1_2" stroke="none" opacity="1" d="M598,365 598,616 440,616 440,583 440,365Z"/>
    <path fill="#bbbbbb" id="1_3" stroke="none" opacity="1" d="M277,365 284,365 289,365 440,365 440,583 284,583 284,616 176,616 176,587 176,365Z"/>
    <path fill="#bbbbbb" id="1_4" stroke="none" opacity="1" d="M289,299 289,365 284,365 277,365 176,365 176,587 26,587 26,103 176,103 176,299Z"/>
    <path fill="#bbbbbb" id="1_5" stroke="none" opacity="1" d="M911,365 1016,365 1016,583 1131,583 1131,109 1016,109 1016,299 911,299Z"/>
    <path fill="#bbbbbb" id="1_6" stroke="none" opacity="1" d="M754,583 911,583 911,616 1016,616 1016,583 1016,365 911,365 754,365Z"/>
    <path fill="#bbbbbb" id="1_7" stroke="none" opacity="1" d="M858,81 754,81 754,299 858,299 893,299 911,299 1016,299 1016,109 1016,45 858,45Z"/>
    <path fill="#bbbbbb" id="1_8" stroke="none" opacity="1" d="M754,583 754,616 598,616 598,365 754,365Z"/>
</svg>

有什么方法可以解析 php.ini 中的路径吗?有必要填写数组中键所在的数组id,值d?

php
  • 1 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-05-30 13:21:19 +0000 UTC

将按钮添加到 wordpress 帖子的编辑部分

  • 0

是否可以在特定帖子类型的编辑器中添加按钮。我想在单击发生事件时添加一个按钮,好吧,让它发送一封包含此帖子内容的电子邮件。wordpress 有这个功能吗?

php
  • 2 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-05-29 00:49:31 +0000 UTC

根据 wordpress 中的时间表批量更新帖子中的字段

  • 0

有一个自定义记录类型,其中存储了 14 条记录,(从周一到周日的第一周和从周一到周日的第二周)每条记录都有一个“周数”字段 - 1 或 2,并且使用 acf 转发器是created,在该行中有名称和2个数字字段,第一个是不断变化的,第二个字段是您需要根据时间表根据第一个字段将值带到的字段(例如,一次小时)。我使用 wp_cron,结果是这样的。

$parameters = array(
    'post_type_schedule' => 'schedule'
);
if( !wp_next_scheduled( 'hook_update_schedule_everyweek',  $parameters ) )
    wp_schedule_event( time(), 'user_everyweek', 'hook_update_schedule_everyweek', $parameters );

add_action( 'hook_update_schedule_everyweek', 'update_schedule', 99, 1 );

function update_schedule( $post_type_schedule) {
    // здесь получаю 7 из 14 постов где номер недели предыдущий (в данном случае 1)
    $prev_week = 1;
    $posts_last_week = new WP_Query(array(
        'post_type' => 'schedule',
        'posts_per_page' => -1,
        'meta_query' => array(
            array(
                'key' => 'number-week',
                'value' => $prev_week
            )
        )
    ));
    // дальше нужно каким то образом пробежаться по массиву всех строк по всем постам и заменить значение
    // взяв из count в той же строке и записать в remain
    foreach ($posts_last_week->$posts as $post_i => $post) {
        setup_postdata($post);
        $i = 0;
        while (have_rows('schedules', $post->ID)) {
            the_row();
            $row = get_row();
            $i++;
            $row['remain'] = get_sub_field('count');
            update_row('schedules', $i, $row);
        }
    } 
    wp_reset_postdata();
}

我使用 acf 插件,要么我不知道如何更新中继器中的字段,要么使用它的方法根本不可能做到这一点。告诉我如何做到这一点?

wordpress
  • 1 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-05-04 14:44:24 +0000 UTC

通过插件在活动的 Wordpress 主题中创建页面

  • 0

激活插件时,需要在管理面板中创建一个带有快捷方式的页面,slug并在活动主题目录中创建其模板(即名称为 的文件page-slug.php)。我像这样在管理面板中创建一个页面

$post_data = array(
    'post_type'     => 'page',
    'post_name'     => 'schedule',
    'post_title'    => 'Страница с расписанием',
    'post_content'  => '',
    'post_status'   => 'publish',
    'post_author'   => 2,
);
$post_id = wp_insert_post( wp_slash($post_data) );

更有趣的是,如何在活动主题中创建文件或如何将文件从插件链接到主题中的页面?

我脑子里有一种方法,类似于下面的方法(但似乎有一个更正确的方法)。在有插件的目录中创建一个文件,并将其写入所需的主题(但是有某种游戏,我无法编写新文件)

$c = file_get_contents('page-schedule.txt');
file_put_contents('page-schedule.php', $c);

ps如果发生这种方法,那么如何找出活动主题的目录?

php
  • 2 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-02-07 16:56:22 +0000 UTC

使用 ajax 在 WP 中显示帖子组

  • 0

我有一个包含 5 个帖子的页面。

<?php 
 // Верстка слайда в слайдер статей на главной странице
 function html_article_list_item() {
     global $post;
     $title = get_the_title();
     $permalink = get_permalink();
     $excerpt = get_the_excerpt();
     $date  = get_the_date('d F Y');
     $id_img_post = get_post_thumbnail_id();
     $img_post = wp_get_attachment_image($id_img_post, 'size_article_list');
     $tags = wp_get_post_tags($post->ID);
     ?>
     <li class="articles-item">
         <a href="#">
             <div class="articles-item-img"><?php echo $img_post; ?></div>
             <div class="articles-item-content">
                 <div class="articles-item-content-title"><?php echo $title; ?></div>
                 <div class="articles-item-content-date"><?php echo $date; ?></div>
                 <div class="articles-item-content-description"><?php echo $excerpt; ?></div>
                 <ul class="articles-item-content-tags">
                     <?php foreach( $tags as $tag ): ?>
                         <li class="articles-item-content-tag"><?php echo $tag->name; ?></li>
                     <?php endforeach; ?>
                 </ul>
             </div>
         </a>
     </li>
 <?php
 }
 ?>

 <div class="section-articles">
     <div class="articles-container container">
         <div class="row">
             <div class="col-12 col-md-9">
                 <ul id='articles-list' class="articles-list">
                     <?php 
                     $posts = get_posts(array(
                         'numberposts' => 5,
                         'post_type' => 'article',
                     ));
                     foreach ($posts as $post):
                         setup_postdata( $post );
                         html_article_list_item();
                     endforeach; 
                     wp_reset_postdata();
                     ?>
                 </ul>
             </div>

             <?php 
             $arr_tags = get_terms(array(
                 'taxonomy' => array('tagarticle'),
                 'orderby' => 'name',
                 'order' => 'ASC',
                 'get' => 'all',
             ));
             ?>

             <div class="articles-tags d-none d-md-block col-md-3">
                 <div class="articles-tags-title">Теги:</div>
                 <ul class="articles-tags-list">
                     <?php foreach( $arr_tags as $arr_tag ): ?>
                         <li class="articles-tags-list-item <?php if($arr_tag->count > 0) echo 'articles-tags-list-item__active'; ?>"><?php echo $arr_tag->name ?></li>
                     <?php endforeach; ?>
                 </ul>
             </div>
         </div>
         <div class="download-button row">
             <button class="transition-300ms">Загрузить еще</button>
         </div>
     </div>
 </div>

现在我需要.download-button button在“加载更多”按钮上显示另外 5 篇文章(记录)。将此代码添加到 function.php 文件中:

add_action('wp_enqueue_scripts', 'ajax_download_last_article', 99);
function ajax_download_last_article() {
    wp_enqueue_script('script-ajax', get_template_directory_uri() . '/js/script-ajax.js', array('jquery'));

    wp_localize_script('script-ajax', 'arrAjax', 
        array(
            'url' => admin_url('admin-ajax.php')
        )
    );  
}
function download_last_article_callback() {
    $countArticles = intval( $_POST['countArticles'] );

    if( isset($countArticles) ) {

        $posts_articles = query_posts(array(
            'numberposts' => -1,
            'post_type' => 'article',
        ));
        $articles_list = '';
        for ($i_article=$count_articles; $i_article < $count_articles+5; $i_article++) { 
            $post = $posts_articles[$countArticles];
            setup_postdata( $post );
            $articles_list = strcat( $articles_list, get_template_part('ajax/add', 'article') );
        }
        echo $articles_list;
        wp_reset_postdata();
    } else {
        echo 0;
    }

    wp_die();
}
add_action('wp_ajax_download_last_article', 'download_last_article_callback');
add_action('wp_ajax_nopriv_download_last_article', 'download_last_article_callback');

文章输出模板

<?php 
// Элемент списка статей

global $post;
$title = get_the_title();
$permalink = get_permalink();
$excerpt = get_the_excerpt();
$date  = get_the_date('d F Y');
$id_img_post = get_post_thumbnail_id();
$img_post = wp_get_attachment_image($id_img_post, 'size_article_list');
$tags = wp_get_post_tags($post->ID);
?>

<li class="articles-item">
    <a href="#">
        <div class="articles-item-img"><?php echo $img_post; ?></div>
        <div class="articles-item-content">
            <div class="articles-item-content-title"><?php echo $title; ?></div>
            <div class="articles-item-content-date"><?php echo $date; ?></div>
            <div class="articles-item-content-description"><?php echo $excerpt; ?></div>
            <ul class="articles-item-content-tags">
                <?php foreach( $tags as $tag ): ?>
                    <li class="articles-item-content-tag"><?php echo $tag->name; ?></li>
                <?php endforeach; ?>
            </ul>
        </div>
    </a>
</li>

在带有 ajax 脚本的文件中,我把这个

    var countArticles = 5;
    $('.download-button button').click(function(e) {
        e.preventDefault();
        var data = {
            'action': 'download_last_article',
            countArticles: countArticles
        };
        var this_element = $(this);
        $.post(arrAjax.url, data, function(response) {
            if(response == 3) 
                console.log('Записей больше нет.');
            else {
                alert('Получено с сервера: ' + response)
                $('#articles-list').html(response).animate({opacity: 1}, 300);
                countArticles += 5;
            }
        });
    });

一切正常,如果您注释掉收到的帖子并将输出作为对某个变量的响应,那么答案就会出现。但是,一旦我尝试输出帖子,就会收到错误 500(内部服务器错误,如果我没记错的话,就像这样)。先感谢您。

php
  • 1 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-02-02 15:36:18 +0000 UTC

wordpress 联系表单中的垃圾邮件

  • 0

如何在wp中用contact form 7插件组织垃圾邮件防护 看了很多资料后,才意识到需要安装垃圾邮件防护插件,但插件大多是付费的。我发现的第二种方法是添加一个隐藏字段,例如电子邮件(例如),然后检查它是否为空(一个人不会看到它,机器人会填充它) - 这种方法有多有效以及如何实现它,谁能告诉我?

wordpress
  • 2 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-01-26 16:04:57 +0000 UTC

<video> safari 中的 html5

  • 1

有必要以透明背景显示视频(适合您的 Alpha 通道)。我对主要的三款浏览器使用 WebM 格式,但 safari 需要不同的格式。发现这种情况下需要使用.mov格式。在没有背景的情况下进行转换,但在这种情况下,视频在任何地方都不可见(如果您在没有 的情况下选中<source src="video/AUTO_BLICK.vebm" type="video/webm">),它会在除 safari 之外的任何地方都可见的背景下进行转换。告诉我,也许还有一些其他的通用格式或者你需要转换什么参数。ps 我认为代码不会有太大帮助,但它可能有问题。

<div class="block-car">
    <a href="#main-gift">
        <div class="car">
            <video width="300" height="150" autoplay loop muted>
                <source src="video/AUTO_BLICK.mov" type="video/mov">
                <source src="video/AUTO_BLICK.vebm" type="video/webm">
            </video>
        </div>
    </a>
</div>
html5
  • 1 个回答
  • 10 Views
Martin Hope
Алексей
Asked: 2020-12-11 18:45:57 +0000 UTC

在jquery中更改css

  • 1

调整窗口大小时,元素的 css 属性不会改变。实际的js代码。如果你输入函数alert('произошло изменение'),那么它就可以工作。

$(window).on('resize', formCss());

function formCss() {
  if($(window).width() > 839) { 
    $('#otdel-kachestva .mdc-layout-grid').css('display', 'grid').css('grid-column-gap', '50px');
    $('#otdel-kachestva .name-client').parent().css('grid-column-end', 'span 6');
    $('#otdel-kachestva .number-house').parent().css('grid-column-end', 'span 6');
  } 
  if (($(window).width() > 479) && ($(window).width() < 840)) {
    $('#otdel-kachestva .mdc-layout-grid').css('display', 'grid').css('grid-column-gap', '50px');
    $('#otdel-kachestva .name-client').parent().css('grid-column-end', 'span 8');
    $('#otdel-kachestva .number-house').parent().css('grid-column-end', 'span 8');
  } 
  if($(window).width() < 479) {
    $('#otdel-kachestva .mdc-layout-grid').css('display', 'grid').css('grid-column-gap', '50px');
    $('#otdel-kachestva .name-client').parent().css('grid-column-end', 'span 4');
    $('#otdel-kachestva .number-house').parent().css('grid-column-end', 'span 4');
  }
}

`

javascript
  • 2 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5