Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Prize Will Be Raised and Split! Modify This Code! SIMPLE! WordPress

Fahd figured out a lot of this code now I need it to be completed, I will raise the prize and split it. This should be easy! This question deals with excerpts for post formats.

I need each post format excerpt to have the same excerpt code as the default excerpt (used without post formats). This MUST contain the excerpt_wrap and exerpt_inside along with the conditional div class. Basically, everything in this code... simply figure out how to integrate it into the second code everywhere it says "CODE GOES HERE":

<!-- Begin excerpt wrap -->
<div class="excerpt_wrap">
<div class="excerpt_inside">


<!-- No post format -->
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink() ?>">
<?php the_post_thumbnail( 'thmb-index' ); ?>
</a>
<?php } ?>
<div class="excerpt_content<?php if ( has_post_thumbnail() ) echo ' with-thumbnail'; ?>"> <span class="index_title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</span> <span class="sub-title">By
<?php the_author_posts_link( ); ?>
<span class="sub-title-divider">|</span>
<?php the_time('F j, Y'); ?>
<span class="sub-title-divider">|</span> <a href="<?php the_permalink(); ?>/#commentlist">
<?php comments_number( 'No comments', 'One comment', '% comments' ); ?>
</a></span>
<?php the_excerpt(); ?>
</div>


<!-- End excerpt wrap -->
</div>
</div>


Here is my code:


<?php get_header(); ?>

<div id="container">
<div id="post_content2">
<div id="main_index">
<div class="main_adjust">

<!-- Grab posts -->
<?php while (have_posts()) : the_post(); ?>



<!-- Post formats -->
<?php
if ( has_post_format( 'aside' )) {
CODE GOES HERE
}
elseif ( has_post_format( 'chat' )) {
CODE GOES HERE
}
elseif ( has_post_format( 'gallery' )) {
CODE GOES HERE
}
elseif ( has_post_format( 'image' )) {
CODE GOES HERE
}
elseif ( has_post_format( 'link' )) {
CODE GOES HERE
}
elseif ( has_post_format( 'quote' )) {
CODE GOES HERE
}
elseif ( has_post_format( 'status' )) {
CODE GOES HERE
}
elseif ( has_post_format( 'video' )) {
CODE GOES HERE
}
elseif ( has_post_format( 'audio' )) {
CODE GOES HERE
}
else {
$format = get_post_format();
if ( false === $format ) {
?>

<!-- Begin excerpt wrap -->
<div class="excerpt_wrap">
<div class="excerpt_inside">


<!-- No post format -->
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink() ?>">
<?php the_post_thumbnail( 'thmb-index' ); ?>
</a>
<?php } ?>
<div class="excerpt_content<?php if ( has_post_thumbnail() ) echo ' with-thumbnail'; ?>"> <span class="index_title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</span> <span class="sub-title">By
<?php the_author_posts_link( ); ?>
<span class="sub-title-divider">|</span>
<?php the_time('F j, Y'); ?>
<span class="sub-title-divider">|</span> <a href="<?php the_permalink(); ?>/#commentlist">
<?php comments_number( 'No comments', 'One comment', '% comments' ); ?>
</a></span>
<?php the_excerpt(); ?>
</div>


<!-- End excerpt wrap -->
</div>
</div>

<?php } // ending the if ( false === $format ) ...

} // end else

?>
<?php endwhile; ?>



<!-- Next/Previous entries -->
<div class="mp_archive">
<div id="more_posts">
<div class="oe">
<?php next_posts_link('&laquo; Older') ?>
</div>
<div class="re">
<?php previous_posts_link ('Newer &raquo;') ?>
</div>
</div>
</div>


</div>
</div>
</div>

<?php get_sidebar(); ?>

</div>
</div>

<?php get_footer(); ?>

Answers (2)

2011-09-14

Fahad Murtaza answers:


$format = get_post_format();
if ( false === $format ) {
?>
<!-- No post format -->

<?php if ( has_post_thumbnail() ) { ?>



<a href="<?php the_permalink() ?>">

<?php the_post_thumbnail( 'thmb-index' ); ?>

</a>



<?php } ?>

<div class="excerpt_content<?php if ( has_post_thumbnail() ) echo ' with-thumbnail'; ?>">

<span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>

<span class="sub-title">By <?php the_author_posts_link( ); ?> <span class="sub-title-divider">|</span> <?php the_time('F j, Y'); ?> <span class="sub-title-divider">|</span> <a href="<?php the_permalink(); ?>/#commentlist"><?php comments_number( 'No comments', 'One comment', '% comments' ); ?></a></span>



<?php the_excerpt(); ?>



</div>



<!-- End excerpt wrap -->

</div>

</div>


<?
the_excerpt();
}


