【问题标题】:wordpress permalink for different categories same page不同类别同一页面的wordpress永久链接
【发布时间】:2014-04-28 04:30:29
【问题描述】:

我有一个包含 2 个不同类别的相同 10 个帖子的列表....我需要一个单独的第 1 类和第 2 类永久链接...怎么做...

<?php 
query_posts('cat=18');
if ( have_posts() ) while ( have_posts() ) : the_post();
$i++;
?>
<?php echo get_permalink(); ?><?php the_title();?> // comes with li and a
<?php
endwhile;
wp_reset_query(); 
?>    

我通过相同的帖子有 2 个类别 17 和 18....第一次永久链接适用于第 18 类...重新加载后它适用于第 17 类的永久链接...我已经检查了 get_the_category() 它显示在 2 个数组数组 [0] 类别 17 和数组 [1] 类别 18... 所以它为第一个数组创建永久链接...但我需要第二个...

【问题讨论】:

  • 我已经像上面那样做了...对于第 17 类和第 18 类相同的帖子...第一次为第 18 类创建永久链接...重新加载后它再次转到第 17 类永久链接跨度>
  • 没有老板,使用这个LOOP。这很简单。如果你做了一些编码。请编辑您的问题并删除一些代码。
  • 我已经更新了代码
  • 标签: wordpress


    【解决方案1】:

    好的!干得好。首先,如果您不知道您想要发布的类别是什么。只需使用 FOREACH 循环。如果您需要从 2 个不同类别中获取帖子。你必须使用两个循环。如果是 3 并使用 3 个循环。就像。如果您正在尝试获取该类别的链接。我会为你做下面的代码。

    <?php 
    $cat = get_the_category();
    $cat_01_id= $cat[0]->term_id;//It will get the category id
    $cat_02_id= $cat[1]->term_id;//It will get the category id
    
    //Get category link before the loop
    // Get the URL of this category
    $category_link_01 = get_category_link($cat_01_id);//Cate link 01
    $category_link_02 = get_category_link($cat_02_id);//Cate link 02
    ?>
    Then the loops. Now I'm going to display The Category Link before the category post. Like header.
    
    //Begin to display you post from the category. this is the loop for only one category. Please remember to change `$category_link_01` and `$cat_01_id` this for the 2nd loop
    <div id="cat_title">
    <a href="<?php echo esc_url( $category_link_01 ); ?>" title="Category Name">Category Name</a>
    </div>
    //Then Loops
    <div>
    <?php
    $args_01 = array( 'posts_per_page' => 5, 'offset'=> 1, 'category' => $cat_01_id );
    
    $cat_post_01 = get_posts( $args_01 );
    foreach ( $cat_post_01 as $post ) : setup_postdata( $post ); ?>
        <div id="post_title">
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        </div>
            <div id="post_contents">
                   <?php the_contents(); //Or you can use excerpt ?>
            </div>
    <?php endforeach; 
    wp_reset_postdata();
    ?>
    </div>
    

    就像上面的代码一样。使用variable 进行另一个循环。请阅读我的答案QUESTION

    如果你需要我的帮助。请通过搜索yeshansachithak找到我的任何社交网络。

    【讨论】:

      猜你喜欢
      相关资源
      最近更新 更多
      热门标签