Skip to content

Instantly share code, notes, and snippets.

View AnatoliyAkhmatov's full-sized avatar
♣️

Anatoliy AnatoliyAkhmatov

♣️
View GitHub Profile
$posts = get_posts([ 'category_name' => 'about_features', // slug или name категории
'numberposts' => '-1' ]); // кол-во постов -1 без лимита, 0 лимит заданный в админке
function post_by_slug($posts, $slug) {
for ($x = 0, $len = count( $posts ); $x < $len; $x++) {
if ($posts[$x]->post_name == $slug) {
return $posts[$x];
}
}
return false;
function add_editor_button() {
if ( ! wp_script_is('quicktags') )
return;
?>
<script type="text/javascript">
QTags.addButton( 'eg_h3', 'h3', '<h3>', '</h3>', 'h', 'Заголовок h3', 1 );
QTags.addButton( 'eg_hr', 'hr', '<hr />', '', 'h', 'Горизонтальная линия', 201 );
QTags.addButton( 'eg_pre', 'pre', '<pre lang="php">', '</pre>', 'q', 'Подсветка PHP синтаксиса', 111 );
</script>
simple 2 level menu
<?php
$menu_id = get_nav_menu_locations()['main'];
$items = wp_get_nav_menu_items($menu_id);
?>
<?php $children = false; ?>
<?php foreach ( (array) $items as $key => $item ): ?>
<?php if ($item->menu_item_parent == 0): ?>
<?php if ($children): ?>
//добавление новых кнопок в редактор start
function wph_new_buttons($buttons) {
$buttons[] = 'fontselect'; //семейство шрифтов
$buttons[] = 'fontsizeselect'; //размеры шрифтов
$buttons[] = 'styleselect'; //форматы
$buttons[] = 'cut'; //вырезать
$buttons[] = 'copy'; //копировать
$buttons[] = 'paste'; //вставить
$buttons[] = 'superscript'; //верхний индекс
$buttons[] = 'subscript'; //нижний индекс
<?php
$args = array(
'orderby' => 'ID',
'order' => 'ASC',
'post_type' => 'instructor',
'post_status' => 'publish',
);
$loop = new WP_Query( $args );
?>
<?php while ( $loop->have_posts() ) : $loop->the_post();?>
// html или tinymce
// Установим визуальный редактор, редактором по умолчанию
add_filter( 'wp_default_editor', create_function('', 'return "tinymce";') );
// Установим HTML (текстовый) редактор, редактором по умолчанию
add_filter( 'wp_default_editor', create_function('', 'return "html";') );
// function.php
function ex_add_tinymce_plugin($plugin_array) {
$plugin_array['ex_first_button'] = get_template_directory_uri()."/js/btn.js"; // Укажите имя ВАШЕГО файла
return $plugin_array;
}
function ex_register_my_first_button($buttons) {
array_push($buttons, "ex_first_button");
return $buttons;
.button
display: inline-block
border: none
color: #fff
text-decoration: none
background-color: $accent
padding: 15px 45px
font-size: 13px
text-transform: uppercase
font-weight: 600
<?php echo wp_trim_words(get_the_excerpt(), 50) ?>
history.pushState('', document.title, window.location.pathname);