I'm new to WordPress and I'm hoping to display post formats differently on the home page; sort of like this image:
The problem is that the theme I'm using is very different than other themes I've seen, the loop is in a function.
In my index.php
, I have
<?php
if(have_posts()) :
while(have_posts()) : the_post();
echo cool_post_article_normal_block();
endwhile;
endif;
?>
In the function it says:
function cool_post_article_normal_block ($usecategory = false)
{
add_filter( 'excerpt_length', 'cool_article_excerpt_latest_length', 999 );
add_filter('excerpt_more', 'cool_article_excerpt_latest_more');
$timeformat = "<time class='post-date' datetime='" . get_the_time("Y-m-d H:i:s") . "'>" . get_the_time("F j, Y ") . "</time>";
$categoryarray = get_the_category();
$categorytext = '';
if(!empty($categoryarray))
$categorytext = "<span class='post-category'><a href='" . get_category_link($categoryarray[0]->term_id) . "' rel='category'>" . $categoryarray[0]->name . "</a></span>";
$authorurl = get_author_posts_url(get_the_author_meta('ID'));
$authorname = apply_filters('cool_get_author_name', null);
$authortext = '<span class="post-author">'. __('By', 'cool_textdomain') . ' <a href="' . $authorurl .'" rel="author">' . $authorname .'</a></span>';
$firsttext = $authortext;
if($usecategory) {
$firsttext = $categorytext;
}
$post_class = get_post_class(array('review-list', 'clearfix'), get_the_ID());
if(is_sticky()) {
$htmlcontent =
'<article class="'. implode(' ', $post_class) .'">
<div class="col-md-6">
' . apply_filters('cool_featured_figure_lazy', null, 'half-post-featured') . '
</div>
<div class="col-md-6">
<div class="">
<header class="content">
<h2 class="post-title"><a href="'. get_permalink(get_the_ID()) .'">'. get_the_title() .'</a></h2>
</header>
<div class="post-meta">
' . $firsttext . '
' . $timeformat . '
</div>
<div class="post-excerpt">
<p>'. get_the_excerpt() .'</p>
</div>
</div>
</div>
</article>';
} else {
$htmlcontent =
'<article class="'. implode(' ', $post_class) .'">
<div class="col-md-5">
' . apply_filters('cool_featured_figure_lazy', null, 'half-post-featured') . '
</div>
<div class="col-md-7">
<div class="">
<header class="content">
<h2 class="post-title"><a href="'. get_permalink(get_the_ID()) .'">'. get_the_title() .'</a></h2>
</header>
<div class="post-meta">
' . $firsttext . '
' . $timeformat . '
</div>
<div class="post-excerpt">
<p>'. get_the_excerpt() .'</p>
</div>
</div>
</div>
</article>';
}
remove_filter( 'excerpt_length', 'cool_article_excerpt_latest_length');
remove_filter( 'excerpt_more', 'cool_article_excerpt_latest_more');
return $htmlcontent;
}
What I understand is that I'm supposed to modify between <article></article>
but what I don't know how to do is get the post format conditionally; especially since there is already a sticky conditional-- and I don't know PHP well :(
I'm very new to PHP so I'm unsure how to do this. I have several post formats activated: quote
, video
, gallery
, audio
and image
.
I'd like the loop to go something like:
if (sticky) {
if (quote)
show title only
} elseif (video, audio, gallery) {
show title
show excerpt
} elseif(image){
show title
show featured image
} else {
if (quote) {
show title only
}elseif (video, audio, gallery){
show title
show excerpt
} elseif (image) {
show title
show featured image
}