if ( in_category( 'example' ) ) {
get_template_part( 'partials/single', 'example' );
} else {
get_template_part( 'partials/single', 'default' );
}
example
- slug вашей категорииpartials/
- папка в которой лежат template partspartials/single-example.php
- template part для этой вашей рубрикиpartials/single-default.php
- template part для всех остальных постов<article>
, содержащий статью, должен содержать класс category-example
, выведенный туда функцией post_class()
0-9
a-z
(общепринято - в нижнем регистре)-
_
SELECT * FROM pages WHERE category="some-slug"
SELECT * FROM pages WHERE category=126
. get_pages_in_category( 'some-slug' )
$object->get_pages_in_category( 'some-slug' )
. $menu_title .= ' <span class="update-count">' . $count . '</span>';
$menu_title .= ' <span class="update-count">' . get_my_count() . '</span>';
<?php
$args = array(
'post_type' => 'blog',
'posts_per_page' => 3,
'orderby' => 'rand',
'tax_query' => array(
array(
'taxonomy' => 'blogs',
'field' => 'slug', // slug or term_id
'terms' => 'bob', // string/int or array of strings/ints (see below)
// 'field' => 'term_id',
// 'terms' => array( 12, 15, 21 ),
),
),
);
$blog = new WP_Query( $args );
?>
<?php while ( $blog->have_posts() ) : $blog->the_post(); ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php
// check if the flexible content field has rows of data
if ( have_rows( 'content' ) ) :
// loop through the rows of flexible content field data
while ( have_rows( 'content' ) ) : the_row();
// check current row layout for gallery
if ( get_row_layout() == 'gallery' ) : ?>
<h1><?php the_sub_field( 'title' ); ?></h1>
<p><?php the_sub_field( 'description' ); ?></p>
// get all images in gallery
// note the get_SUB_field function - it's a SUB field of flexible content
$images = get_sub_field( 'gallery' );
// if there are some images, build output
if ( $images ) : ?>
<ul>
<?php
// Loop through all images and output them
foreach( $images as $image ): ?>
<li>
<a href="<?php echo $image['url']; ?>">
<img
src="<?php echo $image['sizes']['thumbnail']; ?>"
alt="<?php echo $image['alt']; ?>"
/>
</a>
<p><?php echo $image['caption']; ?></p>
</li>
<?php endforeach; // end images loop ?>
</ul>
<?php endif; // end images output
endif;
endwhile; // end flexible content field loop
else :
// no layouts found
endif; ?>