• I would like to change a category’s link from https://www.site.com/category/name to https://www.differentsite.com

    What I am trying to do is feature text on my main page that will link a user to a different site. I would like it to be contained within the list of my other categories. Is this possible to do?

    I have been reading about permalinks and editing ‘htacess’ among other things. It all left me confused. Additionally, my theme does not feature a category.php by itself. It is embedded somewhere else.

    Any help would be much appreciated.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You could use something like this in your theme’s sidebar.php…

    <li><h4>Categories</h4>
           <ul><?php $categories = get_categories();
    	 foreach ($categories as $cat) { ?>
    	    <li class="cat-item">&raquo; <a href="<?= get_category_link( $cat->cat_ID ); ?>"><?= $cat->cat_name; ?></a> <?= '('.$cat->category_count.')' ?></li>
       <?php } ?>
       	    <li class="cat-item">&raquo; <a href="https://www.differentsite.com">Different Site</a></li>
    
    	</ul>
    </li>

    Thread Starter ryan_nerone

    (@ryan_nerone)

    Thanks for the help. I’ll experiment with it when I get the chance and let you know the outcome. Cheers.

    Thread Starter ryan_nerone

    (@ryan_nerone)

    Michael,

    I finally got a chance to play around with your method and, unfortunately, I cannot get it to work properly. I also have a pretty rudimentary knowledge of editing CSS. Here is my code for my sidebarleft.php. Could you take a look and offer me a revised version along with some quick details on how to replace the “different site” section of the code with the site I hope to link to. Any assistance would be very much appreciated.

    <div id="sidebarLeft" class="sidebar">
    
    <?php if ( !function_exists('dynamic_sidebar')
            || !dynamic_sidebar(1) ) : ?>
    
    	<h2><?php the_author_nickname(); ?></h2>
    		<ul>
    			<li><img src="<?php bloginfo('template_directory'); ?>/images/user.png" align="top" alt="About" /> <?php the_author_description(); ?></li>
    			<li><img src="<?php bloginfo('template_directory'); ?>/images/email.png" align="top" alt="Email" /> <a href="mailto:<?php the_author_email(); ?>" title="Email">Contact</a></li>
    		</ul>
    	<h2>New Posts <a href="feed:<?php bloginfo('rss2_url'); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/feed.png" align="top" alt="Feed" /></a></h2>
        	<ul>
    			<?php query_posts('showposts=10'); ?>
    			<?php while (have_posts()) : the_post(); ?>
    			<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
    			<?php endwhile; ?>
        	</ul>
    	<h2>Credits</h2>
    		<ul>
    			<li><a href="https://cleavedesign.com" title="cleave design"><img src="<?php bloginfo('template_directory'); ?>/images/cleavedesign2.png" align="top" alt="cleave design" /></a></li>
    		</ul>
    	<h2>Site Admin</h2>
    		<ul>
    			<?php wp_register(); ?>
    			<li><?php wp_loginout(); ?></li>
    			<?php wp_meta(); ?>
    		</ul>
    
    <?php endif; ?>
    
    </div>

    I don’t see where you even tried to add the code…

    Didn’t test this, but just before this

    <h2>Site Admin</h2>

    add

    <h2>Categories</h2>
           <ul><?php $categories = get_categories();
    	 foreach ($categories as $cat) { ?>
    	    <li class="cat-item">&raquo; <a href="<?= get_category_link( $cat->cat_ID ); ?>"><?= $cat->cat_name; ?></a> <?= '('.$cat->category_count.')' ?></li>
       <?php } ?>
       	    <li class="cat-item">&raquo; <a href="https://www.differentsite.com">Different Site</a></li>
    
    	</ul>

    If you have a category widget in play you may want to not use that.

    Thread Starter ryan_nerone

    (@ryan_nerone)

    Well, I tried to add the code and then it resulted in errors, so I simply posted the default code. I will test what you gave me to see if it works and play around with it if it doesn’t. If it still does not work, then I’ll deactivate the category widget that is in use and repeat. I’ll let you know the results. Thanks again.

    Thread Starter ryan_nerone

    (@ryan_nerone)

    Well, I couldn’t get it to work. I tried it with the “My Categories” widget, with the default “Categories” widget, any lastly without any category widget (of course nothing happened on the last one). The link continued to direct to the list posts by category page.

    I have include my edited code for you to look at. What I was not sure about was replacing the second mention of “class=cat-item”. I used both “cat-item cat-item-29” and “cat-item-29” in the tests. Take a look over and let me know if you have any solutions.

    If it all doesn’t work out then I can create a text widget, but it would be a nicer presentation to have the link within my categories.

    <div id="sidebarLeft" class="sidebar">
    
    <?php if ( !function_exists('dynamic_sidebar')
            || !dynamic_sidebar(1) ) : ?>
    
    	<h2><?php the_author_nickname(); ?></h2>
    		<ul>
    			<li><img src="<?php bloginfo('template_directory'); ?>/images/user.png" align="top" alt="About" /> <?php the_author_description(); ?></li>
    			<li><img src="<?php bloginfo('template_directory'); ?>/images/email.png" align="top" alt="Email" /> <a href="mailto:<?php the_author_email(); ?>" title="Email">Contact</a></li>
    		</ul>
    	<h2>New Posts <a href="feed:<?php bloginfo('rss2_url'); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/feed.png" align="top" alt="Feed" /></a></h2>
        	<ul>
    			<?php query_posts('showposts=10'); ?>
    			<?php while (have_posts()) : the_post(); ?>
    			<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
    			<?php endwhile; ?>
        	</ul>
    	<h2>Credits</h2>
    		<ul>
    			<li><a href="https://cleavedesign.com" title="cleave design"><img src="<?php bloginfo('template_directory'); ?>/images/cleavedesign2.png" align="top" alt="cleave design" /></a></li>
    		</ul>
    <h2>Categories</h2>
           <ul><?php $categories = get_categories();
    	 foreach ($categories as $cat) { ?>
    	    <li class="cat-item">&raquo; <a href="<?= get_category_link( $cat->cat_ID ); ?>"><?= $cat->cat_name; ?></a> <?= '('.$cat->category_count.')' ?></li>
       <?php } ?>
       	    <li class="cat-item cat-item-29">&raquo; <a href="https://www.thegoldbrick.net/zenphoto">the GoLdBricK Gallery</a></li>
    
    	</ul>
    	<h2>Site Admin</h2>
    
    		<ul>
    			<?php wp_register(); ?>
    			<li><?php wp_loginout(); ?></li>
    			<?php wp_meta(); ?>
    		</ul>
    
    <?php endif; ?>
    
    </div>
    Thread Starter ryan_nerone

    (@ryan_nerone)

    anybody have some feedback on trying to accomplish this task?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Change Category Link to Different Link’ is closed to new replies.