【问题标题】:Staggering posts in WordPress from two different categoriesWordPress 中来自两个不同类别的交错帖子
【发布时间】:2018-06-02 19:36:53
【问题描述】:

我正在制作一个 WordPress 主题,并希望在滑块和博客页面上按类别错开帖子。

到目前为止,这是我所拥有的:

$arg1 = array('category_name' => 'Photographs' );
$arg2 = array('category_name' => 'Quotes' );
$myposts1 = get_posts( $arg1 );
$myposts2 = get_posts( $arg2 );

我希望循环输出是这样的:

<article>
    Photographs
</article>
<article>
    Quotes
</article>
<article>
    Photographs
</article>
<article>
    Quotes
</article>
ect..

一旦我得到结构设置,我就可以管理循环的输出。我知道如何在循环中添加以下标签,只是不知道如何设置初始结构。

<?php
    the_title();
    the_permalink();
    the_post_thumbnail();
?>

【问题讨论】:

    标签: php wordpress wordpress-theming custom-wordpress-pages


    【解决方案1】:

    为了使用模板标签,您必须在 WordPress 标准循环上循环。 我在滑块中添加了自定义选项以选择类别,并在模板上进行了以下查询:

    $st_portfolio_id = get_theme_mod( 'styledstore_slider_category' );
        $loop = new WP_Query( array( 'post_type' => 'product', 
            'tax_query' => array(
                array(
                    'taxonomy' => 'product_cat',
                    'terms'    => $st_portfolio_id
                ),
            )
        ) ); ?>
    

    以下代码是从名为Styled Store.的WordPress免费主题中提取的

    希望对你有帮助

    【讨论】:

    • 我想出了上面的方法。 WordPress 可以接受吗?
    猜你喜欢
    • 1970-01-01
    • 2012-09-02
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多