Reputation: 153
I have a Wordpress/Woocommerce website with a theme that displays a featured image thumbnail next to the post title using this code:
<?php
if ( isset( $woo_options['woo_post_content'] ) &&
$woo_options['woo_post_content'] != 'content' )
{
woo_image( 'width=' . $settings['thumb_w'] . '&height=' . $settings['thumb_h'] . '&class=thumbnail ' . $settings['thumb_align'] );
}
?>
However, I would like to display this thumbnail on archive pages only, not on the homepage. Is it possible to modify the code so it checks if the current page is the homepage, and, if it is, the thumbnail is not displayed?
Upvotes: 0
Views: 566
Reputation: 1260
You're looking for the WordPress Conditional Tags. This Codex article explains how the content is displayed on a particular page depending on conditions.
Also, the question title contradicts the question description. Do you want the thumbnails on (a) archive pages only or on (b) all pages except the homepage?
While jeroen has answered case (b), I'd like to expand that to answer case (a).
Check if you are on an archive page using is_archive() and then display the thumbnail.
if (is_archive()) {
if ( isset( $woo_options['woo_post_content'] ) &&
$woo_options['woo_post_content'] != 'content' )
{
woo_image( 'width=' . $settings['thumb_w'] . '&height=' . $settings['thumb_h'] . '&class=thumbnail ' . $settings['thumb_align'] );
}
}
Upvotes: 1
Reputation: 91734
I assume we are talking WooCommerce / WordPress here.
In that case you can check whether you are on the home page using is_home()
:
if (!is_home())
{
if ( isset( $woo_options['woo_post_content'] ) &&
$woo_options['woo_post_content'] != 'content' )
{
woo_image( 'width=' . $settings['thumb_w'] . '&height=' . $settings['thumb_h'] . '&class=thumbnail ' . $settings['thumb_align'] );
}
}
You could of course combine all that, I have written it out for clarity.
Upvotes: 0
Reputation: 165
you could check the page url from $_SERVER['REQUEST_URI'] to display thumbnail if the the url matched desired pages see function.preg-match.php
Upvotes: 0