• In my archive.php file I’m trying to produce a title to the search result that is customised depending upon what the person clicked on. For example, if they click Archive December 2006 link, the archive.php result will display the title ‘Here is a list of all excerpts from posts within December 2006’. That bit is easy.

    But what happens when someone clicks on a tag? I’d like the archive.php to display the result page to show something like ‘Here is a list of all excerpts from the tag ‘tagx’. I’ve tried:

    if (is_archive('archive'))
    	  {echo "You are viewing all exceprts from "; the_time('F Y');}
    
    	elseif (is_archive('the_tag'))
    	  { echo "You are viewing all excerpts from the tag "; the_tag('');}

    …but nothing happens.

    Oh, I’d also like to do the same for the search word as well.

    Any clues?
    fankyouverymuch

Viewing 5 replies - 1 through 5 (of 5 total)
  • Use is_tag() instead of is_archive(‘the_tag’). To display the search word, use the following:

    <?php echo wp_specialchars($s); ?>

    Thread Starter demonboy

    (@demonboy)

    Hi,

    apologies in the delayed reply We are having region-wide connection problems here in Turkey. It has taken me half an hour just to get to this page in order to respond. No doubt it will take another hour to post my reply!

    Your solution sounds interesting but there is very little information on your idea and there is certainly no working example on this website. Perhaps you could give me an example of how the code would look? My code below still ignores the elseif statement.

    <?php 
    
    	if (is_archive(''))
    	  {echo "You are viewing all exceprts from "; the_time('F Y');}
    
    	elseif (is_tag('')) {
    	 echo "This is the tag you were searching- "; wp_specialchars($s);
    	  }
    
     ?>

    I’ve tried changing the ($s) to ‘is_tag’ but it still ignores it. Any further assistance greatly appreciated. Please bear in mind I only started coding PHP last week so I could do with an example to get me going.

    Thread Starter demonboy

    (@demonboy)

    Hi,

    apologies in the delayed reply We are having region-wide connection problems here in Turkey. It has taken me half an hour just to get to this page in order to respond. No doubt it will take another hour to post my reply!

    Your solution sounds interesting but there is very little information on your idea and there is certainly no working example on this website. Perhaps you could give me an example of how the code would look? My code below still ignores the elseif statement.

    <?php 
    
    	if (is_archive(''))
    	  {echo "You are viewing all exceprts from "; the_time('F Y');}
    
    	elseif (is_tag('')) {
    	 echo "This is the tag you were searching- "; wp_specialchars($s);
    	  }
    
     ?>

    I’ve tried changing the ($s) to ‘is_tag’ but it still ignores it. Any further assistance greatly appreciated. Please bear in mind I only started coding PHP last week so I could do with an example to get me going.

    Thread Starter demonboy

    (@demonboy)

    Anyone help?

    neilogic

    (@neilogic)

    Hi there I don’t know if your problem got solved by now or not . But I use this on my archive.php page and when someone clicks on a tag it shows “Posts Tagged with #tagname” . Here’s the code below I hope this helps you out. If not just let me know I will try n show you a working example.

    <?php if ( is_404() || is_category() || is_tag() || is_day() || is_month() ||
    
    						is_year() || is_search() || is_paged() ) {
    
    			?>
    
     	  <?php /* If this is a category archive */ if (is_category()) { ?>
    
    		<h2 class="pagetitle">Archive for the ‘<?php single_cat_title(); ?>’ Category</h2>
    
     	  <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
    
    		<h2 class="pagetitle">Posts Tagged with ‘<?php single_tag_title(); ?>’</h2>
    
     	  <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
    
    		<h2 class="pagetitle">Archive for <?php the_time('F jS, Y'); ?></h2>
    
     	  <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
    
    		<h2 class="pagetitle">Archive for <?php the_time('F, Y'); ?></h2>
    
     	  <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
    
    		<h2 class="pagetitle">Archive for <?php the_time('Y'); ?></h2>
    
    	  <?php /* If this is an author archive */ } elseif (is_author()) { ?>
    
    		<h2 class="pagetitle">Author Archive</h2>
    
     	  <?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
    
    		<h2 class="pagetitle">Blog Archives</h2>
    
     	  <?php } ?>
    
    			<?php }?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to change archive.php title with the_tags search result’ is closed to new replies.