Odd number of posts aren't showing up - php

Using bootstrap in wordpress, I'm trying to get my blog page to have the 1st latest post as a col-sm-12 (which is working) and then have the remaining posts fall into 2 columns where all the even # posts show up in the left column and the odd # posts show up in the right column. My left column loop is working but my right column isn't pulling the odd posts starting at the 3rd post ... please help! http://dev.starship.capital/blog/
<div class="container">
<div class="row">
<h2 style="color: white; text-align: center;">Latest Posts</h2>
<?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) == 0) : $wp_query->next_post(); else : the_post(); ?>
<?php endif; endwhile; else: ?>
<div class="col-md-6 entry blog-menu">
<article class="entry">
<a href="<?php the_permalink(); ?>">
<div class="blog-overlay"></div>
<?php if ( has_post_thumbnail()) the_post_thumbnail('excerpt-thumb'); ?>
</a>
<div class="entry-content clear">
<div style="padding: 1% 15%;">
<?php the_category(); ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<p>Posted on: <?php the_time(get_option('date_format') ); ?> By <?php the_author(); ?> | <?php $totalcomments = get_comments_number(); echo $totalcomments; ?> Comments</p>
</div>
</div>
</article>
<?php endif; ?>
</div>
<?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) !== 0) : $wp_query->next_post(); else : the_post(); ?>
<?php endif; endwhile; else: ?>
<div class="col-md-6 entry blog-menu">
<article class="entry">
<a href="<?php the_permalink(); ?>">
<div class="blog-overlay"></div>
<?php if ( has_post_thumbnail()) the_post_thumbnail('excerpt-thumb'); ?>
</a>
<div class="entry-content clear">
<div style="padding: 1% 15%;">
<?php the_category(); ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<p>Posted on: <?php the_time(get_option('date_format') ); ?> By <?php the_author(); ?> | <?php $totalcomments = get_comments_number(); echo $totalcomments; ?> Comments</p>
</div>
</div>
</article>
<?php endif; ?>
<?php endwhile; ?>
</div>
</div>

Related

Looking to make archive.php display in two columns for Wordpress site

Very new Wordpress apprentice here. Trying to get my archive page to display posts in two columns going like:
Post 1 Post 2
Post 3 Post 4
Here is an example from a figma we were working on: https://ibb.co/N3XwtwD
My question is, what code can I add to my files to allow this? I currently have some bootstrap classes on the html portion I inserted here and it is displaying as one column, so I don't know if those classes will interfere with anything. Here is my archive.php code below:
<?php
get_header();
?>
<div class="container mt-5 mb-5">
<p class="font-size"><?php the_archive_title(); ?></p>
<hr>
</div>
<div class="container">
<?php
while(have_posts()) {
the_post(); ?>
<div class="row">
<div class="col-lg-6">
<p class="font-size text-center"><?php the_title();?></p>
<img class="img-fluid mb-3"<?php
the_post_thumbnail();
?>
<p class="category-font">Published on <?php the_time('n.j.y');?></p>
<p>Posted by <?php the_author_posts_link() ?></p>
</div>
</div>
<?php }
echo paginate_links();
?>
</div>
<?php
get_footer();
?>
First time posting here so apologies if I left anything important out. Really appreciate this place!
Thanks!
You need to create a row every two posts and you have to add <div class="col-lg-6"> two times in a row. check below code.
<?php get_header(); ?>
<div class="container mt-5 mb-5">
<p class="font-size"><?php the_archive_title(); ?></p>
<hr>
</div>
<div class="container">
<?php
$count = 1;
while( have_posts() ) { the_post();
if ( $count % 2 == 1){ ?>
<div class="row">
<?php } ?>
<div class="col-lg-6">
<p class="font-size text-center"><?php the_title();?></p>
<?php the_post_thumbnail(); ?>
<p class="category-font">Published on <?php the_time('n.j.y');?></p>
<p>Posted by <?php the_author_posts_link() ?></p>
</div>
<?php if ( $count % 2 == 0 ){ ?>
</div>
<?php } $count++; ?>
<?php }
if ( $count % 2 != 1 ) echo "</div>";
echo paginate_links(); ?>
</div>
Please replace with the below code that helps you.
<?php
get_header();
?>
<div class="container mt-5 mb-5">
<p class="font-size"><?php the_archive_title(); ?></p>
<hr>
</div>
<div class="container">
<?php
$counterval = 0;
while(have_posts()) {
the_post();
$counterval++;
if($counterval % 2 != 0)
{ ?>
<div class="row">
<?php } ?>
<div class="col-lg-6">
<p class="font-size text-center"><?php the_title();?></p>
<?php $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full');
if(!empty($featured_img_url)){ ?>
<img class="img-fluid mb-3" src="<?php echo esc_url($featured_img_url); ?>" />
<?php } ?>
<p class="category-font">Published on <?php the_time('n.j.y');?></p>
<p>Posted by <?php the_author_posts_link() ?></p>
</div>
<?php
if($counterval % 2 == 0)
{ ?>
</div>
<?php } ?>
<?php } ?>
<?php echo paginate_links();
?>
</div>
<?php
get_footer();
?>

