Wordpress divide posts into two divs - wordpress

I want to divide word press posts into two div but its not working with query posts
how do i achive this?
first ten post in one div and other ten posts in Other div.
<div class="col6">
<ul class="que_ul clearfix">
first ten post
</ul>
</div>
<div class="col6 last">
<ul class="que_ul clearfix">
nex ten posts
</ul>
</div>

You can do something like this
<?php
global $wbdb;
$querystr = "
SELECT *
FROM $wpdb->posts
WHERE $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'faq'
LIMIT 0 , 20";
$pageposts = $wpdb->get_results($querystr, OBJECT);?>
<?php $data_name=array(); ?>
<?php foreach($pageposts as $posts):?>
<?php
$data_name[]=$posts->post_title;
?>
<?php endforeach;?>
<div class="col6">
<ul class="que_ul clearfix">
<?php for($i=0;$i<10;$i++): ?>
<?php if(!empty($data_name[$i])):?> <li><?php echo $data_name[$i]; ?></li> <?php endif;?>
<?php endfor;?>
</ul><!-- end que_ul -->
</div><!-- end col-->
<div class="col6 last">
<ul class="que_ul clearfix">
<?php for($i=10;$i<20;$i++): ?>
<?php if(!empty($data_name[$i])):?> <li><?php echo $data_name[$i]; ?></li> <?php endif;?>
<?php endfor;?>
</ul><!-- end que_ul -->
</div><!-- end col6 last -->

take a look here: http://digwp.com/2010/03/wordpress-post-content-multiple-columns/
I have used this in the past and found that
More flexible multiple columns
Is the option that works best.

Related

How to get custom post type data filter by custom taxonomy

Struggle to get all the records mapped by custom taxonomies.
I have registered a custom post type i.e. job_post and custom taxonomy i.e. countries. I wanted to show all job posts (having job_title, job_location, and permalink to specific job post) which are filtered by Countries (i.e. India & USA). I had Mapped almost 10 job posts under the India category and 18 job posts under the USA category.
I have displayed the records through toggle tabs (i.e. India and USA). I can fetch only one record by each category through the below code:
<section class="container container_filter">
<div class="filters filter-button-group">
<ul class="nav nav-tabs">
<?php
$terms= get_terms('countries');
foreach($terms as $cat_term)
{ ?>
<li><a data-toggle="tab" href="#<?php echo $cat_term->slug;?>"><?php echo $cat_term->name; ?></a></li>
<?php } ?>
</ul>
<div class="tab-content">
<?php
global $post;
$args= array('post_type'=> 'job_post', 'post_per_page' => -1);
$the_query = new WP_Query($args);
if($the_query->have_posts()):
while ($the_query->have_posts()) : $the_query->the_post();?>
<?php
$termsArray= get_the_terms(get_the_ID(), 'countries');
$term_id=$termsArray->id;
foreach ($termsArray as $term){
$termsSlug = $term->slug;
}
?>
<div id="<?php echo $termsSlug;?>" class="tab-pane fade">
<div class='col-md-6'>
<a class='job-card readmoreCustom' href='<?php the_permalink($term_id); ?>'>
<div class='content'>
<h3 class='title'><?php echo get_the_title($term_id) ?></h3>
<p class='job_location'><?php the_field('job_location'); ?></p>
</div>
<span class='more'>KNOW MORE<span class="readIcon"> > </span></span>
</a>
</div>
</div>
<?php
endwhile;
wp_reset_query();
?>
<?php else: ?>
<?php _e('Sorry, no jobs matches your criteria'); ?>
<?php endif; ?>
</div>
</div>
</section>
How can I fetch all the records from both categories under specific tabs? Help is appreciated.
<section class="container container_filter">
<div class="filters filter-button-group">
<ul class="nav nav-tabs">
<?php
$terms= get_terms('countries');
foreach($terms as $cat_term)
{ ?>
<li><a data-toggle="tab" href="#<?php echo $cat_term->slug;?>"><?php echo $cat_term->name; ?></a></li>
<?php } ?>
</ul>
<div class="tab-content">
<?php
global $post;
$args= array('post_type'=> 'job_post', 'post_per_page' => -1);
$the_query = new WP_Query($args);
if($the_query->have_posts()):
while ($the_query->have_posts()) : $the_query->the_post();?>
<?php
$termsArray= get_the_terms(get_the_ID(), 'countries');
$term_id=$termsArray[0]->term_id;
foreach ($termsArray as $term){
$termsSlug = $term->slug;
}
?>
<div id="<?php echo $termsSlug;?>" class="tab-pane fade">
<div class='col-md-6'>
<a class='job-card readmoreCustom' href='<?php the_permalink(); ?>'>
<div class='content'>
<h3 class='title'><?php echo get_the_title(); ?></h3>
<p class='job_location'><?php the_field('job_location'); ?></p>
</div>
<span class='more'>KNOW MORE<span class="readIcon"> > </span></span>
</a>
</div>
</div>
<?php
endwhile;
wp_reset_query();
?>
<?php else: ?>
<?php _e('Sorry, no jobs matches your criteria'); ?>
<?php endif; ?>
</div>
</div>
</section>
The below loop is fine if the post is in only 1 country but if it's in multiple counties the loop should be closed after div
foreach ($termsArray as $term){
$termsSlug = $term->slug;
}

