add_action( 'wp_enqueue_scripts', 'custom_scripts' );
function custom_scripts() {
// Сюда стили
wp_enqueue_style( 'newstyle', get_template_directory_uri() . '/assets/css/custom_style.min.css' );
// Сюда скрипты
wp_enqueue_script( 'newscript', get_template_directory_uri() . '/assets/js/custom_script.min.js' );
// сюда инициализацию или отдельным файлом как выше
$newscript_init = 'jQuery(function($) {
});';
wp_add_inline_script( 'newscript', $newscript_init );
}
add_action( 'wp_footer', 'the_popup_form', 1 );
function the_popup_form() { ?>
<div id="popup" class="mfp-hide popup">
<form id="popup-form" class="popup-form">
<!-- ... -->
</form>
</div>
<?php }
foreach( $categories as $individual_category ) {
if ( $individual_category->parent != 0 ) {
$category_ids[] = $individual_category->term_id;
}
}
// задаем нужные нам критерии выборки данных из БД
$args = array(
'posts_per_page' => 5,
'post_type' => 'post',
);
$query = new WP_Query( $args );
// Цикл
if ( $query->have_posts() ) {
echo '<ul>';
while ( $query->have_posts() ) {
$query->the_post();
echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
}
echo '</ul>';
} else {
// Постов не найдено
}
// Возвращаем оригинальные данные поста. Сбрасываем $post.
wp_reset_postdata();
wp_query()
, это будет работать быстрее и правильнее get_template_part()
и визуально эта функция должна быть в блоке .main-content<div class="container">
<div class="main-content">
<?php get_template_part( 'loop', 'category' ); ?>
</div>
</div>
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<header class="page-header">
<?php the_archive_title( '<h1 class="page-title">', '</h1>' ); ?>
<?php the_archive_description( '<div class="taxonomy-description">', '</div>' ); ?>
</header>
<?php
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', get_post_format() );
endwhile;
// Previous/next page navigation.
the_posts_pagination(
array(
'prev_text' => __( 'Previous page', 'twentysixteen' ),
'next_text' => __( 'Next page', 'twentysixteen' ),
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>',
)
);
else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>
</main>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
стала интересная задача создать тему Wordpress для themeforest.
как вообще создаются темы блогов с несколькими вариантами стилями для импорта
if ( get_post_type() === 'news' ) {
get_template_part( 'template-parts/news-item', get_post_format() );
} else {
get_template_part( 'template-parts/blog-item', get_post_format() );
}
$post_type = get_post_type();
if ( file_exists( get_theme_file_path( 'templates/archive/archive-' . $post_type . '.php' ) ) ) {
get_template_part( 'templates/archive/archive-' . $post_type );
} else {
get_template_part( 'templates/archive/archive-simple' );
}
<noindex>...</noindex>
, гугл его игнорируетremove_image_size()
и нарезать их заново Regenerate Thumbnails<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<header class="page-header">
<?php
the_archive_title( '<h1 class="page-title">', '</h1>' );
the_archive_description( '<div class="taxonomy-description">', '</div>' );
?>
</header><!-- .page-header -->
<?php
// Start the loop.
while ( have_posts() ) :
the_post();
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that
* will be used instead.
*/
get_template_part( 'template-parts/content', get_post_format() );
// End the loop.
endwhile;
// Previous/next page navigation.
the_posts_pagination(
array(
'prev_text' => __( 'Previous page', 'twentysixteen' ),
'next_text' => __( 'Next page', 'twentysixteen' ),
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>',
)
);
// If no content, include the "No posts found" template.
else :
get_template_part( 'template-parts/content', 'none' );
endif;
?>
</main><!-- .site-main -->
if ( isset( $_GET['id'] ) ) {
$id = $_GET['id'];
}
get_query_var()
if ( get_query_var( 'id' ) ) {
$id = get_query_var( 'id' );
}
add_filter( 'query_vars', 'add_my_var' );
function add_my_var( $public_query_vars ) {
$public_query_vars[] = 'id';
return $public_query_vars;
}
template_redirect
с помощью функции wp_redirect()
или wp_safe_redirect()
. Разбираете ссылку, проверяете необходимые условия редиректа и собираете новую ссылку. Вот шаблон:add_action( 'template_redirect', 'custom_template_redirect' );
function custom_template_redirect() {
if ( $condition ) {
wp_redirect( home_url( '/' ) );
exit();
}
}
wp_login_form()
, она выводит HTML-форму авторизации