How to change the WordPress search results page (using Betheme and Ajax search lite)

I'm currently working on a website for a client and I want to change the search results page. I tried a lot of things but when I search for something on the website I get search results, but without a image or description. My client want the website to show a image and a description.
Here is my search.php code:
/**
* The search template file.
*
* #package Betheme
* #author Muffin group
* #link https://muffingroup.com
*/
get_header();
$translate['search-title'] = mfn_opts_get('translate') ? mfn_opts_get('translate-search-title','Ooops...') : __('Ooops...','betheme');
$translate['search-subtitle'] = mfn_opts_get('translate') ? mfn_opts_get('translate-search-subtitle','No results found for:') : __('No results found for:','betheme');
$translate['published'] = mfn_opts_get('translate') ? mfn_opts_get('translate-published','Published by') : __('Published by','betheme');
$translate['at'] = mfn_opts_get('translate') ? mfn_opts_get('translate-at','at') : __('at','betheme');
$translate['readmore'] = mfn_opts_get('translate') ? mfn_opts_get('translate-readmore','Read more') : __('Read more','betheme');
?>
<div id="Content">
<div class="content_wrapper clearfix">
<div class="sections_group">
<div class="section">
<div class="section_wrapper clearfix">
<?php if( have_posts() && trim( $_GET['s'] ) ): ?>
<div class="column one column_blog">
<div class="blog_wrapper isotope_wrapper">
<div class="posts_group classic">
<?php
while ( have_posts() ):
the_post();
?>
<div id="post-<?php the_ID(); ?>" <?php post_class( array('post-item', 'clearfix', 'no-img') ); ?>>
<div class="post-desc-wrapper">
<div class="post-desc">
<?php if( mfn_opts_get( 'blog-meta' ) ): ?>
<div class="post-meta clearfix">
<div class="author-date">
<span class="author"><span><?php echo esc_html($translate['published']); ?> </span><i class="icon-user"></i> <?php the_author_meta('display_name'); ?></span>
<span class="date"><span><?php echo esc_html($translate['at']); ?> </span><i class="icon-clock"></i> <?php echo esc_html(get_the_date()); ?></span>
</div>
</div>
<?php endif; ?>
<div class="post-title">
<h2><?php the_title(); ?></h2>
</div>
<div class="post-excerpt">
<?php the_excerpt(); ?>
</div>
<div class="post-footer">
<div class="post-links">
<i class="icon-doc-text"></i> <?php echo esc_html($translate['readmore']); ?>
</div>
</div>
</div>
</div>
</div>
<?php
endwhile;
?>
</div>
<?php
if(function_exists( 'mfn_pagination' )):
echo mfn_pagination();
else:
?>
<div class="nav-next"><?php next_posts_link(esc_html__('← Older Entries', 'betheme')) ?></div>
<div class="nav-previous"><?php previous_posts_link(esc_html__('Newer Entries →', 'betheme')) ?></div>
<?php
endif;
?>
</div>
</div>
<?php else: ?>
<div class="column one search-not-found">
<div class="snf-pic">
<i class="themecolor <?php echo esc_attr(mfn_opts_get('error404-icon', 'icon-traffic-cone')); ?>"></i>
</div>
<div class="snf-desc">
<h2><?php echo esc_html($translate['search-title']); ?></h2>
<h4><?php echo esc_html($translate['search-subtitle']) .' '. esc_html($_GET['s']); ?></h4>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php if( is_active_sidebar( 'mfn-search' ) ): ?>
<div class="sidebar four columns">
<div class="widget-area clearfix <?php echo esc_attr(mfn_opts_get('sidebar-lines')); ?>">
<?php dynamic_sidebar( 'mfn-search' ); ?>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php get_footer();
<?php $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full'); ?>
<div class="post-img">
<img src="<?php echo $featured_img_url; ?>"/>
</div>
use above code in while loop to show image by using post id.

tired to add pagination on single category.php page

im tried to add pagination and set post per page on my category.php page
how can i solve this
here need set post per page and also pagination
here is my code for category.php
thanks
<?php if( have_posts() ): ?>
<div class="cat-bread-cumb overflow-fix">
<u>
<li><i class="fa fa-home" aria-hidden="true"></i></li>
<li><span>/</span><?php the_archive_title(); ?></li>
</u>
</div>
<?php while( have_posts() ): the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( sprintf('<h1 class="entry-title">', esc_url( get_permalink() ) ),'</h1>' ); ?>
<small>Posted on: <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>, in <?php the_category(); ?></small>
</header>
<div class="row">
<?php if( has_post_thumbnail() ): ?>
<div class="col-xs-12 col-sm-4">
<div class="thumbnail"><?php the_post_thumbnail('medium'); ?></div>
</div>
<div class="col-xs-12 col-sm-8">
<?php the_content(); ?>
</div>
<?php else: ?>
<div class="col-xs-12">
<?php the_content(); ?>
</div>
<?php endif; ?>
</div>
</article>
<?php endwhile; ?>
<?php endif; ?>

