最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

loop - Why do my custom post type show up in all pages?

programmeradmin0浏览0评论

I was doing a page with template-parts to call my custom post type but the posts are popping up across the top of the site, I think it's because of the query , when I deleted it they stop popping up on the top.

Here:

page.php

<?php get_header();?>

<?php $slug = basename(get_permalink()); ?>
<?php while (have_posts()) : the_post(); ?>
    <?php if(is_page($slug)) : ?>
        <?php get_template_part("template-parts/component", $slug ) ?>
    <?php endif; ?>
<?php endwhile; ?>

<?php get_footer(); ?>

component-testes.php

<?php
  $args = array(
  'post_type' => 'teste',
  );
  query_posts($args);
?>
  <div class="container">
    <h1><a href="<?php the_permalink(); ?>"><?php echo the_title(); ?></a> </h1>
    <?php if(have_posts()): while(have_posts()): the_post(); ?>
        <a href="<?php the_permalink(); ?>" title="<?php echo the_title(); ?>"><?php echo the_title(); ?></a><br>
    <?php endwhile; endif;?>
  </div>
<?php  wp_reset_query();?>

postypes.php

if (!function_exists('teste')) {

function teste()
{
    $labels = array(
        'name' => 'Testes',
        'singular_name' => 'Teste',
        'menu_name' => 'Testes',
        'parent_item_colon' => 'Testes',
        'all_items' => 'Todos os Testes',
        'view_item' => 'Ver Testes',
        'add_new_item' => 'Adicionar nova teste',
        'add_new' => 'Novo teste',
        'edit_item' => 'Editar teste',
        'update_item' => 'Atualizar teste',
        'search_items' => 'Produto',
        'not_found' => 'Nenhum teste encontrado',
        'not_found_in_trash' => 'Nenhum teste encontrado na lixeira',
    );

    $rewrite = array(
        'slug' => 'teste',
        'with_front' => true,
        'pages' => true,
        'feeds' => false,
    );

    $args = array(
        'label' => 'Testes',
        'description' => 'Testes',
        'labels' => $labels,
        'supports' => array('title', 'thumbnail','editor'),
        'taxonomies' => array(),
        'hierarchical' => true,
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        //puxar o posttype para o menu e criar a sub sessão
        'show_in_nav_menus' => true,
        'show_in_admin_bar' => true,
        'menu_position' => 6,
        'menu_icon' => 'dashicons-plugins-checked',
        'can_export' => true,
        'has_archive' => false,
        'exclude_from_search' => false,
        'publicly_queryable' => true,
        'query_var' => 'teste',
        'rewrite' => $rewrite,
        'capability_type' => 'post',
    );
    register_post_type('teste', $args);
}

add_action('init', 'teste');
}
发布评论

评论列表(0)

  1. 暂无评论