WordPress posts, link to category pages

Within this wordpress function:

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 -->

I want a link back to the categorie pages inside the li. The php lines that are in there now are what I tried, but of course it does not work. Is there a way to get a link that changes per category?

Related posts

1 comment

  1. Try this and function ruls is return or echo value

    <?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>';
                }
        }
        ?>
    

Comments are closed.