WP - Archive.php - Not showing all posts in a category

I am not finding out why archive.php only shows maximum 10 posts in a category... Could you please help to find where the bug is?
<div id="blogg_header" class="col col-lg-12 col-sm-12"><div class="well">
<?php if (is_category()) {?>
<h1 class="title">Kategori: <i><?php single_cat_title(); ?> </i></h1>
<?php } elseif (is_month()) { ?>
<h2 clss="title"><?php the_time('F, Y'); ?></h2>
<?php } ?>
</div></div>
<div id="blogg_innlegg_left" class="col col-lg-8 col-sm-8"><div class="well">
<ul>
<?php if (have_posts()) :?>
<?php while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<a class id="linkforside" href="<?php the_permalink(); ?>">
<?php get_the_post_thumbnail($header_thumb->ID);?><br/>
</a>
<p class id="infotekst"><?php the_time('d.m.Y') ?></p>
<p class="blogg_innlegg_teksten"><?php echo substr(strip_tags($post->post_content), 0, 250);?></p>
<?php endwhile; ?>
<?php else : ?>
<h2>Ingenting ble funnet.</h2>
<?php endif; ?>
</ul>
</div></div>
I guess I may need to insert the following:
<?php wp_get_archives('type=postbypost&limit=none'); ?>

wordpress the_content() == null although $page->content returns value

Any ideas why the_content() is returning null? When I use $page->content in the same place, this returns the correct value from database.
<?php get_header(); ?>
<div id="main" class="clearfix" role="main">
<?php $attachments = new Attachments( 'attachments' ); ?>
<?php if( $attachments->exist() ) : ?>
<div id="myCarousel" class="carousel">
<!-- Carousel items -->
<div class="carousel-inner">
<?php $i = 0; while( $attachments->get() ) : $i++; ?>
<div class="<?php if($i == 1){ echo 'active'; } ?> item item-<?php echo $attachments->id(); ?>">
<?php echo $attachments->image( 'featured-home' ); ?>
<?php if($attachments->field('caption')){ ?>
<div class="carousel-caption">
<?php echo $attachments->field('caption'); ?>
</div>
<?php } ?>
</div>
<?php endwhile; ?>
</div>
<?php if($i > 1) { ?>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">›</a>
<?php } ?>
<div class="carousel-overlay icons">
Facebook
Twitter
YouTube
RSS Feed
</div>
</div>
<?php endif; ?>
<?php if (have_posts()) : ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(array('row-fluid','clearfix')); ?> role="article">
<div id="content" class="span8">
<header>
<h1><?php echo get_post_meta($post->ID, 'custom_tagline' , true);?></h1>
<?php the_content(); ?>
</header>
<section class="post_content hasSidebar">
<?php query_posts('showposts=10');
while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article">
<header>
<?php the_post_thumbnail( 'wpbs-featured' ); ?>
<h2><?php the_title(); ?></h2>
<?php if(get_comments_number() >= 1): ?>
<a href="<?php comments_link() ?>" title="<?php comment_date() . ' - ' . comment_excerpt(); ?>" <?php comment_class(); ?>><?php comments_number(); ?></a>
<?php endif; ?>
<p class="meta"><?php _e("Posted", "bonestheme"); ?> <time datetime="<?php echo the_time('Y-m-j'); ?>" pubdate><?php the_date(); ?></time> <?php _e("by", "bonestheme"); ?> <?php the_author_posts_link(); ?> <span class="amp">&</span> <?php _e("filed under", "bonestheme"); ?> <?php the_category(', '); ?>.</p>
</header>
<section class="post_content">
<?php the_excerpt(); ?>
</section>
<?php if(has_tag()): ?>
<footer>
<p class="tags"><?php the_tags('<span class="tags-title">' . __("Tags","bonestheme") . ':</span> ', ' ', ''); ?></p>
</footer>
<?php endif; ?>
</article>
<?php endwhile ?>
<?php content_paging_nav('nav-below'); ?>
</section>
<footer>
<p class="clearfix"><?php the_tags('<span class="tags">' . __("Tags","bonestheme") . ': ', ', ', '</span>'); ?></p>
</footer>
</div>
<?php get_sidebar('sidebar2'); ?>
</article>
<?php else : ?>
<article id="post-not-found">
<header>
<h1><?php _e("Not Found", "bonestheme"); ?></h1>
</header>
<section class="post_content">
<p><?php _e("Apologies, but no results were found. Perhaps searching will help find a related post.", "bonestheme"); ?></p>
</section>
<footer>
</footer>
</article>
<?php endif; ?>
</div> <!-- end #main -->
<?php //get_sidebar(); // sidebar 1 ?>
<?php get_footer(); ?>
You're not in a WP loop. You should call e.g. the_post() to set up WP's slew of globals.
Beware of nested WP loops, too. There used to be a gazillion bugs related to them, and there might still be a few lying around just waiting to bite.

Categories