Need Help with Correcting Links on Wordpress Template Page

Hi. I’ve recently started at a small company as their Marketing Coordinator, but it basically entails everything to do with presentation, including the running of their website. Their site is relatively new and there was a lot of drama in getting it created. It’s built on the Wordpress platform but is a bespoke site with a lot of customised coded areas. I’m not sure why they did this but that’s not why I’m here.

There is a Projects section on the website, with individual projects that the company has worked on. One each of the individual project pages there is a list of links on the bottom right hand side, under headings such as “Solutions”, “Brand” and “Applications”. The links for everything under Applications go to 404 error because the links are doing something strange, that I’m not sure how to fix.

There are actual pages that these links should connect to. For example, the link for CSSD Sterilisation should go to http://southlandfiltration.com.au/applications/CSSD-Sterilisation/

If you hover over the link you can see that the link shows as http://southlandfiltration.com.au/projects/woolmers-estate-tas/CSSD Sterilisation

If I change the actual anchor text of the link to be “CSSD-Sterilisation” (note the hyphen) then the link works. However, we don’t want hyphens all through the anchor text on each of those links if possible.

So I’m hoping it’s a simple matter of altering the code, perhaps to use the slug in the link instead of the title (the slug has a hyphen already)

Please excuse my “beginnerness” of all this, I’m trying to learn PHP so I can fix a number of things on this site but it’s a slow process. Having broken links is one of the more important fixes to make asap so I’m hoping someone here can help me.

The code for the single.php page is here:

<?php
/**
 * The template for displaying all single posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
 *
 * @package tc-southland-filtration
 */

