This thread is over two years old and may be outdated. Please create a new thread if you need help, or email us if you have an active Premium license.

Vantage Theme – overlay the category name as a link on an image in the post loop

Resolved 3 replies premiumthemetheme-vantage
11 years ago · Last reply by Andrew Misplon 11 years ago

Hello

Thanks for this theme – it’s excellent and the best I’ve tried yet!

I would like to overlay the category name as a link on an image in the post loop. I did some tweaking to loop-grid.php and managed to get the category name to display above the image as plain text. However, I’d like to overlay it on the image with an opaque background. The Smart-Mag theme does this:

http://themeforest.net/item/smartmag-responsive-retina-wordpress-magazine/full_screen_preview/6652608

Here’s the code I tweaked for loop-grid.php

<?php
/**
 * Loop Name: Grid
 */
?>
<?php if( have_posts() ) : $i = 0; ?>
	<div class="vantage-grid-loop">
		<?php while( have_posts() ): the_post(); $i++ ?>
			<article <?php post_class(array('grid-post')) ?>>
<?php 
$category = get_the_category(); 
if($category[0]){
echo '<a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>';
}
?>
				<?php if( has_post_thumbnail() ) : ?>
					<a class="grid-thumbnail" href="<?php the_permalink() ?>">
						<?php the_post_thumbnail('vantage-grid-loop') ?>
					</a>
				<?php endif; ?>
				<h3><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h3>
				<div class="excerpt"><?php the_excerpt() ?></div>
			</article>
			<?php if($i % 2 == 0) : ?><div class="clear"></div><?php endif; ?>
		<?php endwhile; ?>
	</div>
	<?php vantage_content_nav( 'nav-below' ); ?>
<?php endif; ?>

URL: http://amsterdamforvisitors.com/

This is our free support forum. Replies can take several days.

Need fast email support? Get SiteOrigin Premium

Replies

3
  1. Andrew Misplon Staff 11 years, 3 months ago

    Hi

    Thanks for your positive feedback, glad you’re enjoying the theme.

    Please be sure to keep any edited files in a child theme. Changes within the Vantage folder will be lost during theme updates.

    How’s your CSS? Here is an example CSS section from another theme, the most important property is opacity:

    .post-type-archive-theme .entry-content-wrapper {
    -moz-transition: all 0.3s ease-in-out;
    -o-transition: all 0.3s ease-in-out;
    -webkit-transition: all 0.3s ease-in-out;
    transition: all 0.3s ease-in-out;
    background: rgba(58, 193, 98, 0.95);
    display: block;
    height: 100%;
    left: 0;
    opacity: 0;
    border: 1.6875rem solid #f2f2f2;
    position: absolute;
    top: 0;
    width: 100%;
    }
    .post-type-archive-theme .entry-content-wrapper:hover {
    opacity: 1;
    }

    So in summary what’s happening there is the container that the title is in is being absolute positioned and then given opacity: 0; On hover the opacity is being changed to 1.

    Hope that helps steer you in the right direction.

  2. AmsterdamForVisitors 11 years, 3 months ago

    Thanks for getting back to me. I’ve got it looking how I want with the following PHP & CSS changes:

    <?php
    /**
     * Loop Name: Grid
     */
    ?>
    <?php if( have_posts() ) : $i = 0; ?>
    	<div class="vantage-grid-loop">
    		<?php while( have_posts() ): the_post(); $i++ ?>
    			<article <?php post_class(array('grid-post')) ?>>
    <?php 
    $category = get_the_category(); 
    if($category[0]){
    echo '<span class="cat-title '.$category[0]->cat_name.'"> 
    <a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.' 
    </span>
    </a>';
    }
    ?>
    				<?php if( has_post_thumbnail() ) : ?>
    					<a class="grid-thumbnail" href="<?php the_permalink() ?>">
    						<?php the_post_thumbnail('vantage-grid-loop') ?>
    					</a>
    				<?php endif; ?>
    				<h3><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h3>
    				<div class="excerpt"><?php the_excerpt() ?></div>
    			</article>
    			<?php if($i % 2 == 0) : ?><div class="clear"></div><?php endif; ?>
    		<?php endwhile; ?>
    	</div>
    	<?php vantage_content_nav( 'nav-below' ); ?>
    <?php endif; ?>
    .cat-title {
    position: absolute;
    line-height: 25px;
    background: #e54e53;
    font-size: 12px;
    text-transform: uppercase;
    padding: 0 10px;
    margin-left: 12px;
    margin-top: 6px;
    display: block;
    z-index: 1;
    }
    .cat-title a:hover {
    color: #fff;
    text-decoration: underline;
    }
    .cat-title a{
    color: #fff;
    text-decoration: none;
    }
  3. Andrew Misplon Staff 11 years, 3 months ago

    That’s looking great. Nice improvement for sure. Sorry, I thought you wanted a title to appear only on hover. For anyone else reading, that wasn’t required, so the opacity setting isn’t needed.

    Thanks for sharing. Glad you were able to take my example and make it happen.

Replies on this thread are closed.

Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Have a different question or issue?

Start New Thread