Monthly Archives: April 2011

WordPress Content Slide plugin: How to stop all of the slideshow images from displaying on page load

I recently ran into an issue with the WP Content Slide plugin where, when you first went to the website it was installed on, all of the images in the slideshow displayed in a line down the page for a split second before disappearing and only showing the top image like it was supposed to. Here is the solution (or workaround, more accurately) that I came up with to hide that line of images as they were loading.

In your WordPress admin panel, go to Plugins -> Editor. Select the Content Slide plugin from the drop down list of plugins to edit. In the content-slide/content_slide.php file, find this line of code:

#wpcontent_slider_container
{
 overflow: hidden; position: relative; padding:0px;margin:0px; text-align:center; width:<?php echo $total_width;?>px !important;
}

Now, simply add a height declaration to that code snippet, so that your code now looks like this:

#wpcontent_slider_container
{
 overflow: hidden; position: relative; padding:0px;margin:0px; text-align:center; width:<?php echo $total_width;?>px !important;height: 130px !important;
}

Obviously, you will want to change the height to whatever the height of your slideshow is.

Making this change fixed the problem and now all of the images are not shown as the page loads.

Let me know if you have any questions or run into any further issues.

WordPress: How to show a different number of posts on different pages

Here is the line of code that I use to control the number of posts on particular pages in a WordPress site.

Note: the website that this code was written for is set up to display different categories of posts on different pages.

Copy this line of code:

<?php if(is_category('3')) { query_posts('cat=3&posts_per_page=3&paged='.$paged);
} else if(is_category('5')) { query_posts('cat=5&posts_per_page=8&paged='.$paged);
} else if(is_category('6')) { query_posts('cat=6&posts_per_page=10&paged='.$paged);
} else if(is_category('7')) { query_posts('cat=7&posts_per_page=5&paged='.$paged);
} else if(is_category('4')) { query_posts('cat=4&posts_per_page=13&paged='.$paged);
} else if(is_category('1')) { query_posts('cat=1&posts_per_page=1&paged='.$paged);
}
$paged = ( get_query_var('paged') && get_query_var('paged') > 1 ) ? get_query_var('paged') : 1;
?>

And paste it into your page.php template, just before the loop is called.

Then just edit the category IDs and the number of posts you want to display on each page.

This code worked perfectly for me but, as always, just let me know if you run into any issues!

WordPress: Manually control which blog pages show excerpts and which show full posts

Here is how to manually control which blog pages on your WordPress site display posts as excerpts and which show the entire posts.

For the site that I developed this solution for, the pages are set up to display posts from a particular category on each particular page.

First, open the loop-page.php file in your WordPress admin panel.

Between the two tags: <div class=”entry-content”> and <?php wp_link_pages…, paste this code:

<?php if ( is_category(3) ) { ?>
<?php the_content(); ?>

<?php } else { ?>
<?php the_excerpt(); ?>

<?php } ?>

In this example, we are telling WordPress that if the page is displaying posts from category ID 3, show the entire post. Otherwise, on all other pages, show the exerpts of posts.

Of course, you will want to edit <?php if ( is_category(3) ) { ?> to whatever category ID or page ID (using <?php if ( is_page(3) ) { ?>) or post ID (using <?php if ( is_post(3) ) { ?>) that you are trying to control.

If you want to control the excerpts and/or full posts on multiple pages or posts or categories, you would use this line at the beginning of the previous code:

<?php if ( is_category(array(3,5)) ) { ?>

Let me know if you have any questions or trouble with this!

WordPress: Display latest posts from a particular category in the sidebars of specific pages

After spending hours trying to figure out a way to display the latest posts from a certain category in WordPress on specific pages, I have finally found a solution!

First of all, it is important to note that the site I am working on is set up to display only posts from a particular category on specific pages.

The first thing I did was install the Exec-PHP plugin (which allows you to add php code to your sidebar widgets) and the Widget Logic plugin (which allows you to control which widgets show up on which pages’ sidebars).

Next, I added a “text” widget to my sidebar. I named the widget “Latest posts in Video.”

Then I pasted this code into the text area of the widget:

<?php
 global $cat;
 $recentPosts = new WP_Query();
 $recentPosts->query('showposts=5&cat=7');
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
 <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; ?>

I changed the category ID (in this case: “7″) to the category ID that I wanted to display on the Video page.

Next, in the Widget Logic field of the widget, I used this line of code to tell the widget which page to appear on:

is_category(7)

That is where I had been going wrong. I had been using is_page(26) (which is the page ID where I have Video posts being displayed), but WordPress sees that page as a category page and not as a page page (because of the fact that I had it set up to show only a certain category of posts), so once I changed the Widget Logic code to is_category, rather than is_page, my solution worked perfectly.

As always, let me know if you have any questions or issues with this, I would be happy to help.

WordPress Tricks: Disable the parent links in a navigation menu

Here is the line of code I use to disable the top, or parent, links in a navigation menu in a WordPress site.

Insert this line of code into your header.php file, right before the closing <head> tag:

<script type="text/javascript">jQuery(function($) {    $("li.page-item-7").children("a").attr('href', "javascript:void(0)");});</script>

Now, simply change the page-item-7 to the ID of the page that you wish to disable. If you want to disable more than one of the parent menu items, use this code:

<script type="text/javascript">
jQuery(function($) {
$("li.page-item-7,li.page-item-14,li.page-item-20,li.page-item-28").children("a").attr('href', "javascript:void(0)");
});
</script>

Let me know if you run into any issues or have any questions at all.

WordPress: How to control which category of posts displays on particular pages

Here are the codes I use to control which category of posts are displayed on which particular pages in WordPress. This is a great way to allow for multiple blogs on a single site, or to organize your blog posts according to topic, etc.

Open the page.php file in your WordPress admin panel. Insert this block of code just before the loop is called:

<?php
$catID = 0;
if (is_page('videos')) {
 $catID=3;
} elseif (is_page('music')) {
 $catID=4;
}
 elseif (is_page('poetry')) {
 $catID=5;
}

if ($catID) {
 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
 query_posts("cat=$catID&paged=$paged");
} ?>

Of course, you will want to change the category IDs and the page names to reflect those on your own site.

Note: the page names in this block of code are the slugs of each page, not the page titles.

This has worked perfectly for me in the past, but let me know if you run into any issues or have any questions.