get_header();
?>
<?php
   if(get_post_type(get_the_ID()) == 'products_post'){
?>
<section>
	<div id="carousel-1" class="carousel slide multi-item-carousel" data-ride="carousel">
	  <ol class="carousel-indicators">
	  <?php
	       
			if( have_rows('manage_product_banner') ):
				$i = 0;
				while ( have_rows('manage_product_banner') ) : the_row();
			?>
			<li data-target="#carousel-1" data-slide-to="<?php echo($i);?>" class="<?php if($i==0): echo('active'); endif;?>"></li>		
			<?php
				$i++;
				endwhile;
			else :
			endif;
		?>   
	  </ol>
	  <div class="carousel-inner" role="listbox">
		<?php
		
			
			if( have_rows('manage_product_banner') ):
				$k = 0;
				while ( have_rows('manage_product_banner') ) : the_row();
				$accreditationsimage = get_sub_field('product_banner');
				
			?>
			<div class="item <?php if($k==0): echo('active'); endif;?>">
			<?php if($i <= 1): ?>
			  <div class="item__third" style="width:100% !important">
					<div class="product_details_img" style="background:url(<?php echo($accreditationsimage['url']);?>)no-repeat center center/contain;"></div>
			  </div>
			 <?php else : ?>
			  <div class="item__third">
					<div class="product_details_img" style="background:url(<?php echo($accreditationsimage['url']);?>)no-repeat center center/contain;"></div>
			  </div>
			  <?php endif; ?>
			</div>
			<?php
				$k++;
				endwhile;
			else :
			endif;
		?>
		
	  </div>
	  <a href="#carousel-1" class="left carousel-control" role="button" data-slide="prev"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true" style="opacity:0"></span></a>
	  <a href="#carousel-1" class="right carousel-control" role="button" data-slide="next"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true" style="opacity:0"></span></a>
	</div>
</section>
<section class="blog_main_content ">
	<div class="container">
		<div class="row">
		<?php		
			while ( have_posts() ) : the_post();
				?>	
				<div class="col-md-12">
					<h1 class="big_title"><?php the_title(); ?> <small><a href="<?php echo esc_url( home_url( '/products' ) ); ?>">< Back to all Products</a></small></h1>
				</div>
				<div class="col-sm-7">
					<div id="" class="ulforhelath">	
						<?php the_content();?>
						<?php //the_content();?>
						<?php echo do_shortcode('[wp_social_sharing social_options="linkedin"]');?>						
					</div>
				</div>	
				<div class="col-sm-1"></div>
				<div class="col-sm-4 ">	
					<?php $brand_image = get_field('select_brand_image');?>
					<div class="brand_image">
						<a href="<?php echo get_field('brand_url');?>"><img src="<?php echo $brand_image['url'];?>" alt=""></a>
					</div>
					<div class="manage_download_files">
						<h6>available downloads</h6>						
						<?php
							if( have_rows('manage_available_downloads') ):
								while ( have_rows('manage_available_downloads') ) : the_row();
								$accreditationsimage = get_sub_field('upload_file');
							?>
							<div class="download_files">
								<a href="<?php echo $accreditationsimage['url'];?>" download><?php echo get_sub_field('title_d');?></a>
							</div>
							<?php
								endwhile;
							else :
							endif;
						?>						
					</div>
				</div>
				<div class="clearfix"></div>
				<?php				
			endwhile; 
		?>
		</div>
	</div>
</section>
<section class="blog_section">
	<div class="container">
		<h1>
		Knowledge Center
		<?php 
		//$cat_id = get_field('select_post_category_for_homepage');
		//echo get_cat_name( $cat_id ); 
		?>
		</h1>
		<div class="row">
			<?php
			//$catquery = new WP_Query( 'cat='.$cat_id.'&posts_per_page=4' );
			$catquery = new WP_Query( 'posts_per_page=4' );
			while($catquery->have_posts()) : $catquery->the_post();
			?>
			<div class="col-sm-6 col-md-3 each_bloh">
				<div style="background:url(<?php the_post_thumbnail_url( $size );?>)no-repeat center center / cover" class="blog_image" >
					
				</div>
				<h2><a href="<?php the_permalink() ?>" style="color:inherit"><?php the_title(); ?></a></h2>
				<?php 
				$content = get_field('short_description');
				?>
				<p><?php echo wp_trim_words( $content , '17' );?></p> 
				<a href="<?php the_permalink() ?>">Read More</a>
			</div>
			<?php endwhile; wp_reset_query(); ?>
			<div class="clearfix"></div>
		</div>
	</div>
</section>
<?php
}
?>
<?php
   if(get_post_type( get_the_ID()) == 'projects'){
?>
<section>
	<div id="carousel-1" class="carousel slide multi-item-carousel" data-ride="carousel">
	  <ol class="carousel-indicators">
	  <?php
			if( have_rows('manage_project_banner') ):
				$i = 0;
				while ( have_rows('manage_project_banner') ) : the_row();
			?>
			<li data-target="#carousel-1" data-slide-to="<?php echo($i);?>" class="<?php if($i==0): echo('active'); endif;?>"></li>		
			<?php
				$i++;
				endwhile;
			else :
			endif;
		?>   
	  </ol>
	  <div class="carousel-inner" role="listbox">
		<?php
			if( have_rows('manage_project_banner') ):
				$k = 0;
				while ( have_rows('manage_project_banner') ) : the_row();
				$accreditationsimage = get_sub_field('project_banner');
			?>
			<div class="item <?php if($k==0): echo('active'); endif;?>">
			  <div class="item__third">
				<img src="<?php echo($accreditationsimage['url']);?>" alt="">
			  </div>
			</div>
			<?php
				$k++;
				endwhile;
			else :
			endif;
		?>
	  </div>
	  <a href="#carousel-1" class="left carousel-control" role="button" data-slide="prev"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true" style="opacity:0"></span></a>
	  <a href="#carousel-1" class="right carousel-control" role="button" data-slide="next"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true" style="opacity:0"></span></a>
	</div>
</section>
<section class="blog_main_content ">
	<div class="container">
		<div class="row">
		<?php		
			while ( have_posts() ) : the_post();
				?>	
				<div class="col-md-12">
					<h1 class="big_title"><?php the_title(); ?> <small><a href="<?php echo esc_url( home_url( '/projects' ) ); ?>">< Back to all Projects</a></small></h1>
				</div>
				<div class="col-sm-7">
					<div id="" class="ulforhelath">	
						<?php the_content();?>
						<?php //the_content();?>
						<?php echo do_shortcode('[wp_social_sharing social_options="linkedin"]');
							$download_file = get_field('upload_file');
						?>
						<!--<a style="display:inline-block; margin-top:20px" download href="<?php echo $download_file['url']; ?>"><img src="<?php bloginfo('template_url'); ?>/images/btn_download.png"  alt="" /></a>-->
					</div>
				</div>	
				<div class="col-sm-1"></div>
				<div class="col-sm-4 ">	
					<div class="each_cat" style="border-top:1px solid #969696">
						<h5><strong>SOLUTION</strong></h5>
						<?php
							$terms = get_terms( 'project_solution' );
								if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){						
								foreach ( $terms as $term ) {
								?>
									<h6><a href="<?php echo  $term->name; ?>"><?php echo  $term->name; ?></a></h6>
								<?php
								}							
							}
						?>
					</div>
					<div class="each_cat">
						<h5><strong>BRAND</strong></h5>
						<?php
							$terms = get_terms( 'project_brand' );
								if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){						
								foreach ( $terms as $term ) {
								?>
									<h6><a href="<?php echo  $term->name; ?>"><?php echo  $term->name; ?></a></h6>
								<?php
								}							
							}
						?>
					</div>
					<div class="each_cat">
						<h5><strong>APPLICATION</strong></h5>
						<?php
							$terms = get_terms( 'project_application' );
								if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){						
								foreach ( $terms as $term ) {
								?>
									<h6><a href="<?php echo  $term->name; ?>"><?php echo  $term->name; ?></a></h6>
								<?php
								}							
							}
						?>
					</div>
				</div>
				<div class="clearfix"></div>
				<?php				
			endwhile; 
		?>
		</div>
	</div>