Fahad Murtaza comments:

The complete code


<?php get_header(); ?>

<div id="container">
<div id="post_content2">
<div id="main_index">
<div class="main_adjust">

<!-- Grab posts -->

<?php while (have_posts()) : the_post(); ?>

<!-- Begin excerpt wrap -->

<div class="excerpt_wrap">
<div class="excerpt_inside">

<!-- Post formats -->

<?php

if ( has_post_format( 'aside' )) {

?>
<span class="icon-aside"></span> <a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
</a> <span class="sub-title">Posted
<?php the_time("F j, Y"); ?>
by
<?php the_author_posts_link(); ?>
in
<?php the_category(', ') ?>
</span> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span>
<?php the_excerpt();

}

if ( has_post_format( 'chat' )) {

?>
<span class="icon-chat"></span> <a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
</a> <span class="sub-title">
<?php the_time("F j, Y"); ?>
&nbsp;/&nbsp;
<?php the_author_posts_link(); ?>
&nbsp;/&nbsp;
<?php the_category(', ') ?>
</span> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span>
<?php the_excerpt();

}

if ( has_post_format( 'gallery' )) {

?>
<span class="icon-gallery"></span> <a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
</a> <span class="sub-title">
<?php the_author_posts_link(); ?>
&nbsp;/&nbsp;
<?php the_category(', ') ?>
&nbsp;/&nbsp;
<?php the_time("F j, Y"); ?>
</span> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span>
<?php the_content(); ?>
<?php comments_number( 'no responses', 'one response', '% responses' );

}

if ( has_post_format( 'image' )) {

?>
<span class="icon-image"></span> <a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
</a> <span class="sub-title">
<?php the_time("F j, Y"); ?>
&nbsp;/&nbsp;
<?php the_author_posts_link(); ?>
&nbsp;/&nbsp;
<?php the_category(', ') ?>
</span> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span>
<?php the_excerpt();

}

if ( has_post_format( 'link' )) {

?>
<span class="icon-link"></span>
<h1><a href="<?php echo $first_link = catch_that_link(); ?>">
<?php the_title(); ?>
</a></h1>
<a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
</a> <span class="sub-title">
<?php the_time("F j, Y"); ?>
&nbsp;/&nbsp;
<?php the_author_posts_link(); ?>
&nbsp;/&nbsp;
<?php the_category(', ') ?>
</span>
<?php comments_number( 'no responses', 'one response', '% responses' );

}

if ( has_post_format( 'quote' )) {

?>
<span class="icon-quote"></span> <a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
</a> <span class="sub-title">
<?php the_time("F j, Y"); ?>
&nbsp;/&nbsp;
<?php the_author_posts_link(); ?>
&nbsp;/&nbsp;
<?php the_category(', ') ?>
</span> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span>
<?php the_content();

}

if ( has_post_format( 'status' )) {

?>
<span class="icon-status"></span> <a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
</a> <span class="sub-title">
<?php the_time("F j, Y"); ?>
&nbsp;/&nbsp;
<?php the_author_posts_link(); ?>
&nbsp;/&nbsp;
<?php the_category(', ') ?>
</span> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span>
<?php the_excerpt();

}

if ( has_post_format( 'video' )) {

?>
<span class="icon-video"></span> <span class="sub-title">
<?php the_time("F j, Y"); ?>
&nbsp;/&nbsp;
<?php the_author_posts_link(); ?>
&nbsp;/&nbsp;
<?php the_category(', ') ?>
</span> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span>
<?php the_content();

}

if ( has_post_format( 'audio' )) {

?>
<span class="icon-audio"></span> <a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
</a> <span class="sub-title">
<?php the_time("F j, Y"); ?>
&nbsp;/&nbsp;
<?php the_author_posts_link(); ?>
&nbsp;/&nbsp;
<?php the_category(', ') ?>
</span> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span>
<?php the_content();

}



?>
<?php

$format = get_post_format();

