I am trying to simply output all posts but everything is working fine but I want to add the classes in the tag but the classes gets written in plain text not into the tag.
my code:
<?php
if (have_posts()) :
// Start the Loop.
while (have_posts()) : the_post();
echo '<article id="post-' . get_the_ID() . '" ' . post_class() . '>';
twentyfourteen_post_thumbnail();
the_title('<h1 class="entry-title">', '</h1>');
echo '<div class="entry-summary">';
the_excerpt();
echo '</div>';
echo '</article>';
endwhile;
endif;
?>
I think it has something to do with the chaining but I tried everything... :(
Replace
echo '<article id="post-' . get_the_ID() . '" ' . post_class() . '>';
with
echo '<article id="post-' . get_the_ID() . '" ';
post_class();
echo '>';
Related
I want to implement an ajax post filter based on category and found this which works: https://rudrastyh.com/wordpress/ajax-post-filters.html
The only thing is that I would like the post output from function.php to be different. Originally it is just:
echo '<h2>' . $query->post->post_title . '</h2>';
but I want to use my own post loop configuration:
<div <?php post_class( 'front-post-small col-front' ); ?> id="post-<?php the_ID(); ?>">
<a href="<?php echo esc_url( the_permalink() ); ?>">
<div class="front-post-img">
<?php the_post_thumbnail( array(756,512) ); ?>
<div class="post-caption">
<h3 class="text-uppercase front-post-title"><?php the_title(); ?></h3>
</div>
</div>
</a>
</div>
I have tried passing it with echo, but it either doesn't work at all or the classes and links are printed instead of producing links and css.
Solved:
echo '<div class="front-post-small col-front">';
echo '<a href="' . get_permalink() . '">';
echo '<div class="front-post-img">';
echo '<img' . the_post_thumbnail( array(756,512) ) . '>';
echo '<h3 class="text-uppercase front-post-title post-caption">' . $query->post->post_title . '</h3>';
echo '</div>';
echo '</a>';
echo '</div>';
Trying to edit the post page inside our theme and wanted to add the thumbnail image above the post title but it keeps placing the thumbnail at the end of the post title. Any help is appreciated.
if (have_posts()) :
echo "<h1>" . __('Valhalla Integration Blog','avia_framework') . "</h1>";
echo "<ul>";
while (have_posts()) : the_post();
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
echo "<li><h4><a href='".get_permalink()."' rel='bookmark' title='". __('Permanent Link:','avia_framework')." ".the_title_attribute('echo=0')."'>".get_the_title()."</a></h4></li>";
endwhile;
echo "</ul>";
else:
echo "<h3>" . __('No Blog Posts found','avia_framework') . "</h3>";
endif;
You're echoing an <img> tag into a <ul> which is invalid HTML. I modified it to echo the image inside the <li> which also contains your title.
if (have_posts()) :
echo "<h1>" . __('Valhalla Integration Blog','avia_framework') . "</h1>";
echo "<ul>";
while (have_posts()) : the_post();
echo "<li>";
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
echo "<h4><a href='".get_permalink()."' rel='bookmark' title='". __('Permanent Link:','avia_framework')." ".the_title_attribute('echo=0')."'>".get_the_title()."</a></h4></li>";
endwhile;
echo "</ul>";
else:
echo "<h3>" . __('No Blog Posts found','avia_framework') . "</h3>";
endif;
I am wrapping my head on wordpress loop at the moment, im trying to give tags to the respective content, so an H tag to the title, an p tag to the excerpt and so on...
The code i got so far is
<div id="<?php echo $page_id; ?>" class="container"><!-- begin container -->
<div id="postovi" style="display:none;">
<?php $custom_loop = new
WP_Query('showposts=5&category_name=Zanimljivosti&orderby=rand');
if ( $custom_loop->have_posts() ) : echo '<ul>'; while ( $custom_loop->have_posts() ) : $custom_loop->the_post(); echo '<li>' . get_the_title() . get_the_post_thumbnail($loop->post->ID, 'shop_catalog') . get_the_excerpt();'</li>'; endwhile; wp_reset_query(); echo '</ul>';endif;?> </div>
any suggestions apreciated :)
So your solution is :
<?php
$custom_loop = new WP_Query('showposts=5&category_name=Zanimljivosti&orderby=rand');
if ( $custom_loop->have_posts() ) :
echo '<ul>';
while ( $custom_loop->have_posts() ) :
$custom_loop->the_post(); echo '<li><h2><a href="' . get_permalink() . '">' . get_the_title();
echo '</h2>' . get_the_post_thumbnail($loop->post->ID, 'shop_catalog');
echo'<p>' . get_the_excerpt();'</p></a></li>';
endwhile; wp_reset_query();
echo '</ul>';endif;
?>
I'm working on a Wordpress index page that only shows posts if they have a featured image. This is my content.php code:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="col-sm-4">
<?php
if (has_post_thumbnail()) {
echo '<div class="small-index-thumbnail clear">';
echo '<a href="' . get_permalink() . '" title="' . get_the_title() . '" rel="bookmark">';
echo the_post_thumbnail('index-thumb');
echo '</a>';
echo '</div>';
}
?>
</div>
</article><!-- #post-## -->
I'm just wondering if this is enough code for someone to tell me why it's still showing the posts, despite the posts not having a featured image. Thank you!
Actually, it looks right but there is a note about this on Codex, which is something like this:
// Must be inside a loop.
if ( has_post_thumbnail() ) {
// ...
}
Note The above code apparently fails in some instances and the below code is "recommended"
if ( '' != get_the_post_thumbnail() ) {
// some code
} else {
// some code
}
Check get_the_post_thumbnail if needed.
I wanted to show post from just recent post from a specific categories
so far this is what I have but:
<ul>
<?php
$number_recents_post = 5;
$recent_posts = wp_get_recent_posts($number_recents_post);
foreach($recent_posts as $post){
echo '<li><a href="' . get_permalink($post["ID"]) . '" title="Look '.$post["post_title"].'" >' . $post["post_title"].'</a> </li> ';
} ?>
</ul>
I tried turning it into this but not working
<ul>
<?php
$number_recents_post = 5;
$recent_posts = wp_get_recent_posts($number_recents_post . 'cat=3,4,5');
foreach($recent_posts as $post){
echo '<li><a href="' . get_permalink($post["ID"]) . '" title="Look '.$post["post_title"].'" >' . $post["post_title"].'</a> </li> ';
} ?>
</ul>
Please let me know what am I doing wrong....
According to the Codex, you can't use wp_get_recent_posts() the way you do:
Parameters
$num
(integer) (optional) Number of posts to get.
Default: 10
Maybe codedude's example helps.
why don't you try this (assuming you are using Wordpress)
<?php query_posts('post_per_page=5&category_name=yourcategoryname'); ?>
<?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>
<?php endwhile; else: ?>
<p>An error Message</p>
<?php endif; ?>