首页 > 解决方案 > Wordpress Post Grid Shortcode 不显示类别模板中的最新帖子,但显示所有其他帖子

问题描述

我创建了一个 post_type“案例研究”,创建了一个类别模板覆盖页面,并在该类别模板覆盖中调用了一个 Post Grid Shortcode,但它总是忽略该类型的最新帖子...... post grid 短代码正确显示所有'实例探究'。

就像它有一个偏移量= 1 ...

代码 - 名为“category-case-studies.php”的页面:

<?php
    get_header();
?>
<div <?php echo apply_filters('shrk-page-cover-atts', 'page-cover'); ?> >
<div class="container">
    <header class="page-header">
        <h1 class="page-title">Case Studies</h1>
    </header>
</div><!-- .entry-header -->
<?php do_action('shrk-page-cover-after'); ?>
</div>

<div class="container container-main-content">
<div class="row">
    <div class="main-content-inner">
        <div class="col-xs-12 col-sm-12 breadcrumb-inner">
            <?php
            if (function_exists('yoast_breadcrumb')) {
                yoast_breadcrumb('<nav id="woocommerce-breadcrumb">', '</nav>');
            }
            ?>
        </div>
    </div>
</div>
</div>

<div class="container container-main-content">
<div class="row after-breadcrumb">
    <div class="main-content-inner col-12 <?php echo esc_attr(shrk_get_main_inner_class()); ?>">

        <?php
        echo do_shortcode('[vc_row][vc_column][vc_basic_grid post_type="post" max_items="10" element_width="6" grid_id="vc_gid:1575382949300-f7c10d1d-4924-6" taxonomies="96" offset="0"][/vc_column][/vc_row]');
        ?>

        <?php get_sidebar(); ?>

    </div><!-- close .*-inner (main-content or sidebar, depending if sidebar is used) -->
</div><!-- close .row -->
</div><!-- close .container .container-main-content -->

<?php get_footer(); ?>

不过真的很奇怪......其他类别类型显示该类别类型的所有帖子(刚刚检查过,是的......)

我有一种感觉(尽管我正在抓住稻草)这与位于与类别类型相同名称/类型的类别页面上有关......

任何建议表示赞赏。

## 更新包括 do_shortcode()
/**
 * Search content for shortcodes and filter shortcodes through their hooks.
 *
 * If there are no shortcode tags defined, then the content will be returned
 * without any filtering. This might cause issues when plugins are disabled but
 * the shortcode will still show up in the post or content.
 *
 * @since 2.5.0
 *
 * @global array $shortcode_tags List of shortcode tags and their callback hooks.
 *
 * @param string $content Content to search for shortcodes.
 * @param bool $ignore_html When true, shortcodes inside HTML elements will be skipped.
 * @return string Content with shortcodes filtered out.
 */
function do_shortcode( $content, $ignore_html = false ) {
    global $shortcode_tags;

    if ( false === strpos( $content, '[' ) ) {
        return $content;
    }

    if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) {
        return $content;
    }

    // Find all registered tag names in $content.
    preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches );
    $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] );

    if ( empty( $tagnames ) ) {
        return $content;
    }

    $content = do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames );

    $pattern = get_shortcode_regex( $tagnames );
    $content = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $content );

    // Always restore square braces so we don't break things like <!--[if IE ]>
    $content = unescape_invalid_shortcodes( $content );

    return $content;
}

标签: wordpressshortcodecustom-wordpress-pages

解决方案


推荐阅读