if ( false === $format ) {
?>
<!-- No post format -->

<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink() ?>">
<?php the_post_thumbnail( 'thmb-index' ); ?>
</a>
<?php } ?>
<div class="excerpt_content<?php if ( has_post_thumbnail() ) echo ' with-thumbnail'; ?>"> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span> <span class="sub-title">By
<?php the_author_posts_link( ); ?>
<span class="sub-title-divider">|</span>
<?php the_time('F j, Y'); ?>
<span class="sub-title-divider">|</span> <a href="<?php the_permalink(); ?>/#commentlist">
<?php comments_number( 'No comments', 'One comment', '% comments' ); ?>
</a></span>
<?php the_excerpt(); ?>
</div>

<!-- End excerpt wrap -->

</div>
</div>
<?php } // ending the if ( false === $format ) ... ?>
<?php endwhile; ?>

<!-- Next/Previous entries -->

<div class="mp_archive">
<div id="more_posts">
<div class="oe">
<?php next_posts_link('&laquo; Older') ?>
</div>
<div class="re">
<?php previous_posts_link ('Newer &raquo;') ?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php get_sidebar(); ?>
</div>
</div>
<?php get_footer(); ?>


Lucas Wynne comments:

Ok, after changing things up I go this code to work.

One quick question before I award you the money... say I want to put a div, more specifically this one:

<div class="excerpt_content<?php if ( has_post_thumbnail() ) echo ' with-thumbnail'; ?>">
</div>


In a single if statement like the one below. How would I do that? (Wrap it around the entire statement)

if ( has_post_format( 'aside' )) {
?>
<span class="icon-aside"></span>
<a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
</a>
<span class="sub-title">Posted <?php the_time("F j, Y"); ?> by <?php the_author_posts_link(); ?> in <?php the_category(', ') ?></span>
<span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
<?php the_excerpt();
}


Fahad Murtaza comments:

That should do it



<div class="excerpt_content<?php if ( has_post_thumbnail() ) { echo ' with-thumbnail';} ?>">

<?php
if ( has_post_format( 'aside' )) {

?>

<span class="icon-aside"></span>

<a href="<?php the_permalink() ?>">

<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>

</a>

<span class="sub-title">Posted <?php the_time("F j, Y"); ?> by <?php the_author_posts_link(); ?> in <?php the_category(', ') ?></span>

<span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>

<?php the_excerpt();

}
?>
</div>


Fahad Murtaza comments:

Even better conditional structure for your first question would be if else based like below



<?php get_header(); ?>

<div id="container">
<div id="post_content2">
<div id="main_index">
<div class="main_adjust">

<!-- Grab posts -->

<?php while (have_posts()) : the_post(); ?>

<!-- Begin excerpt wrap -->

<div class="excerpt_wrap">
<div class="excerpt_inside">

<!-- Post formats -->

<?php

if ( has_post_format( 'aside' )) {

?>
<span class="icon-aside"></span> <a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
</a> <span class="sub-title">Posted
<?php the_time("F j, Y"); ?>
by
<?php the_author_posts_link(); ?>
in
<?php the_category(', ') ?>
</span> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span>
<?php the_excerpt();

}

elseif ( has_post_format( 'chat' )) {

?>
<span class="icon-chat"></span> <a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
</a> <span class="sub-title">
<?php the_time("F j, Y"); ?>
&nbsp;/&nbsp;
<?php the_author_posts_link(); ?>
&nbsp;/&nbsp;
<?php the_category(', ') ?>
</span> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span>
<?php the_excerpt();

}

elseif ( has_post_format( 'gallery' )) {

?>
<span class="icon-gallery"></span> <a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
</a> <span class="sub-title">
<?php the_author_posts_link(); ?>
&nbsp;/&nbsp;
<?php the_category(', ') ?>
&nbsp;/&nbsp;
<?php the_time("F j, Y"); ?>
</span> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span>
<?php the_content(); ?>
<?php comments_number( 'no responses', 'one response', '% responses' );

}

elseif ( has_post_format( 'image' )) {

?>
<span class="icon-image"></span> <a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
</a> <span class="sub-title">
<?php the_time("F j, Y"); ?>
&nbsp;/&nbsp;
<?php the_author_posts_link(); ?>
&nbsp;/&nbsp;
<?php the_category(', ') ?>
</span> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span>
<?php the_excerpt();

}

