Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Header logo link, recent posts on home page, and category header WordPress

  • SOLVED

This is a three part question for http://www.straightdopedad.com/

1. Want my header graphic to link to home page
2. I'm using a static home but want to show the last three posts below that on the home page
3. On category pages I want to see the category title on top so people know where they are.
Something like "You are Viewing Category Name" (http://www.straightdopedad.com/category/conversations-with-my-daughter/)

Answers (4)

2010-11-09

Nick Parsons answers:

<strong>#1</strong>: In style.css, add:
#header h1 a { display: block; width: 100%; text-indent: -9999px; }

<strong>#2</strong>: Create a custom page template for your static home page, using index.php as the basis. Add this to the top:
<?php
/*
Template Name: Home Page
*/
?>


And then change the loop like this:

<?php
global $post;
$latest_three = get_posts('numberposts=3');
foreach($latest_three as $post) : setup_postdata($post); ?>

<!-- normal loop code that outputs your title, excerpt, etc. -->

<?php endforeach; ?>



<strong>#3</strong>: And in archive.php, add (where you want the title to appear):

<?php if (is_category()) { ?>
<h2 class="pagetitle">You are Viewing <?php single_cat_title(); ?></h2>
<?php } ?>



Clay Butler comments:

I don't have an archive.php or a category.php


Nick Parsons comments:

No problem, just copy index.php and rename it archive.php.


Clay Butler comments:

The archive idea worked great but I don't undertstand the loop part. I can' tell what I'm supposed to replace in this file ( I already added the top part you suggested)

<?php

/*

Template Name: Home Page

*/

?>
<?php get_header(); ?>
<div id="content-container">

<div id="content">

<div id="body">

<?php if (have_posts()) : ?>

<?php while (have_posts()) : the_post(); ?>

<div class="post" id="post-<?php the_ID(); ?>">

<div class="date">
<span class="month"><?php the_time('M') ?></span>
<span class="day"><?php the_time('j') ?></span>
<span class="year"><?php the_time('Y') ?></span>
</div>

<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'elegant-grunge'), get_the_title()); ?>"><?php the_title(); ?></a></h2>

<?php if ( get_option("show_author") ) : ?>
<div class="author"><?php the_author() ?></div>
<?php endif ;?>

<!-- <div class="info">by <?php the_author() ?></div> -->

<div class="entry">
<?php the_content(__('Continue reading', 'elegant-grunge')); ?>
</div>

<div class="clear"></div>

<p class="metadata">
<?php comments_popup_link(__('no comments', 'elegant-grunge'), __('1 comment', 'elegant-grunge'), __('% comments', 'elegant-grunge')); ?>
<?php the_tags('&nbsp;&nbsp;|&nbsp;&nbsp;'.__('tags:', 'elegant-grunge').' ', ', ', ''); ?>
<?php if ( count(($categories=get_the_category())) > 1 || $categories[0]->cat_ID != 1 ) : ?>
| <?php _e('posted in', 'elegant-grunge')?> <?php the_category(', ') ?>
<?php endif; ?>
<?php edit_post_link(__('Edit', 'elegant-grunge'), '&nbsp;&nbsp;|&nbsp;&nbsp;', ''); ?>
</p>

</div>

<div class="hr"><hr /></div>

<?php endwhile; ?>

<div class="navigation">
<div class="next"><?php next_posts_link(__('&laquo; Older Entries', 'elegant-grunge')) ?></div>
<div class="previous"><?php previous_posts_link(__('Newer Entries &raquo;', 'elegant-grunge')) ?></div>
</div>

<?php else : ?>

<h2 class="center"><?php _e('Not Found', 'elegant-grunge') ?></h2>
<p class="center"><?php _e('Sorry, but you are looking for something that isn\'t here.', 'elegant-grunge') ?></p>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>

<?php endif; ?>

</div>

<?php if ( get_option('page_setup') != 'no-sidebar' ) get_sidebar(); ?>

</div>
<div class="clear"></div>
</div>

<?php get_footer(); ?>


Nick Parsons comments:

Here's my edited version:

<?php

/*

Template Name: Home Page

*/

?>
<?php get_header(); ?>
<div id="content-container">

<div id="content">

<div id="body">

<?php

global $post;

if ($latest_three = get_posts('numberposts=3')) :

foreach($latest_three as $post) : setup_postdata($post);

?>

<div class="post" id="post-<?php the_ID(); ?>">

<div class="date">
<span class="month"><?php the_time('M') ?></span>
<span class="day"><?php the_time('j') ?></span>
<span class="year"><?php the_time('Y') ?></span>
</div>