</section>
<section class="blog_section">
	<div class="container">
		<h1>
		Knowledge Center
		<?php 
		//$cat_id = get_field('select_post_category_for_homepage');
		//echo get_cat_name( $cat_id ); 
		?>
		</h1>
		<div class="row">
			<?php
			//$catquery = new WP_Query( 'cat='.$cat_id.'&posts_per_page=4' );
			$catquery = new WP_Query( 'posts_per_page=4' );
			while($catquery->have_posts()) : $catquery->the_post();
			?>
			<div class="col-sm-6 col-md-3 each_bloh">
				<div style="background:url(<?php the_post_thumbnail_url( $size );?>)no-repeat center center / cover" class="blog_image" >
					
				</div>
				<h2><a href="<?php the_permalink() ?>" style="color:inherit"><?php the_title(); ?></a></h2>
				<!-- <p><?php echo get_field('short_description');?></p> -->
				<?php 
				$content = get_field('short_description');
				?>
				<p><?php echo wp_trim_words( $content , '17' );?></p> 
				<a href="<?php the_permalink() ?>">Read More</a>
			</div>
			<?php endwhile; wp_reset_query(); ?>
			<div class="clearfix"></div>
		</div>
	</div>
</section>
<?php
}
?>
<?php
   if(get_post_type( get_the_ID()) == 'post'){
?>
<?php
$category_detail=get_the_category(get_the_ID());//$post->ID
foreach($category_detail as $cd){
$cat_id= $cd->term_id;
}
?>
<section class="page-title">
	<?php
			if ( is_singular() ) :
			?>
			<div  class="title_background title_backgroundgray" 
					<?php
			// Must be inside a loop.
			 
			if ( get_field('banner_image') ) {
				$banner_image = get_field('banner_image');
				?>
				style="background-image:url( <?php echo $banner_image['url'];?>)"				
				 <?php
			}
			else {
				echo '';
			}
			?>>
		<div class="container">
			<table>
				<tr>
					<td><!-- <h1><?php echo $cd->cat_name;?></h1> -->
					   <?php		
						while ( have_posts() ) : the_post();
						?>	
						<h1><?php the_title(); ?></h1>
						<?php
						endwhile;
						?> 
						<!-- <p class="gobacktop"><?php echo date_i18n( 'j', false, false);?>&nbsp;&nbsp;of&nbsp;&nbsp;<?php echo date_i18n( 'F Y', false, false);?></p> -->
						<h5 class="goback"><a href="javascript:history.back()">< GO BACK</a></h5>
					</td>
					<td><?php dynamic_sidebar( 'bannersidebar' ); ?></td>
				</tr>
			</table>
		</div>
	</div>
	<?php	
	endif; ?>
</section>
<section class="blog_main_content">
	<div class="container">
		<div class="row">
		<?php		
			while ( have_posts() ) : the_post();
				?>		
				<div class="col-sm-7">
					<h1 class="hide_title"><?php the_title(); ?></h1>
				  <?php	if ( 'post' === get_post_type() ) : ?>
					<!-- 
<div class="entry-meta">
						<span class="posted-on">Posted on <a href="" rel="bookmark"><?php the_time('jS F Y') ?></a></span><span class="byline"> by <span class="author vcard"><a class="url fn n" href=""><?php the_author(); ?></a></span></span>					
					</div>
 -->
					<?php
					endif; ?>
					<div class="post_sub_heading">
						<h2><?php echo(get_field('post_sub_heading'));?></h2>
					</div>
					<div id="" class="">
						<?php the_content();?>
						<a style="display:inline-block; margin-top:20px" href="<?php echo esc_url( home_url( '/contact-us' ) ); ?>"><img src="<?php bloginfo('template_url'); ?>/images/contact.png"  alt="" /></a>
					</div>
				</div>	
				<div class="col-sm-1"></div>
				<div class="col-sm-4 ">
					<?php
					if( have_rows('post_images') ):
						while ( have_rows('post_images') ) : the_row();
							$img = get_sub_field('image_post');
					?>
						<img src="<?php echo $img['url']; ?>"  alt="" class="postimage" />
					<?php
						endwhile;
					else :
						//no rows found
					endif;

					?>
				</div>
				<div class="clearfix"></div>
				<?php				
			endwhile; 
		?>
		</div>
	</div>
</section>
<section class="blog_section">
	<div class="container">
		<h1>Related <?php echo $cd->cat_name;?>. </h1>
		<?php $current_postid = get_the_ID(); ?>
		<div class="row">
		<?php query_posts("cat=$cat_id&posts_per_page=4");
		if (have_posts()) : while (have_posts()) : the_post(); 
			if($current_postid != get_the_ID()){
			?>
			<div class="col-sm-6 col-md-3 each_bloh">
			<div  class="fil_img">
				<a href="<?php the_permalink() ?>"><?php echo get_the_post_thumbnail(); ?></a>
			</div>
			<h2><a href="<?php the_permalink() ?>" style="color:inherit"><?php the_title(); ?></a></h2>
			<p><?php echo get_field('short_description');?></p>
			<a href="<?php the_permalink() ?>">Read More</a>
			</div>
		<?php } endwhile; endif; ?>
		</div>
	</div>
</section>
<?php }?>
<?php if(get_post_type( get_the_ID()) == 'applications') { ?>
  <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <section class="application">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <h1 class="big_title"><?php echo the_title(); ?></h1>
                <?php if ( has_post_thumbnail() ) { ?>
                    <div class="col-sm-4 each_bloh">
                        <div  class="fil_img">
                          <?php echo the_post_thumbnail(); ?>
                        </div>
                    </div>
                <?php } ?>
                    <div class="col-sm-8">
                        <?php echo the_content();?>
                    </div>
                </div>
            </div>
        </div>
    </section>
  <?php endwhile; endif; ?>
<?php } ?>
<?php
get_sidebar();
get_footer();

