Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 具有相同分类术语中的下一篇和上一篇文章的自定义文章类型_Wordpress_Custom Post Type_Taxonomy - Fatal编程技术网

Wordpress 具有相同分类术语中的下一篇和上一篇文章的自定义文章类型

Wordpress 具有相同分类术语中的下一篇和上一篇文章的自定义文章类型,wordpress,custom-post-type,taxonomy,Wordpress,Custom Post Type,Taxonomy,好的,我已经在stackoverflow和google上搜索了又搜索,但没有找到我要找的东西。我正在寻找一种方法,让我的下一个和上一个按钮链接到我的文章,是在相同的职位类型术语 我有一个名为“Projects”的帖子类型,分类法是“Projects\u category”。在这种分类法下我有几个术语,当我查看单个项目帖子时,我希望能够在该术语内单击“下一步”和“上一步”。有办法做到这一点吗 更新(11/13/13)(再次): 这就是我现在拥有的 <?php $projectCat = wp

好的,我已经在stackoverflow和google上搜索了又搜索,但没有找到我要找的东西。我正在寻找一种方法,让我的下一个和上一个按钮链接到我的文章,是在相同的职位类型术语

我有一个名为“Projects”的帖子类型,分类法是“Projects\u category”。在这种分类法下我有几个术语,当我查看单个项目帖子时,我希望能够在该术语内单击“下一步”和“上一步”。有办法做到这一点吗

更新(11/13/13)(再次):

这就是我现在拥有的

<?php
$projectCat = wp_get_post_terms($postid,"projects_category");
if(count($projectCat)){
$projectC = $projectCat[0]->slug;
}
else{
$projectC = "";
}
$args = array(

'post_type'=>'project_post',
'showposts' => -1,
'tax_query' => array(
array(
        'taxonomy' => 'projects_category',
        'terms' => '{$projectC}',  //define your category id or slug here
            'field' => 'slug',
        )
),
'order'=>'ASC', 
);

$postlist = get_posts($args);
$posts = array();
foreach ($postlist as $post) {
$posts[] += $post->ID;
}

$prev_post = get_previous_post(); 
$prevID = $prev_post->ID ;
?>
<?php 
$next_post = get_next_post();
$nextID = $next_post->ID ;
?>          

<?php if (!empty($prevID)) { ?>

<li><a href="<?php echo get_permalink($prevID); ?>"
title="<?php echo get_the_title($prevID) ." ". $projectC; ?>" 
class="p_prev widget_anim"><span></span>Previous</a>
</li>
<?php }

if (!empty($nextID)) { ?>
<li><a href="<?php echo get_permalink($nextID); ?>" 
title="<?php echo get_the_title($nextID) ." ". $projectC;; ?>"  
class="p_next widget_anim">Next<span></span></a>
</li>
<?php }  

wp_reset_postdata();
?>


  • 我得到了在single-project_post页面上找到的当前术语,查询似乎捕捉到了它,但查询没有遵循它需要保留在术语中的规则。它从我的其他术语中提取帖子。即使我在查询中用确切的术语替换$projectC,它仍然会为下一篇和上一篇提供错误的帖子。有人能帮我吗?我非常感谢前面的答案所提供的帮助。

    在子主题中创建functions.php,这样它就不会被更新覆盖。然后 编写一个返回POST数组的函数。抄本会告诉你如何按照你的要求去做。然后从链接标记中的自定义帖子类型调用该函数

    这是在同一个法典页上

        <div class="alignleft">    
        <a href="<?php echo get_permalink($prevID); ?>"
        title="<?php echo get_the_title($prevID); ?>">Previous</a>
        </div>
        <?php }
        if (!empty($nextID)) { ?>
        <div class="alignright">
        <a href="<?php echo get_permalink($nextID); ?>" 
         title="<?php echo get_the_title($nextID); ?>">Next</a>
        </div>
    
    
    
    
    

  • 也有同样的问题,我在这里找到了解决方案:


    希望它对你有用

    很抱歉,我对此有点陌生。我查看了您提供的链接,但它没有告诉我如何编写该函数。您不能将自定义分类使用tax_查询的参数直接传递给category。如果我希望使用当前分类术语,而不管它在哪个类别上?(即:术语是当前和过去的项目)
    <?php
                     $args = array(
                    'tax_query' => array(
                        array(
                                'taxonomy' => 'projects_category',
                                'field' => 'id',
                                'terms' => '2'  //define your category id hear
                                )
                        ),
                        'post_type'=>'project_post',
                        'order'=>'ASC',
                        'posts_per_page'=>-1
                );
    
                            $postlist = get_posts($args);
    $posts = array();
    foreach ($postlist as $post) {
       $posts[] += $post->ID;
    }
                    <?php
            $prev_post = get_previous_post(); 
            $prevID = $prev_post->ID ;
    ?>
    <?php 
            $next_post = get_next_post();
            $nextID = $next_post->ID ;
    ?>          
    
        <?php if (!empty($prevID)) { ?>
    
        <li><a href="<?php echo get_permalink($prevID); ?>"
                title="<?php echo get_the_title($prevID); ?>" 
                class="p_prev widget_anim">Previous</a>
                </li>
        <?php }
    
        if (!empty($nextID)) { ?>
            <li><a href="<?php echo get_permalink($nextID); ?>" 
                title="<?php echo get_the_title($nextID); ?>"  
                class="p_next widget_anim">Next</a>
                </li>
        <?php }  
    
        wp_reset_postdata();
    ?>