张贴页面显示没有URL更改的子页面



我正在为一家公司开发WordPress网站,遇到了以下问题。这就是结构:

章节:

fruits

类别(小节(:

red, yellow, blue, orange

项目(小节(:

apples, oranges, lemons, blueberries

Fruits基于站点的Posts部分(旁边有一个小图钉(。该类别显示在该页面的URL中,因此当选择一个项目时,它看起来像:

food.com/fruits/red/apples/

类别页面有自己的页面,带有一些视觉导航和关于该类别的简介。但是,当选择水果并导航到其中一个类别时,页面会显示水果的内容,而不是自己构建的类别页面。

例如,URL看起来像:

food.com/fruits/red/

但它显示的是页面

food.com/fruits/red/apples/

而不改变URL。

到目前为止,我唯一能解决这个问题的方法是不选择一个类别,但后来我遇到了这个问题,水果页面的URL看起来像这样:

food.com/fruits/colour/apples/

到目前为止,我还没有找到任何关于这个主题的信息,如果能提供任何帮助,我们将不胜感激。

在下图中,您可以看到下一步显示了错误的页面,但第二页的永久链接在两种情况下都是相同的。

这个问题的视觉

编辑:

archive fruits.blade.php

@include('page')

page.blade.php

@php $iterator = 0 @endphp
@extends('layouts.app')
@section('content')
@while(have_posts()) @php the_post() @endphp
@if ($flexible_content)
@foreach ($flexible_content as $block)
@if ($block->block_type == 'markets_slider')
@include('partials.markets-slider')
@elseif ($block->block_type == 'static_content')
@include('partials.static-content')
@elseif ($block->block_type == 'expandable_content')
@include('partials.expandable-content')
@elseif ($block->block_type == 'image_+_text_listings')
@include('partials.image-plus-text-listings')
@elseif ($block->block_type == 'farmers_markets_list')
@include('partials.farmers-markets-list')
@elseif ($block->block_type == 'fruits_list')
@include('partials.fruits-list')
@elseif ($block->block_type == 'tabbed_content')
@include('partials.tabbed-content')
@endif
@endforeach
@endif
@endwhile
@endsection

布局:app.blade.php

<!doctype html>
<html {!! get_language_attributes() !!}>
@include('partials.head')
<body @php body_class() @endphp>
@php do_action('get_header') @endphp
@include('partials.header')
<div class="wrap container" role="document">
<div class="content">
<main class="main">
@yield('content')
</main>
@if (Appdisplay_sidebar())
<aside class="sidebar">
@include('partials.sidebar')
</aside>
@endif
</div>
</div>
@php do_action('get_footer') @endphp
@include('partials.footer')
@php wp_footer() @endphp
</body>
</html>

我真的不明白你是怎么工作的。对不起,我不能发表评论,但我还没有足够的声誉。这个";水果";是自定义帖子类型或者是";张贴";功能本身?这是什么意思;而不改变URL";?

您可以在Wordpress的设置中,按照Settings>Permalink更改帖子的永久链接,并在URL中添加类别,如您所见。

我不知道您是如何创建CPT的,但它使用默认的页面模板作为存档模板。这意味着您在类别归档中不会有帖子列表,只有内容。您必须在archivefruits.blade.php中创建一个归档模板,替换已经存在的那一行。

您可以在任何Wordpress主题的archive.php文件中查看归档模板是如何制作的,但这是一种自定义帖子类型,因此可能存在差异(例如名为archive fruits的事实(。没有什么是在谷歌上快速搜索无法解决的。我建议你先阅读法典,然后再阅读一些指南。

最新更新