• Okay, on my website the category for “Programs’ is kind of the focus. As such it has a lot of unique properties.

    One thing I’d like to do is set it up so that should I decide to change the way programs are laid out I’d rather only change a single template, as opposed to changing all past posts.

    For example, here’s the current “template” that I’d use:

    <p align="center"><a href="/pages/proggy/proggy.exe"><img src="/images/buttonexe.gif" alt="Download this program as a pre-compiled EXE for windows." /></a><a href="/pages/proggy/proggy.pdf"> <img src="/images/buttonpdf.gif" alt="Download the code in a formated PDF for print." /> </a><a href="/pages/proggy/proggy.c"><img src="/images/buttonc.gif" alt="Download the source code." /></a></p>
    <p align="center"><a href="/pages/proggy/proggy.pdf"><img src="/pages/proggy/proggythumb.gif" border="0" alt="proggy.C" /></a></p>
    <!--more-->
    <img src="/pages/proggy/proggy.gif" alt="" align="right" />blurb
    
    Download the <a href="/pages/proggy/proggy.pdf">PDF</a> for more including the Author's Notes on the program.

    Basically search and replace “proggy” with the program’s name (alleytris or battleship) and insert a blurb where it says “blurb”.

    Any ideas how to do that?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter guesst

    (@guesst)

    Okay, I’ve hacked an ugly index.php that mostly does what I’m looking for, but there’s one little caviat: sometimes I need to have the download link be for a C file and sometimes for a CPP file.

    Is there a way I can search the tags and if I see a CPP tag to change a variable?

    Wanna see what I’ve got so far?

    <?php get_header();?>
    
    <?php $postnum = 1; $showadsense1 = 1;?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <?php the_date('','<h2>','</h2>'); ?>
    
    <div class="post" id="post-<?php the_ID(); ?>">
    	 <h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
             <?php foreach((get_the_category()) as $cat) {
               $cats =  $cat->cat_name . ' ';   if(strstr("$cats", "Programs")  !== FALSE) {
                 if(function_exists('the_ratings')) {
                 /* Little PostRatings Mod */
                 /* Replaces all <div> tags with <span> tags to fix display problems on some themes */
                   ob_start();
                   the_ratings();
                   $remove_divs = ob_get_contents();
                   ob_end_clean();
                   echo str_replace('div', 'span', $remove_divs);
                 }
               }
             } ?>
    </h3>
    	<div class="meta"><?php _e("Filed under:"); ?> <?php the_category(',') ?> — <?php the_tags(__('Tags: '), ', ', ' — '); ?> <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>
    
    	<div class="storycontent">
              <?php if (is_single()) { ?>
              <p align="center"><?php previous_post_link('&laquo; &laquo; %link', '%title', 'yes'); ?> | <?php next_post_link('%link &raquo; &raquo; ', '%title', 'yes'); } ?></p>
    
                    <?php foreach((get_the_category()) as $cat) {
                      $cats =  $cat->cat_name . ' ';   if(strstr("$cats", "Programs")  !== FALSE) { ?>
    
    <!-- Program posting template -->
    <?php $proggy = strtolower(the_title('','',FALSE)); ?>
    <p align="center"><a href="/pages/<?php _e($proggy); ?>/<?php _e($proggy); ?>.exe"><img src="/images/buttonexe.gif" alt="Download this program as a pre-compiled EXE for windows." /></a><a href="/pages/<?php _e($proggy); ?>/<?php _e($proggy); ?>.pdf"> <img src="/images/buttonpdf.gif" alt="Download the code in a formated PDF for print." /> </a><a href="/pages/<?php _e($proggy); ?>/<?php _e($proggy); ?>.c"><img src="/images/buttonc.gif" alt="Download the source code." /></a></p>
    <p align="center"><a href="/pages/<?php _e($proggy); ?>/<?php _e($proggy); ?>.pdf"><img src="/pages/<?php _e($proggy); ?>/<?php _e($proggy); ?>thumb.gif" border="0" alt="<?php _e($proggy); ?>.C" /></a></p>
    
                      <?php }
                    } ?>
    
              <?php the_content() ?>
    
              <?php if (is_single()) { ?>
              <p align="center"><?php previous_post_link('&laquo; &laquo; %link', '%title', 'yes'); ?> | <?php next_post_link('%link &raquo; &raquo; ', '%title', 'yes'); } ?></p>
    
    	</div>
    
    	<div class="feedback">
    		<?php wp_link_pages(); ?>
    		<?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); ?>
    	</div>
    
    </div>
    
    <?php comments_template(); // Get wp-comments.php template ?>
    
    <?php if ($postnum == $showadsense1) { ?>
    <p align="center">
    <script type="text/javascript"><!--
    google_ad_client = "pub-7691058508257211";
    /* 468x60, created 4/29/08 */
    google_ad_slot = "3195266714";
    google_ad_width = 468;
    google_ad_height = 60;
    //-->
    </script>
    <script type="text/javascript"
    src="https://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    </p>
    <?php } ?>
    <?php $postnum++; ?>
    
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
    
    <?php posts_nav_link(' — ', __('&laquo; Newer Posts'), __('Older Posts &raquo;')); ?>
    
    <?php get_footer(); ?>

    Thread Starter guesst

    (@guesst)

    Sometimes I think I only ask so that I’ll find my own solutions.

    <!-- Program posting template -->
    <?php $proggy = strtolower(the_title('','',FALSE)); $format = "c";
        $posttags = get_the_tags();
          if ($posttags) {
            foreach($posttags as $tags) {
              $tag = strtolower($tags->name);
              if(strstr("$tag", "cpp")  !== FALSE) $format = "cpp";
            }
          }
    ?>
    <p align="center"><a href="/pages/<?php _e($proggy); ?>/<?php _e($proggy); ?>.exe"><img src="/images/buttonexe.gif" alt="Download this program as a pre-compiled EXE for windows." /></a><a href="/pages/<?php _e($proggy); ?>/<?php _e($proggy); ?>.pdf"> <img src="/images/buttonpdf.gif" alt="Download the code in a formated PDF for print." /> </a><a href="/pages/<?php _e($proggy); ?>/<?php _e($proggy); ?>.<?php _e($format); ?>"><img src="/images/button<?php _e($format); ?>.gif" alt="Download the source code." /></a></p>
    <p align="center"><a href="/pages/<?php _e($proggy); ?>/<?php _e($proggy); ?>.pdf"><img src="/pages/<?php _e($proggy); ?>/<?php _e($proggy); ?>thumb.gif" border="0" alt="<?php _e($proggy); ?>.C" /></a></p>
    
                      <?php }
                    } ?>
    
              <?php the_content() ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Category from template’ is closed to new replies.