Support » Fixing WordPress » link to a different template

  • Pardon me, I know this is totally obvious, but can’t get WP to link to a different template. There’s probably something wrong with my PHP syntax.
    I have tried many variations including
    <?php the_permalink(posts.php) ?>
    <?php permalink_link('posts.php') ?>
    <?php the_permalink("posts.php",true) ?>
    <?php permalink_link('posts.php',true) ?>
    but they all keep using index.php instead of posts.php, even if the original link is from posts.php.
    Thanks in advance for any help y’all can give!

Viewing 9 replies - 1 through 9 (of 9 total)
  • BTW, I also tried <?php permalink_single('posts.php'); ?> but I got a Fatal error: Call to undefined function: permalink_single() ...

    Are you trying to have 2 different templates, or just to change the name from index to posts.php?
    Having done a 2-template site (with no comments, no permalinks, and no calendar), my advice is avoid if at all possible – it’s a really ugly hack trying to get the permalinks, archives, and category links on both templates to point back to that same template instead of the other one.
    I ended up modifying the get_permalink and get_month_link functions in wp-includes/template-functions-links.php and more..
    Anyway, before I end up embarrassing myself with some butt-ugly and probably irrelevant code here, it might be helpful to tell us what you’re trying to do.

    I am trying to have two different templates. One for the front page (index.php) and one for viewing archived posts in a variety of ways (posts.php). I could get around this if I had a better understanding of the conditional controls available to me. But I’m a PHP newbie.

    Sorry, what’s “clean uri?”

    Oh don’t get me started. I’ve tried to create the nice URLs and I always get 404 errors. But in any case, this won’t help me as they are all using the same template. I want different things on different types of pages.
    I think I can also do what I want using conditionals to evaluate variables like $single but I don’t know what all the variables I can use are. Is there one for $monthly? How about $front or something that indictaes if they’re on the front/root page?

    rubyji – have you set up your .htaccess file so you can use the clean URIs?

    Yes I have added the code to my .htaccess file. And I have CHMODed it to a variety of things, although I think 644 is what it’s supposed be (right?). Nothing works. It’s not my top priority right now. Thanks, though.

    rubyji – I have the same problem.
    I found a solution here:
    But I’d like a solution without a patch.

    What you want to do sounds similiar to how I have my site set up. I have seperated the standard index.php into header and footer files so that I can make ‘static’ pages.
    (Keep in mind I have tags in these that are specific to my site)
    /* Don't remove this line. */
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <html xmlns="">
    <head profile="">
    <title><?php bloginfo('name'); ?><?php wp_title(); ?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo('charset'); ?>" />
    <meta name="generator" content="WordPress <?php bloginfo('version'); ?>" /> <!-- leave this for stats -->
    <style type="text/css" media="screen">
    @import url( <?php echo get_settings('siteurl'); ?>/wp-layout.css );
    <link rel="stylesheet" type="text/css" media="print" href="<?php echo get_settings('siteurl'); ?>/print.css" />
    <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url'); ?>" />
    <link rel="alternate" type="text/xml" title="RSS .92" href="<?php bloginfo('rss_url'); ?>" />
    <link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="<?php bloginfo('atom_url'); ?>" />
    <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
    <?php wp_get_archives('type=monthly&format=link'); ?>
    <?php //comments_popup_script(); // off by default ?>
    <?php wp_head(); ?>
    <div id="rap">
    <h1 id="header">"><?php bloginfo('name'); ?></h1>
    <div id="content">

    <div id="menu">

      <li id="categories"><?php _e('Categories:'); ?>
      <?php wp_list_cats(); ?>

    <li id="search">
    <label for="s"><?php _e('Search:'); ?></label>
    <form id="searchform" method="get" action="<?php echo $PHP_SELF; ?>">
    <input type="text" name="s" id="s" size="15" />

    <input type="submit" name="submit" value="<?php _e('Search'); ?>" />

    <li id="archives"><?php _e('Archives:'); ?>

      <?php wp_get_archives('type=monthly'); ?>

    <li id="calendar">
    <?php get_calendar(); ?>

    <li id="other"><?php _e('Other:'); ?>

    <li id="meta"><?php _e('Meta:'); ?>


    And then any page I want to create is only 3 lines of code:
    <?php include('wp-includes/header.php') ?>
    <?php include('wp-includes/posts.php') ?>
    <?php include('wp-includes/footer.php') ?>

    My resume and links page use this method.
    You could create a new page: newpage.php
    and have the code:
    <?php include('wp-includes/header.php') ?>
    <?php include('wp-includes/NEWTEMPLATE.php') ?>
    <?php include('wp-includes/footer.php') ?>

    If you want a completely different look for that page, just create a new header file and use a different CSS file for it.
    <?php include('wp-includes/NEWHEADER.php') ?>
    <?php include('wp-includes/NEWTEMPLATE.php') ?>
    <?php include('wp-includes/footer.php') ?>

    Create whatever CSS you want for NEWHEADER.php

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘link to a different template’ is closed to new replies.