You’ll want to use a conditional tag:
<?php if (! is_home()) { // do something }
See the Variable Sidebar Content example.
Thread Starter
siewe
(@siewe)
From my understanding i can put this:
<?php if (! is_home()) { c2c_get_recent_posts(5); }
instead of the // do something part?
I can test this of course but i want to know for sure i’m on the right track. This is the first time i take a dive in php code.
Siewe,
That looks fine.
BTW, don’t worry about experimenting. If it works, then good. If it doesn’t, then you can just revert things back and have another look at things.
You can learn as much from making your mistakes as you can from listening to others.
Siewe: you got it.
<?php if (! is_home()) { c2c_get_recent_posts(5); }
Thread Starter
siewe
(@siewe)
Thanks for the help guys, but i got a little problem: When i add <?php if (! is_home()) { c2c_get_recent_posts(5) }; ?> to my side bar, i get an error when opening a Page (like “Contact”). It says:
Parse error: parse error, unexpected T_ENDIF in /home/******/domains/******/public_html/wp-content/themes/siewesite/page.php on line 15
Line 15 contains this <?php endwhile; endif; ?> but that is referring to the if and while code in page.php. Adding <?php } ?>
in sidebar.php wont do any good either.
I think you have your ; and } backwards. (Se skippy’s code)
Try <?php if (! is_home()) { c2c_get_recent_posts(5); } ?>
Thread Starter
siewe
(@siewe)
I tried your solution IanD it still result in this:
Parse error: parse error, unexpected T_ENDIF in /home/******/domains/******/public_html/wp-content/themes/siewesite/page.php on line 15. I have edited the template thought admin panel and reuploading the sidebar.php file. Same result
Here are my template files in question.
sidebar.txt
page.txt
Your page.txt is giving a 404 at the moment.
Just to check, does what you have at the moment work if you are looking at the your front page? (I can’t check, your site is blocked to me at work).
Thread Starter
siewe
(@siewe)
Page.txt is working. I’ve setted up the site somewhere else now, on .nl domain and edited my profile. Maybe that will work.
Your page.php:
<?php get_header(); ?>
<div id="content" class="narrowcolumn">
<div class="post" id="post-<?php the_ID(); ?>">
default theme page.php:
<?php get_header(); ?>
<div id="content" class="narrowcolumn">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
Looks like you are missing a line from yours. (or if you did mean to take it out, you will need to remove the <?php endwhile; endif; ?>
line.
Thread Starter
siewe
(@siewe)
If i remove <?php if (have_posts()) : while (have_posts()) : the_post(); ?> and <?php endwhile; endif; ?> I see posts in my sidebar. I can open the posts and read them. If i want to acces pages like Contact i get a Parse error: parse error, unexpected T_ENDIF in /home/******/domains/******/public_html/wp-content/themes/siewesite/page.php on line 16.
I alse updated page.txt the same as my template.
Thinking about it, you can’t take out those lines – they start and finish the loop, and the_title
etc needs to be inside the loop to work. Try replacing your page.php with a fresh one from the default theme.
Thread Starter
siewe
(@siewe)
I have it working now. Thanks for your help guys.
So if you were displaying category X, your list would be the five most recent posts in category X?
To do that I think you will have to explore options using multiple loops:
http://codex.wordpress.org/The_Loop
Thread Starter
siewe
(@siewe)
I’m using the Customizable Post Listings plugin. It is working. However i want to display “Latest 5 postings as a menu title. Now i have this:
<?php if /* this it not home */ (! is_home())
echo ('<li><h2>Latest posts</h2></li>');
{c2c_get_recent_posts(5); } ?>
It displays the the posts and the title. But it also display the posts on the homepage (which i don’t want). I tink i’m close but not close enough.