Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.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
Php Wordpress帖子,链接到分类页面_Php_Wordpress - Fatal编程技术网

Php Wordpress帖子,链接到分类页面

Php Wordpress帖子,链接到分类页面,php,wordpress,Php,Wordpress,在此wordpress功能中: function ct_post_nav() { ?> <ul> <li class="post-nav-all"> <?php $linktitelposts = get_cat_ID( $cat_name ); if ($linktitelposts == 'blogs' )

在此wordpress功能中:

function ct_post_nav() { ?>
        <ul>
           <li class="post-nav-all">
              <?php $linktitelposts = get_cat_ID( $cat_name );          
                 if ($linktitelposts == 'blogs' )
                 {$linktitelposts = '<a href="#">Lees alle blogs</a>';}
                 if ($linktitelposts == 'vacatures')
                 {$linktitelposts = '<a href="#">Lees alle vacatures</a>';}
             ?> 
           </li>
        </ul>
    </div><!-- .nav-links -->
</nav><!-- .navigation -->
函数ct\u post\u nav(){?>

我想要一个链接回到li中的分类页面。那里的php行现在是我尝试过的,但它当然不起作用。有没有办法获得每个类别都会更改的链接?

试试这个和
函数
ruls Is
return
echo

<?php function ct_post_nav($cat_name) { 
            // Get the ID of a given category
            $linktitelposts = get_cat_ID( $cat_name );
            // In this variable `$linktitelposts` Your Category ID and Pass this id
            // Get the URL of this category
            $category_link = get_category_link( $linktitelposts );


        <!-- Print a link to this category -->

            if ($linktitelposts == 'blogs' )
            {
             // Not use Same variable `$linktitelposts` 
             echo $anLink = '<a href="<?php echo esc_url( $category_link ); ?>">Lees alle blogs</a>';
            }
            else if ($linktitelposts == 'vacatures')
            {
             // Not use Same variable `$linktitelposts` 
             echo  $anLink = '<a href="<?php echo esc_url( $category_link ); ?>">Lees alle vacatures</a>';
            }
    }
    ?>

尝试此操作,然后
函数
规则为
返回
回显

<?php function ct_post_nav($cat_name) { 
            // Get the ID of a given category
            $linktitelposts = get_cat_ID( $cat_name );
            // In this variable `$linktitelposts` Your Category ID and Pass this id
            // Get the URL of this category
            $category_link = get_category_link( $linktitelposts );


        <!-- Print a link to this category -->

            if ($linktitelposts == 'blogs' )
            {
             // Not use Same variable `$linktitelposts` 
             echo $anLink = '<a href="<?php echo esc_url( $category_link ); ?>">Lees alle blogs</a>';
            }
            else if ($linktitelposts == 'vacatures')
            {
             // Not use Same variable `$linktitelposts` 
             echo  $anLink = '<a href="<?php echo esc_url( $category_link ); ?>">Lees alle vacatures</a>';
            }
    }
    ?>


谢谢你的回答,我尝试了类似的方法。但它只链接回同一篇文章。如果我使用你的版本,它会使网站崩溃。@bhaveshvala函数需要
$cat\u name
参数,所以它应该像
函数ct\u post\u nav($cat\u name){
我尝试了您的更改,我也将href更改为实际页面,在博客页面上它可以工作,但在另一个页面上它保持相同的链接。好的,谢谢您的回答,我尝试了类似的方法。但它只链接回同一篇文章。如果我使用您的版本,它会使网站崩溃。@bhaveshvala函数需要
$cat\u name
参数,因此它应该像
函数ct\u post\u nav($cat\u name){
我尝试了您的更改,我也将href更改为实际页面,在博客页面上它工作,但在不同页面上它保持相同的链接。好的,使用
var\u dump($cat\u name)中的内容
?此
$cat\u name
在何处定义?您在
变量转储($cat\u name)
中得到了什么?此
$cat\u name
在何处定义?