<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'elegant-grunge'), get_the_title()); ?>"><?php the_title(); ?></a></h2>

<?php if ( get_option("show_author") ) : ?>
<div class="author"><?php the_author() ?></div>
<?php endif ;?>

<!-- <div class="info">by <?php the_author() ?></div> -->

<div class="entry">
<?php the_content(__('Continue reading', 'elegant-grunge')); ?>
</div>

<div class="clear"></div>

<p class="metadata">
<?php comments_popup_link(__('no comments', 'elegant-grunge'), __('1 comment', 'elegant-grunge'), __('% comments', 'elegant-grunge')); ?>
<?php the_tags('&nbsp;&nbsp;|&nbsp;&nbsp;'.__('tags:', 'elegant-grunge').' ', ', ', ''); ?>
<?php if ( count(($categories=get_the_category())) > 1 || $categories[0]->cat_ID != 1 ) : ?>
| <?php _e('posted in', 'elegant-grunge')?> <?php the_category(', ') ?>
<?php endif; ?>
<?php edit_post_link(__('Edit', 'elegant-grunge'), '&nbsp;&nbsp;|&nbsp;&nbsp;', ''); ?>
</p>

</div>

<div class="hr"><hr /></div>

<?php endforeach; ?>

<div class="navigation">
<div class="next"><?php next_posts_link(__('&laquo; Older Entries', 'elegant-grunge')) ?></div>
<div class="previous"><?php previous_posts_link(__('Newer Entries &raquo;', 'elegant-grunge')) ?></div>
</div>

<?php else : ?>

<h2 class="center"><?php _e('Not Found', 'elegant-grunge') ?></h2>
<p class="center"><?php _e('Sorry, but you are looking for something that isn\'t here.', 'elegant-grunge') ?></p>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>

<?php endif; ?>

</div>

<?php if ( get_option('page_setup') != 'no-sidebar' ) get_sidebar(); ?>

</div>
<div class="clear"></div>
</div>

<?php get_footer(); ?>


Clay Butler comments:

Maybe I'm just being dense, but I don't understand how this new template will have both my static content followed by my latest three posts. When I activate it, I just get the posts and lose my static content. My static content is in a page file that I've assigned to be the home.


Nick Parsons comments:

My bad, Clay, I forgot to leave the static page display in there. Sorry about that :) You can add this right underneath "<div id='body'>"

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_content(__('<p class="serif">Read the rest of this page &raquo;</p>', 'elegant-grunge')); ?>

<?php wp_link_pages(array('before' => '<p><strong>'.__('Pages:', 'elegant-grunge').'</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>

</div>
</div>
<?php endwhile; endif; ?>
<?php edit_post_link(__('Edit this entry.', 'elegant-grunge'), '<p>', '</p>'); ?>

2010-11-09

John Cotton answers:

1. You need to edit your theme to have <a href="/"></a> around the logo.

2. Drop this in where you want it in home.php


<?php

//The Query
query_posts('posts_per_page=3');

//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
..
endwhile; else:
..
endif;

//Reset Query
wp_reset_query();

?>



3. Put this where you want it in category.php

echo '<h1>'. get_cat_name( $cat ) .' News</h1>';


Clay Butler comments:

I don't have an archive.php or a category.php


John Cotton comments:


<blockquote>
Clay Butler says:
I don't have an archive.php or a category.php
</blockquote>

This is the one from TwentyTen - might work, but it depends on your theme.


<?php
/**
* The template for displaying Category Archive pages.
*
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.0
*/

get_header(); ?>

<div id="container">
<div id="content" role="main">

<h1 class="page-title"><?php
printf( __( 'Category Archives: %s', 'twentyten' ), '<span>' . single_cat_title( '', false ) . '</span>' );
?></h1>
<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo '<div class="archive-meta">' . $category_description . '</div>';

/* Run the loop for the category page to output the posts.
* If you want to overload this in a child theme then include a file
* called loop-category.php and that will be used instead.
*/
get_template_part( 'loop', 'category' );
?>

</div><!-- #content -->
</div><!-- #container -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

2010-11-09

enodekciw answers:

to make your header link to your homepage - open up style.css and at a very bottom add these lines:

#header h1 {float: left; width: 100%;}
#header h1 a {width: 100%;}

2010-11-09

idt answers:

For #1:

Add this to your CSS:

#header h1 a {
display:block;
height:185px;
text-indent:-9999px;
width:800px;
}