Having an archive page with categories and tags

I'd like to have an archive (alternative to search) with Categories and Tags listed on one page. Is this possible? Can't seem to find any information on it.
Title/Archive Search<
Browse by category:
cat 1, cat 2 etc.
(Something more specific) Browse by Tags:
tag 1, tag 2 etc.
Something like this maybe?
<?php get_header(); ?>
<div id="container">
<div id="content" role="main">
<?php the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php get_search_form(); ?>
<h2>Browse by month:</h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>
<h2>Browse by category:</h2>
<ul>
<?php wp_list_categories(); ?>
</ul>
<h2>Browse by tags:</h2>
<ul>
<?php wp_tag_cloud(','); ?>
</ul>
</div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Different column width in 2 rows with bootstrap and custom post types

I'm using a custom post type on my WP website and also using bootstrap.
I want to list 5 custom post type entries on my home page, and I want the first 3 to have class col-md-4 in one row and in the next row 2 cpt entries to have the class col-md-6
At the moment I have a class col-md-4 and 2 items in the 2nd row are not centered nicely.
This is my current code:
<div class="container-fluid gray-section">
<div class="container">
<div class="row">
<?php
$projects = get_posts(array('post_type'=>'project','posts_per_page'=>5, 'order'=>'ASC'));
if ($projects) { ?>
<ul class="list-unstyled">
<?php foreach ($projects as $post) { setup_postdata( $post ) ?>
<li class="col-md-4 col-sm-6 col-xs-12 col-xxs-12 text-center ">
<a class="highlights-item" href="<?php echo get_permalink(); ?>">
<div class="highlights-container">
<?php the_post_thumbnail(); ?>
<span class="highlights-title">
<?php the_excerpt(); ?>
</span>
</div>
</a>
</li>
<?php } wp_reset_postdata(); ?>
</ul>
<?php }
?>
</div> <!-- end row -->
</div> <!-- end container -->
</div> <!-- end container fluid -->
Any suggestions how to fix this?
This sort of issue is usually solved by adding a count to foreach loop and adding 1 each time. Then within the loop you can check what the count is and apply specific classes. e.g.
<div class="container-fluid gray-section">
<div class="container">
<div class="row">
<?php
$projects = get_posts(
array(
'post_type'=>'project',
'posts_per_page'=>5,
'order'=>'ASC'
)
);
if ($projects) { $count = 1; ?>
<ul class="list-unstyled">
<?php foreach ($projects as $post) {
setup_postdata( $post );
if( $count >= 4 ) { $extra_class = 'col-md-6'; }
else { $extra_class = 'col-md-4'; }
?>
<li class="<?php echo $extra_class; ?> col-sm-6 col-xs-12 col-xxs-12 text-center ">
<a class="highlights-item" href="<?php echo get_permalink(); ?>">
<div class="highlights-container">
<?php the_post_thumbnail(); ?>
<span class="highlights-title">
<?php the_excerpt(); ?>
</span>
</div>
</a>
</li>
<?php $count++; } wp_reset_postdata(); ?>
</ul>
<?php }
?>
</div> <!-- end row -->
</div> <!-- end container -->
</div> <!-- end container fluid -->
Give that a go...
Regards
Dan
<?php
$i = 0;
foreach ($projects as $post) { setup_postdata( $post )
?>
<li class="<?php echo ($i>2):'col-md-6'?'col-md-4' ?> col-sm-6 col-xs-12 col-xxs-12 text-center ">
<a class="highlights-item" href="<?php echo get_permalink(); ?>">
<div class="highlights-container">
<?php the_post_thumbnail(); ?>
<span class="highlights-title">
<?php the_excerpt(); ?>
</span>
</div>
</a>
</li>
<?php
$i++;
}
wp_reset_postdata();
?>

