1 reply [Last post]
gfr's picture
Last seen: 9 years 38 weeks ago
Timezone: GMT+1
Joined: 2013-03-07
Posts: 1
Points: 2

Hello i've got php code

global $post;
$postclass = '';
if ( '' != get_the_post_thumbnail() ) {
	$thumb = get_the_post_thumbnail( $post->ID, 'post-thumbnail', array( 'title' => esc_attr( get_the_title() ) ) ) . '<span class="no-thumbnail">' . get_the_title() . '</span>';
else {
	$args = array(
				'post_type' => 'attachment',
				'numberposts' => 1,
				'post_status' => null,
				'post_mime_type' => 'image',
				'post_parent' => $post->ID,
	$first_attachment = get_children( $args );
	if ( $first_attachment ) {
		foreach ( $first_attachment as $attachment ) {
			$thumb = wp_get_attachment_image( $attachment->ID, 'post-thumbnail', false, array( 'title' => esc_attr( get_the_title() ) ) );
	else {
		$postclass = 'no-thumbnail';
<article id="post-<?php the_ID(); ?>" <?php post_class( $postclass ); ?>>
	<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php echo $thumb; ?><?php the_title(); ?></a>
</article><!-- #post-<?php the_ID(); ?> -->

But i want to change only the color, alignament, ... of the title but i don't know how.
In the css (style.css) i try to capture the title to change some parameters i use this in CSS:

.blog .hentry a, .archive .hentry a, .search .hentry a .attachment-post-thumbnail a{
 position: absolute;
 font-family: Amatic SC;
 font-size: 24px;
 font-style: bold;

But this code not change only the tittle it change de image and the title, what i'm doing wrong?


Hugo's picture
Last seen: 7 years 47 weeks ago
Joined: 2004-06-06
Posts: 15668
Points: 2806

Firstly this is a frontend

Firstly this is a frontend coding forum and one specifically for CSS, so we do ask that server script isn't posted just browser output.

However your issue clearly lies with how your conditions and functions are constructing final output. The code looks over thought I don't understand why if you have run a check on the post thumb not being empty the following code you generate has a span tag with a class 'no-thumb'?

There feels like quite a lot wrong with what your doing here, for starters '' != get_the_post_thumbnail() is not the best method if valid at all really using  has_post_thumbnail() is the normal check for thumbnails but more than this I'm not sure why you are not working this as a proper WP loop using WP_Query(), building your query args first then running a while( has_post()): the_post() type loop then your markup does the actual check for the thumb in each iteration.

As to the styling you do need to work your styles on a span tag so the post title will need to be wrapped in spans and the anchor made display block.

I would head over to the WP Codex though and look at WP loops before going further.

N.B I realise in all this that I may have missed the point of what you're trying to achieve though Smile

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me