Answer the question
In order to leave comments, you need to log in
How to handle categories in WordPress?
Good afternoon!
1. There is a WordPress site in which the output of news of a certain category is implemented not as it should be through a separate url of the form www.goodsite.com/category/category-name, but on the general page www.mysite.com/news (that is, all news in full and news of any category are displayed on the same page (with the same url).This was done using buttons with the names of the categories, on which jQuery is hung.If you are interested, below is the code that implements this, but the point is not in it.
function() {
$(".blog .nav-item").removeClass("this-item"), $(this).addClass("this-item");
var s = $(this).attr("data-news");
$(".block-news").removeClass("block-news_show"), $(".block-news" + s).addClass("block-news_show")
}
<?=
ot_get_option('footer_link6') // это ссылка на mysite.com/news/
. '?cats='
. $number // это айдишник категории
?>
<?php if(isset($_GET['cats'])) { ?>
<?php if( ($_GET['cats'] == 3) ) { ?>
function a() {
$('.nav-item3').click();
}
setTimeout(a, 0.3);
<script>
$(document).ready(function() {
$('.header a').css('color', '#171717');
$('.header .this-nav a').css('color', 'white');
$('.header').css('background', 'white');
$('.header-nav_list .current_page_item').addClass('this-nav');
$('.bread').find('span').addClass('mobile-hidden');
$('.bread .current').removeClass('mobile-hidden');
var button_lang = localStorage.getItem('switch_lang');
if(button_lang == 'en') {
$('.mc_signup_submit input').attr('value','Subscribe');
} else {
$('.mc_signup_submit input').attr('value','Подписка');
}
<?php if(isset($_GET['cats'])) { ?>
<?php if( ($_GET['cats'] == 3) ) { ?>
function a() {
$('.nav-item3').click();
}
setTimeout(a, 0.3);
Answer the question
In order to leave comments, you need to log in
It's hard to answer without code,
but in general I would output like this
//получаем все категорию новость
<?php $categories = get_categories([
'parent' => ID
]);
//проходимся по массиву и вытаскиваем значения
foreach($categories as $category):?>
<div><a "href=<?php echo $category->term_id;?>"><?php echo category->name;?></a><div>
<?php endforeach;?>
// ну и далее выводим уже наши посты в нужной вам обертке и и тд
<?php
$post = get_posts([
'category' => ID
]);
foreach($posts as $post):?>
//разметка
<div> <?php the_title?>/div>
//и тд и тп
<?php endforeach;?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question