 |
|
|
03-14-2009, 08:19 PM
|
Wordpress Question
|
Posts: 133
|
On the sidebar of my wordpress blog, I only want some advertisements to appear on the main page of my blog (it becomes too long when viewing individual posts. How would I do this?
I'm talking about the ads under the Sponsors tab at http://nkingdom.com
|
|
|
|
03-14-2009, 10:49 PM
|
Re: Wordpress Question
|
Posts: 2,784
Name: Matt
Location: Irvine, CA
|
All wordpress pages use a shared sidebar, so you'll have to edit the code in sidebar.php to do this.
Wordpress has a built in way of handling this sort of thing:
PHP Code:
<?php
/* If this is the frontpage */
if ( is_home() || is_page() )
{
//echo advertisement
}
I think that should work. Just find the position in the sidebar where you want your ads to appear and use that code.
|
|
|
|
03-15-2009, 12:26 AM
|
Re: Wordpress Question
|
Posts: 59
Location: Random places
|
You also have to use !is_paged() if you only want it to appear on the main page, and not the main page's archives. ["previous entries" at the bottom]
Last edited by Generator; 03-15-2009 at 12:21 PM..
Reason: checked my WP code :)
|
|
|
|
03-15-2009, 12:34 AM
|
Re: Wordpress Question
|
Posts: 2,784
Name: Matt
Location: Irvine, CA
|
Quote:
Originally Posted by Generator
You also have to use !is_page() (I think that's correct) if you only want it to appear on the main page, and not the main page's archives. ["previous entries" at the bottom]
That's assuming || is_page() doesn't do that for ya - not too familiar with php conditionals 
|
Are you sure? I pulled that code off of my own WP and it was for the links and meta sections, which only appear on the main page. I could be wrong, but from looking at my own blog that's how it appears.
|
|
|
|
03-15-2009, 01:43 AM
|
Re: Wordpress Question
|
Posts: 133
|
Quote:
Originally Posted by smashking
On the sidebar of my wordpress blog, I only want some advertisements to appear on the main page of my blog (it becomes too long when viewing individual posts. How would I do this?
I'm talking about the ads under the Sponsors tab at http://nkingdom.com
|
Hmm...it didn't work, but maybe I didn't do it right. Where do I put my ad code at? Sorry, I'm not great at php. I only really know enough to figure out what something is so I know how to move things around to get the design I want.
Last edited by smashking; 03-15-2009 at 01:45 AM..
|
|
|
|
03-15-2009, 01:50 AM
|
Re: Wordpress Question
|
Posts: 2,784
Name: Matt
Location: Irvine, CA
|
In your dashboard go to your theme editor and locate sidebar.php. Different themes have different sidebar code so where it goes is really going to depend on your theme. I think the code should be something like:
PHP Code:
if ( is_home() || is_page() )
{
echo 'Advertisement code goes here';
}
If that doesn't work you can post your sidebar.php code and I'll see what I can do.
|
|
|
|
03-15-2009, 02:12 AM
|
Re: Wordpress Question
|
Posts: 133
|
Ok, that is what I did but I get a syntax error. Here is my code. Some of it has been edited by me so it might not be the most efficient code, but it gets me what I need.
PHP Code:
<div id="dynamic_sidebars">
<div class="dynamic_widget">
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar(1) ) : ?>
<h2>Categories</h2>
<ul class="arrow">
<?php wp_list_cats('sort_column=name&optioncount=0'); ?>
</ul>
<h2>Recent Entries</h2>
<ul class="arrow">
<?php get_archives('postbypost', 5); ?>
</ul>
<h2>Featured Sponsor</h2>
<center><a href="http://click.linksynergy.com/fs-bin/click?id=PWeI268eJl8&offerid=148499.10000086&type=4&subid=0"><IMG alt="Gameduell Inc." border="0" src="http://us-m1.gameduell.com/res/Affiliate/US/180x150/gif/prt/180x150_prt_us.gif"></a><IMG border="0" width="1" height="1" src="http://ad.linksynergy.com/fs-bin/show?id=PWeI268eJl8&bids=148499.10000086&type=4&subid=0"></center>
<h2>Recent Comments</h2>
<ul class="arrow">
<?php if(function_exists("get_recent_comments")) : ?>
<?php get_recent_comments(); ?>
<?php else : ?>
<?php mw_recent_comments(5, false, 50, 50, 35, 'all', '<li><a href="%permalink%" title="%title%"><font color="#AB3622">%date%</font> | %author_name% in %title%</a></li>','d.m'); ?>
<?php endif; ?>
</ul>
<h2>Links</h2>
<ul class="arrow">
<?php get_links(-1, '<li>', '</li>', ' - '); ?>
</ul>
<?php endif; ?>
<h2>Rss</h2>
<ul class="arrow">
<li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php _e('Syndicate this site using RSS'); ?>">Main Entries RSS</a></li>
<li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php _e('The latest comments to all posts in RSS'); ?>">
<?php _e('Comments RSS'); ?>
</a></li>
</ul>
<h2>Archives</h2>
<ul class="arrow">
<?php wp_get_archives('type=monthly'); ?>
</ul>
<!--<h2>Meta</h2>
<ul class="arrow">
<?php wp_register(); ?>
<li>
<?php wp_loginout(); ?>
</li>
<li><a href="http://validator.w3.org/check?uri=referer">Valid XHTML</a></li>
<li><a href="http://wordpress.org/" title="Powered by WordPress, state-of-the-art semantic personal publishing platform.">WordPress</a></li>
<?php wp_meta(); ?>
</ul>-->
<h2>Sponsors</h2><br />
<center><script src="http://tag.contextweb.com/TagPublish/getjs.aspx?action=VIEWAD&cwrun=200&cwadformat=160X600&cwpid=506087&cwwidth=160&cwheight=600&cwpnet=1&cwtagid=52101"></script><br /><br /><script src="http://entrecard.s3.amazonaws.com/widget.js?user_id=44205&type=standard_127" type="text/javascript" id="ecard_widget"></script></center><br />
</div>
</div>
|
|
|
|
03-15-2009, 02:49 AM
|
Re: Wordpress Question
|
Posts: 2,784
Name: Matt
Location: Irvine, CA
|
This should work:
PHP Code:
<div id="dynamic_sidebars">
<div class="dynamic_widget">
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar(1) ) : ?>
<h2>Categories</h2>
<ul class="arrow">
<?php wp_list_cats('sort_column=name&optioncount=0'); ?>
</ul>
<h2>Recent Entries</h2>
<ul class="arrow">
<?php get_archives('postbypost', 5); ?>
</ul>
<h2>Featured Sponsor</h2>
<center><a href="http://click.linksynergy.com/fs-bin/click?id=PWeI268eJl8&offerid=148499.10000086&type=4&subid=0"><IMG alt="Gameduell Inc." border="0" src="http://us-m1.gameduell.com/res/Affiliate/US/180x150/gif/prt/180x150_prt_us.gif"></a><IMG border="0" width="1" height="1" src="http://ad.linksynergy.com/fs-bin/show?id=PWeI268eJl8&bids=148499.10000086&type=4&subid=0"></center>
<h2>Recent Comments</h2>
<ul class="arrow">
<?php if(function_exists("get_recent_comments")) : ?>
<?php get_recent_comments(); ?>
<?php else : ?>
<?php mw_recent_comments(5, false, 50, 50, 35, 'all', '<li><a href="%permalink%" title="%title%"><font color="#AB3622">%date%</font> | %author_name% in %title%</a></li>','d.m'); ?>
<?php endif; ?>
</ul>
<h2>Links</h2>
<ul class="arrow">
<?php get_links(-1, '<li>', '</li>', ' - '); ?>
</ul>
<?php endif; ?>
<h2>Rss</h2>
<ul class="arrow">
<li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php _e('Syndicate this site using RSS'); ?>">Main Entries RSS</a></li>
<li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php _e('The latest comments to all posts in RSS'); ?>">
<?php _e('Comments RSS'); ?>
</a></li>
</ul>
<h2>Archives</h2>
<ul class="arrow">
<?php wp_get_archives('type=monthly'); ?>
</ul>
<!--<h2>Meta</h2>
<ul class="arrow">
<?php wp_register(); ?>
<li>
<?php wp_loginout(); ?>
</li>
<li><a href="http://validator.w3.org/check?uri=referer">Valid XHTML</a></li>
<li><a href="http://wordpress.org/" title="Powered by WordPress, state-of-the-art semantic personal publishing platform.">WordPress</a></li>
<?php wp_meta(); ?>
</ul>-->
<?php if(is_home()) { ?>
<h2>Sponsors</h2><br />
<center><script src="http://tag.contextweb.com/TagPublish/getjs.aspx?action=VIEWAD&cwrun=200&cwadformat=160X600&cwpid=506087&cwwidth=160&cwheight=600&cwpnet=1&cwtagid=52101"></script><br /><br /><script src="http://entrecard.s3.amazonaws.com/widget.js?user_id=44205&type=standard_127" type="text/javascript" id="ecard_widget"></script></center><br />
<?php } ?>
<?php endif; ?>
</div>
</div>
In this case I set it so that your sponsors section would only be visible on your home page.
Last edited by NullPointer; 03-15-2009 at 02:52 AM..
|
|
|
|
03-15-2009, 09:21 AM
|
Re: Wordpress Question
|
Posts: 133
|
I get this:
Code:
Parse error: syntax error, unexpected T_ENDIF in /home/supersma/public_html/wp-content/themes/red-star-version-2/sidebar.php on line 53
|
|
|
|
03-15-2009, 12:20 PM
|
Re: Wordpress Question
|
Posts: 59
Location: Random places
|
Quote:
Originally Posted by NullPointer
Are you sure? I pulled that code off of my own WP and it was for the links and meta sections, which only appear on the main page. I could be wrong, but from looking at my own blog that's how it appears.
|
Yup, check http://tinsology.net/page/2/
You can see how it works with the !is_paged type code over on my graphics blog. The previous pages don't have some of the contents I don't want duplicated
Just checked my code and it's this I use for that:
Code:
<?php if (is_home() && !is_paged()) { } ?>
|
|
|
|
03-15-2009, 05:59 PM
|
Re: Wordpress Question
|
Posts: 2,784
Name: Matt
Location: Irvine, CA
|
Quote:
Originally Posted by Generator
Yup, check http://tinsology.net/page/2/
You can see how it works with the !is_paged type code over on my graphics blog. The previous pages don't have some of the contents I don't want duplicated
Just checked my code and it's this I use for that:
Code:
<?php if (is_home() && !is_paged()) { } ?>
|
My mistake. Turns out (after looking up the documentation) that is_home() refers to the main page and is_page() refers to any page (which may include the home page). So I think using just is_home() is correct.
This should fix that bug smashking:
PHP Code:
<div id="dynamic_sidebars">
<div class="dynamic_widget">
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar(1) ) : ?>
<h2>Categories</h2>
<ul class="arrow">
<?php wp_list_cats('sort_column=name&optioncount=0'); ?>
</ul>
<h2>Recent Entries</h2>
<ul class="arrow">
<?php get_archives('postbypost', 5); ?>
</ul>
<h2>Featured Sponsor</h2>
<center><a href="http://click.linksynergy.com/fs-bin/click?id=PWeI268eJl8&offerid=148499.10000086&type=4&subid=0"><IMG alt="Gameduell Inc." border="0" src="http://us-m1.gameduell.com/res/Affiliate/US/180x150/gif/prt/180x150_prt_us.gif"></a><IMG border="0" width="1" height="1" src="http://ad.linksynergy.com/fs-bin/show?id=PWeI268eJl8&bids=148499.10000086&type=4&subid=0"></center>
<h2>Recent Comments</h2>
<ul class="arrow">
<?php if(function_exists("get_recent_comments")) : ?>
<?php get_recent_comments(); ?>
<?php else : ?>
<?php mw_recent_comments(5, false, 50, 50, 35, 'all', '<li><a href="%permalink%" title="%title%"><font color="#AB3622">%date%</font> | %author_name% in %title%</a></li>','d.m'); ?>
<?php endif; ?>
</ul>
<h2>Links</h2>
<ul class="arrow">
<?php get_links(-1, '<li>', '</li>', ' - '); ?>
</ul>
<?php endif; ?>
<h2>Rss</h2>
<ul class="arrow">
<li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php _e('Syndicate this site using RSS'); ?>">Main Entries RSS</a></li>
<li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php _e('The latest comments to all posts in RSS'); ?>">
<?php _e('Comments RSS'); ?>
</a></li>
</ul>
<h2>Archives</h2>
<ul class="arrow">
<?php wp_get_archives('type=monthly'); ?>
</ul>
<!--<h2>Meta</h2>
<ul class="arrow">
<?php wp_register(); ?>
<li>
<?php wp_loginout(); ?>
</li>
<li><a href="http://validator.w3.org/check?uri=referer">Valid XHTML</a></li>
<li><a href="http://wordpress.org/" title="Powered by WordPress, state-of-the-art semantic personal publishing platform.">WordPress</a></li>
<?php wp_meta(); ?>
</ul>-->
<?php if(is_home()) : ?>
<h2>Sponsors</h2><br />
<center><script src="http://tag.contextweb.com/TagPublish/getjs.aspx?action=VIEWAD&cwrun=200&cwadformat=160X600&cwpid=506087&cwwidth=160&cwheight=600&cwpnet=1&cwtagid=52101"></script><br /><br /><script src="http://entrecard.s3.amazonaws.com/widget.js?user_id=44205&type=standard_127" type="text/javascript" id="ecard_widget"></script></center><br />
<?php endif; ?>
</div>
</div>
Last edited by NullPointer; 03-15-2009 at 06:03 PM..
|
|
|
|
03-16-2009, 05:27 PM
|
Re: Wordpress Question
|
Posts: 133
|
awesome, that works. Thanks a ton for your help.
|
|
|
|
03-18-2009, 07:44 PM
|
Re: Wordpress Question
|
Posts: 299
Location: north central,florida
|
thanks for the visable codes nullpointer Iam dealing with the same issue Iam a newbie at this so is info was indeed appreciated
|
|
|
|
|
« Reply to Wordpress Question
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|