elseif ( has_post_format( 'link' )) {

?>
<span class="icon-link"></span>
<h1><a href="<?php echo $first_link = catch_that_link(); ?>">
<?php the_title(); ?>
</a></h1>
<a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
</a> <span class="sub-title">
<?php the_time("F j, Y"); ?>
&nbsp;/&nbsp;
<?php the_author_posts_link(); ?>
&nbsp;/&nbsp;
<?php the_category(', ') ?>
</span>
<?php comments_number( 'no responses', 'one response', '% responses' );

}

elseif ( has_post_format( 'quote' )) {

?>
<span class="icon-quote"></span> <a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
</a> <span class="sub-title">
<?php the_time("F j, Y"); ?>
&nbsp;/&nbsp;
<?php the_author_posts_link(); ?>
&nbsp;/&nbsp;
<?php the_category(', ') ?>
</span> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span>
<?php the_content();

}

elseif ( has_post_format( 'status' )) {

?>
<span class="icon-status"></span> <a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
</a> <span class="sub-title">
<?php the_time("F j, Y"); ?>
&nbsp;/&nbsp;
<?php the_author_posts_link(); ?>
&nbsp;/&nbsp;
<?php the_category(', ') ?>
</span> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span>
<?php the_excerpt();

}

elseif ( has_post_format( 'video' )) {

?>
<span class="icon-video"></span> <span class="sub-title">
<?php the_time("F j, Y"); ?>
&nbsp;/&nbsp;
<?php the_author_posts_link(); ?>
&nbsp;/&nbsp;
<?php the_category(', ') ?>
</span> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span>
<?php the_content();

}

elseif ( has_post_format( 'audio' )) {

?>
<span class="icon-audio"></span> <a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
</a> <span class="sub-title">
<?php the_time("F j, Y"); ?>
&nbsp;/&nbsp;
<?php the_author_posts_link(); ?>
&nbsp;/&nbsp;
<?php the_category(', ') ?>
</span> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span>
<?php the_content();

}

else {

$format = get_post_format();

if ( false === $format ) {
?>
<!-- No post format -->

<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink() ?>">
<?php the_post_thumbnail( 'thmb-index' ); ?>
</a>
<?php } ?>
<div class="excerpt_content<?php if ( has_post_thumbnail() ) echo ' with-thumbnail'; ?>"> <span class="index_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></span> <span class="sub-title">By
<?php the_author_posts_link( ); ?>
<span class="sub-title-divider">|</span>
<?php the_time('F j, Y'); ?>
<span class="sub-title-divider">|</span> <a href="<?php the_permalink(); ?>/#commentlist">
<?php comments_number( 'No comments', 'One comment', '% comments' ); ?>
</a></span>
<?php the_excerpt(); ?>
</div>

<!-- End excerpt wrap -->

</div>
</div>
<?php } // ending the if ( false === $format ) ...
} // end else
?>
<?php endwhile; ?>

<!-- Next/Previous entries -->

<div class="mp_archive">
<div id="more_posts">
<div class="oe">
<?php next_posts_link('&laquo; Older') ?>
</div>
<div class="re">
<?php previous_posts_link ('Newer &raquo;') ?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php get_sidebar(); ?>
</div>
</div>
<?php get_footer(); ?>


Lucas Wynne comments:

The new, better code, is returning a bunch of errors: [[LINK href="http://validator.w3.org/check?uri=http%3A%2F%2Fthemeforward.com%2Fdemo2%2F&charset=%28detect+automatically%29&doctype=Inline&group=0&user-agent=W3C_Validator%2F1.2"]]http://validator.w3.org/check?uri=http%3A%2F%2Fthemeforward.com%2Fdemo2%2F&charset=%28detect+automatically%29&doctype=Inline&group=0&user-agent=W3C_Validator%2F1.2[[/LINK]]

The site: [[LINK href="http://themeforward.com/demo2"]]themeforward.com/demo2[[/LINK]]


Lucas Wynne comments:

Take a look at my updated question please! :-)

2011-09-15

Gabriel Reguly answers:

Hi Lucas,


if ( has_post_format( 'aside' )
|| ( has_post_format( 'chat' )
|| ( has_post_format( 'gallery' )
|| ( has_post_format( 'image' )
|| ( has_post_format( 'link' )
|| ( has_post_format( 'quote' )
|| ( has_post_format( 'status' )
|| ( has_post_format( 'video' )
|| ( has_post_format( 'audio' )) {

CODE GOES HERE

}


Regards,
Gabriel