"Read more" doesn't appear on categories page of wordpress

"Read more" link appears on index page, while it doesn't on the separate category page. The categories page code is pretty much the same, as on index page.
<?php while ( have_posts() ) : the_post() ?>
<?php get_template_part( 'entry' ); ?>
<?php comments_template(); ?>
<?php endwhile; ?>
entire code of the page
<?php get_header(); ?>
<div class="container">
<div id="tabs">
<ul>
<li><div class="tabs1"><div id="t1"><div class="bmtxt"><?php
$post_id = 76;
$queried_post = get_post($post_id);
?>
<p><?php echo $queried_post->post_content; ?></p></div>
</div></div>
</li>
<li class="tabs2"><div class="tabs1"> <div id="t2"><div class="bmtxt"><?php
$post_id = 83;
$queried_post = get_post($post_id);
?>
<p><?php echo $queried_post->post_content; ?></p></div>
</div></div>
</li>
<li class="tabs2"><div class="tabs1"><div id="t3"><div class="bmtxt"><?php
$post_id = 92;
$queried_post = get_post($post_id);
?>
<p><?php echo $queried_post->post_content; ?></p></div>
</div></div>
</li>
<li class="tabs2"><div class="tabs1"><div id="t4"><div class="bmtxt"><?php
$post_id = 98;
$queried_post = get_post($post_id);
?>
<p><?php echo $queried_post->post_content; ?></p></div>
</div></div>
</li>
</ul>
</div>
</div>
<div class="container-full" id="cnt1">
<div class="container">
<div id="content">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'entry' ); ?>
<?php comments_template(); ?>
<?php endwhile; ?>
</div>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
And a little bit more text to allow the site all of this code
Try adding this under the article code:
<?php echo "<form action='";
echo the_permalink();
echo "' method='get'>";?>
<button>Read More..</button></form>
If there is more text it should pick it up
Error found:
<?php while(have_posts()) : the_post()?>
You are missing ";" before ?>
Use the_excerpt() instead of the_content().
In this link Modifying How Posts are Displayed section is useful to you to know about how to display the content.
Also in the code you have provided,
echo $queried_post->post_content;
is responsible for the content display. I don't know what theme you are using?. So instead of using post_content we have to use post_excerpt.

How to get Isotope Wordpress plugin mintthemes work?

I have installed the WordPress plugin Isotope from Mintthemes. But I don't get it to work. I have set the following snippet of code in my page.php and also filled in the optional settings for usage of custom post types.
<?php moveplugins_isotopes(); ?>
Added categories to my custom post type portfolio items but it doesn't work.
My code:
<?php moveplugins_isotopes(); ?>
<ul class="entrybox">
<?php
$args = array('post_type' => 'portfolio');
$loop = new WP_Query($args);
?>
<?php if ($loop->have_posts()) : while ($loop->have_posts()) : $loop->the_post(); ?>
<li class="grid_4 portfolio-post">
<a href="<?php the_permalink(); ?>">
<div class="thumbnail">
<img src="<?php print IMAGES; ?>/portfolio/thumbnails/thumbnail.png" alt="Thumbnail">
</div><!-- End .thumbnail -->
</a>
<div class="description">
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
</div><!-- End div.description -->
</li><!-- End li.grid_4 projectbox -->
<?php endwhile; ?>
<?php endif; ?>
</ul><!-- End ul.entrybox -->
The problem is that your li isn't using the post_class function in WordPress. It uses that post_class to identify which items are in the loop.
It should be something like
<li class="<?php post_class( array('grid_4', 'portfolio-post') ) ?>">
You can find out more about it here:
http://codex.wordpress.org/Function_Reference/post_class

Resources