This code above covers a couple of different types of pages we have on the site (products and projects). The specific code that deals with the Applications links is here:

<div class="col-sm-1"></div>
				<div class="col-sm-4 ">	
					<div class="each_cat" style="border-top:1px solid #969696">
						<h5><strong>SOLUTION</strong></h5>
						<?php
							$terms = get_terms( 'project_solution' );
								if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){						
								foreach ( $terms as $term ) {
								?>
									<h6><a href="<?php echo  $term->name; ?>"><?php echo  $term->name; ?></a></h6>
								<?php
								}							
							}
						?>
					</div>
					<div class="each_cat">
						<h5><strong>BRAND</strong></h5>
						<?php
							$terms = get_terms( 'project_brand' );
								if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){						
								foreach ( $terms as $term ) {
								?>
									<h6><a href="<?php echo  $term->name; ?>"><?php echo  $term->name; ?></a></h6>
								<?php
								}							
							}
						?>
					</div>
					<div class="each_cat">
						<h5><strong>APPLICATION</strong></h5>
						<?php
							$terms = get_terms( 'project_application' );
								if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){						
								foreach ( $terms as $term ) {
								?>
									<h6><a href="<?php echo  $term->name; ?>"><?php echo  $term->name; ?></a></h6>
								<?php
								}							
							}
						?>
					</div>
				</div>

Any help with this would be greatly appreciated. If you are able to offer a fix and you have the time it would be great if you could explain it to me as well, to help with my learning - but if you don’t have the time I’d be happy with just the fix :wink: Thank you in advance!

Hi, just wondering if there’s a reason why no one has commented on this? Is it too difficult to figure out? Have I not been clear in what I’m trying to do? Do I need to provide more information? It would be good if I can get some idea so I can potentially escalate the issue to a local web developer, if it’s something I can’t get help with myself. Cheers :slight_smile:

I was able to solve this problem myself in the end. I’m not able to delete this topic, so if anyone who can wants to that’s fine by me :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service