Right now in my theme for my home page I have a row of 1 post, a row of 3 posts, 3 posts, and then back to a row of 1 post. After this loop I would like to add a new widget. I want to have a few different widgets like popular videos, popular posts, etc. Does anyone have any idea how I can do this?
Here is an example of what I want it to look like. I want a new widget for every 14 posts.
Here is are some examples of the different widgets I want to add (source - http://www.whowhatwear.com) -
Here is my front-page.php
<?php
/*
* Template Name: learningwordpress
*/
get_header();
get_template_part ('inc/carousel');
$i = 0;
$args = array(
'posts_per_page' => 14,
'paged' => 1
);
$the_query = new WP_Query($args);
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
if( $i %2 == 1 ) {
$the_query->the_post(); ?>
<article class="post col-md-4">
<?php the_post_thumbnail('medium-thumbnail'); ?>
<h2><?php the_title(); ?></h2>
<p>
<?php echo get_the_excerpt(); ?>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
</p>
</article>
<?php $the_query->the_post(); ?>
<article class="post col-md-4">
<?php the_post_thumbnail('medium-thumbnail'); ?>
<h2><?php the_title(); ?></h2>
<p>
<?php echo get_the_excerpt(); ?>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
</p>
</article>
<?php $the_query->the_post(); ?>
<article class="post col-md-4">
<?php the_post_thumbnail('medium-thumbnail'); ?>
<h2><?php the_title(); ?></h2>
<p>
<?php echo get_the_excerpt(); ?>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
</p>
</article>
<?php $the_query->the_post(); ?>
<article class="post col-md-4">
<?php the_post_thumbnail('medium-thumbnail'); ?>
<h2><?php the_title(); ?></h2>
<p>
<?php echo get_the_excerpt(); ?>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
</p>
</article>
<?php $the_query->the_post(); ?>
<article class="post col-md-4">
<?php the_post_thumbnail('medium-thumbnail'); ?>
<h2><?php the_title(); ?></h2>
<p>
<?php echo get_the_excerpt(); ?>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
</p>
</article>
<?php $the_query->the_post(); ?>
<article class="post col-md-4">
<?php the_post_thumbnail('medium-thumbnail'); ?>
<h2><?php the_title(); ?></h2>
<p>
<?php echo get_the_excerpt(); ?>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
</p>
</article>
<?php
}
else {
$the_query->the_post(); ?>
<article class="post col-md-12">
<?php the_post_thumbnail('large-thumbnail'); ?>
<h2><?php the_title(); ?></h2>
<p>
<?php echo get_the_excerpt(); ?>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
</p>
</article>
<?php
}
?>
<?php
$i++;
}
}
else {
echo '<p>Sorry, no posts matched your criteria.</p>';
}
get_footer();
Add following code in your theme functions.php file to create widget
register_sidebar( array(
'name' => 'After content',
'id' => 'after-content',
'description' => '',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h2>',
'after_title' => '</h2>',
) );
Add following code where you want to display widget area
if ( is_active_sidebar( 'after-content' ) ) :
dynamic_sidebar( 'after-content' );
endif;
Related
I'm using WP-query to display my 3 most recent 'events' which are a custom post type.
Visually it looks like its working fine, but after doing some debugging I noticed that the same image is being loaded 4 times for each post.
<div class="container">
<?php
$args = array(
'post_type' => 'projects',
'posts_per_page' => '2'
);
$the_query = new WP_Query( $args );
$count = $the_query->post_count;
?>
<div class="row small-up-1 medium-up-2 large-up-<?php echo $count ?>" data-equalizer="news" data-equalize-on-stack="false" data-equalize-on="medium">
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<div class="column">
<div class="card">
<div class="card-divider" data-equalizer-watch="news">
<h4> <?php the_title(); ?></h4>
<?php
// FLEXIBLE CONTENT NAME
if( have_rows('main_sections') ):
// FLEXIBLE CONTENT NAME
while ( have_rows('main_sections') ) : the_row(); ?>
<?php // LAYOUT NAME
if( get_row_layout() == 'standard_details' ): ?>
<?php if( get_sub_field('date_of_event') ):
$field_name1 = "date_of_event";
$field1 = get_sub_field_object($field_name1);
?>
<p><?php echo $field1['value']; ?></p>
<?php endif; ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
<?php the_excerpt(__('(more…)')); ?>
</div>
<?php if ( 'video' == get_post_format() ) { ?>
<div class="video-icon">
<i class="fa fa-play fa-3x" aria-hidden="true"></i>
<?php } ?>
<a href="<?php the_permalink() ?>">
<img data-interchange="[<?php echo the_post_thumbnail_url('recent-news'); ?>, small]" alt="<?php the_title(); ?>" />
</a>
</div>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
</div>
</div>
</div>
I'm trying to query some related posts and wrap them in a row div every 3 posts. I've checked all the questions regarding this but still my query renders a mess.
This is what I have so far:
<?php
$related = get_posts( array(
'category__in' => wp_get_post_categories($post->ID),
'numberposts' => 6,
'post__not_in' => array($post->ID) ) );
$counter=0;
if( $related ) foreach( $related as $post ) {
setup_postdata($post); $counter++;
?>
<div class="row">
<article class="third-width">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="third-link">
<?php the_post_thumbnail('post-parrilla'); ?>
</a>
<?php exclude_post_categories("8"); ?>
<div class="clear"></div>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="third-link">
<div class="post-title">
<span><?php the_title(); ?></span>
</div>
</a>
</article>
<?php if ($counter%3==0):?>
</div><div class="row">
<?php endif;?>
<?php } wp_reset_postdata(); ?>
Thank you in advance
Use below code
<?php
$related = get_posts( array(
'category__in' => wp_get_post_categories($post->ID),
'numberposts' => 6,
'post__not_in' => array($post->ID) ) );
if( $related )
{
$counter = 0;
?>
<div class="row">
<?php
foreach( $related as $post ) {
setup_postdata($post);
if ($counter%3==0){
?>
</div><div class="row">
<?php
}
?>
<article class="third-width">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="third-link">
<?php the_post_thumbnail('post-parrilla'); ?>
</a>
<?php exclude_post_categories("8"); ?>
<div class="clear"></div>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="third-link">
<div class="post-title">
<span><?php the_title(); ?></span>
</div>
</a>
</article>
<?php
$counter++;
}
?>
</div>
<?php
}
wp_reset_postdata();
?>
How can I add price to 'search.php' in Woocommerce?
Current code is:
<?php
get_header();
global $wp_query;
?>
<div class="wapper">
<div class="contentarea clearfix">
<div class="content">
<h1 class="search-title"> <?php echo $wp_query->found_posts; ?>
<?php _e( 'Search Results Found For', 'locale' ); ?>: "<?php the_search_query(); ?>" </h1>
<?php if ( have_posts() ) { ?>
<ul>
<?php while ( have_posts() ) { the_post(); ?
<hr width=“20%”>
<h3><b><a href="<?php echo get_permalink(); ?>"></b>
<?php the_title(); ?>
</a></h3>
<?php the_post_thumbnail( 'shop_thumbnail' ) ?>
<br/>
<div class="h-readmore"> <I>Click to see full details</I></div>
</hr width=“20%”>
<?php } ?>
</ul>
<?php paginate_links(); ?>
<?php } ?>
</div>
</div>
</div>
<?php
do_action( 'storefront_sidebar' );
get_footer();
This also has the sidebar at the bottom and not the side - so if anyone can advise how to have the sidebar on the LEFT that too would help.
<?php
get_header();
global $wp_query;
?>
<div class="wapper">
<div class="contentarea clearfix">
<div class="content">
<h1 class="search-title"> <?php echo $wp_query->found_posts; ?>
<?php _e( 'Search Results Found For', 'locale' ); ?>: "<?php the_search_query(); ?>" </h1>
<?php if ( have_posts() ) { ?>
<ul>
<?php while ( have_posts() ) { the_post(); ?>
<hr width=“20%”>
<h3><b><a href="<?php echo get_permalink(); ?>"></b>
<?php the_title(); ?>
</a></h3>
<?php the_post_thumbnail( 'shop_thumbnail' ) ?>
<br/>
<p itemprop="price" class="price"><?php echo $product->get_price_html(); ?></p>
<div class="h-readmore"> <I>Click to see full details</I></div>
</hr width=“20%”>
<?php } ?>
</ul>
<?php paginate_links(); ?>
<?php } ?>
</div>
</div>
</div>
<?php
do_action( 'storefront_sidebar' );
get_footer();
update you search.php with above code the price can we call with this <p itemprop="price" class="price"><?php echo $product->get_price_html(); ?></p>
I am trying to code my homepage to have 2 posts in a row, and then the next row have one post, next row 2 posts, and so on.
I have tried using this article, however every time I try I just get glitches.
https://perishablepress.com/two-column-horizontal-sequence-wordpress-post-order/
If anyone has any coding solutions I would really appreciate it.
This is my current index.php file
<?php
get_header();
if (have_posts()) :
while (have_posts()) :
$i++; if(($i % 2) == 0) : $wp_query->next_post(); else :
the_post(); ?>
<article class="post">
<div id="left-column">
<h2><?php the_title(); ?></h2>
<p>
<?php echo get_the_excerpt(); ?>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
</p>
</div>
</article>
<?php endif; endwhile; else: ?>
<div>Alternate content</div>
<?php endif; ?>
<?php $i = 0; rewind_posts(); ?>
<?php if (have_posts()) :
while (have_posts()) :
$i++; if(($i % 2) !== 0) : $wp_query->next_post(); else :
the_post(); ?>
<article class="post">
<div id="right-column">
<h2><?php the_title(); ?></h2>
<p>
<?php echo get_the_excerpt(); ?>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
</p>
</div>
</article>
<?php endif; endwhile; else: ?>
<div>Alternate content</div>
<?php endif;
get_footer();
?>
Each time you call the_post(); the post index is advanced and the next post data becomes in scope.
Create a new template file in your theme and add a new page using that template;
<?php
/*
* Template Name: page-2-col
*/
get_header();
$i = 0;
$args = array(
'posts_per_page' => 5,
'paged' => 1
);
$the_query = new WP_Query($args);
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
if( $i %2 == 1 ) {
$the_query->the_post(); ?>
<article class="post col-md-12">
<h2><?php the_title(); ?></h2>
<p>
<?php echo get_the_excerpt(); ?>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
</p>
</article>
<?php
}
else {
$the_query->the_post(); ?>
<article class="post col-md-6">
<h2><?php the_title(); ?></h2>
<p>
<?php echo get_the_excerpt(); ?>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
</p>
</article>
<?php $the_query->the_post(); ?>
<article class="post col-md-6">
<h2><?php the_title(); ?></h2>
<p>
<?php echo get_the_excerpt(); ?>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
</p>
</article>
<?php
}
?>
<?php
$i++;
}
}
else {
echo '<p>Sorry, no posts matched your criteria.</p>';
}
get_footer();
To add bootstrap, in your functions.php;
function learningWordPress_resources() {
wp_enqueue_style('style', get_stylesheet_uri());
wp_enqueue_script( 'bootstrap-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', array('jquery'), '3.3.7', true );
wp_enqueue_style( 'bootstrap-style', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' );
}
add_action('wp_enqueue_scripts', 'learningWordPress_resources');
I want to display the posts of post_status="trash" but not post_status="publish". In short, the posts in trash should get displayed on the site. For how long the trash posts would be available in trash? Any help would be appreciated.
index.php
<?php
// show all coupons and setup pagination
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array(
'post_type' => APP_POST_TYPE,
'ignore_sticky_posts' => 1,
'paged' => $paged
));
?>
<?php get_template_part('loop', 'coupon'); ?>
loop-coupon.php
<?php while (have_posts()) : the_post(); ?>
<?php appthemes_before_post(); ?>
<div <?php post_class('item'); ?> id="post-<?php echo $post->ID; ?>">
<div class="item-holder">
<div class="item-frame">
<div class="store-holder">
<div class="store-image">
<img height="89" width="110" src="<?php echo clpr_store_image($post->ID, APP_TAX_STORE, 'term_id', '110', null); ?>" alt="" />
</div>
<div class="store-name">
<?php echo get_the_term_list($post->ID, APP_TAX_STORE, ' ', ', ', ''); ?>
</div>
</div>
<?php clpr_vote_box_badge($post->ID, $the_trans); ?>
<div class="item-panel">
<?php clpr_coupon_code_box(); ?>
<div class="clear"></div>
<?php appthemes_before_post_title(); ?>
<h1><?php if (mb_strlen(get_the_title()) >= 87) echo mb_substr(get_the_title(), 0, 87).'...'; else the_title(); ?></h1>
<?php appthemes_after_post_title(); ?>
<?php appthemes_before_post_content(); ?>
<p class="desc"><?php echo mb_substr(strip_tags($post->post_content), 0, 200).'... ';?><a class="more" href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'View the %s coupon page', 'appthemes' ), the_title_attribute( 'echo=0' ) ); ?>"><?php _e('more ››', 'appthemes') ?></a></p>
<?php appthemes_after_post_content(); ?>
</div> <!-- #item-panel -->
</div> <!-- #item-frame -->
</div>
</div>
<?php appthemes_after_post(); ?>
<?php appthemes_after_endwhile(); ?>
<?php appthemes_loop_else(); ?>
<h3><?php _e('Sorry, no coupons found', 'appthemes'); ?></h3>
`
Try adding this before your loop
query_posts($query_string. '&post_status=trash');