Wordpress static front-page made up of child pages - wordpress

Is there a way to make a static front-page made up of child pages, surrounded by sections, like this:
Front Page
<div class="main">
Parent Start
<section id="<section title>">
Child Content
</section>
<section id="<section title>">
Child Content
</section>
<section id="<section title>">
Child Content
</section>
Parent End
</div>
I was thinking the section id could be added from the menu settings?
Appreciate if anybody could point me in the right direction!
SOLUTION
$args = array(
'posts_per_page' => -1,
'meta_key' => 'priority',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'post_type' => 'page',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'add_to_front_page',
'value' => 'Yes',
'compare' => '=',
),
),
);
$pages = get_posts( $args );
foreach ( $pages as $page ) {
$title = $page->post_title;
$content = wpautop( $page->post_content );
}
priority and add_to_front_page are custom fields!

Use WP_Query.
<div class="main">
<?php
$args = array(
'posts_per_page' => -1,
'meta_key' => 'priority',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'post_type' => 'page',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'add_to_front_page',
'value' => 'Yes',
'compare' => '=',
),
),
);
$query = new WP_Query( $args );
while($query->have_posts() ):
$query->the_post() : ?>
<section id="<section title>">
<?php the_title();
the_content(); ?>
</section>
<?php
endwhile;
wp_reset_postdata();
?>
</div>

Related

WP query returning limited items only from two childs

I am using code as follows:
$args = array(
'post_type'=> 'portfolio',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'portfolio-category',
'field' => 'slug',
'terms' => 'studio-blu',
'posts_per_page' => -1,
'include_children' => true,
),
),
);
$the_query = new WP_Query( $args );
if($the_query->have_posts() ) :
while ( $the_query->have_posts() ) {
$the_query->the_post();
$featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full');
?>
<div class="grid-item col-sm-6 col-md-4 col-lg-3 <?php the_category(' '); ?>">
<a class="magnific-popup" href="<?php echo $featured_img_url; ?>">
<img src="<?php echo $featured_img_url; ?>" />
</a>
</div>
<?php
}
wp_reset_postdata();
endif;
Here, studio-blu is the parent category of the custom post type. It has 0 posts directly, however, it has the following children with the corresponding number of posts.
ads = 9
branding = 1
events = 4
logos = 7
misc = 4
However, on the above wp_query, it is returning only 10 items, i.e, 9 from ads and 1 from branding. Why is that?
Oh I found the problem, the issue was I was missing 'posts_per_page' => -1, under $args. Now, my $args looks like:
$args = array(
'post_type'=> 'portfolio',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'portfolio-category',
'field' => 'slug',
'terms' => 'studio-blu',
'posts_per_page' => -1,
'include_children' => true,
),
),
'posts_per_page' => -1,
);

Wordpress show future events based on custom field

I know similar questions are asked a million times and i have tried different kinds of solutions but without any success
I have Cpt contests
<?php
$paged = ( get_query_var('paged') ) ?get_query_var('paged') : 1;
$contest = new WP_Query(
array(
'post_type' => 'contests',
'posts_per_page' => '15',
'meta_key'=> '_closingdate',
'orderby'=> 'meta_value',
'order' => 'ASC',
'paged' => $paged
));
?>
<?php if ($contest->have_posts()) : while ($contest->have_posts()) : $contest->the_post();?>
<div class="row">
<div class="cell_left"><p><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></p></div>
<div class="cell"><p class="posted"><?php echo date('d-m-Y', strtotime(get_post_meta($post->ID, "_closingdate",true)));?></p></div>
</div>
<?php endwhile;?>
</div>
<div class="navigation">
<?php wp_pagenavi( array( 'query' => $contest ) ); ?>
<?php wp_reset_query();?>
</div>
<?php endif; ?>
This is working without any problem
now i try to only show "contests" with closing date today and future.
i have found this on stack overflow but i cant get it working .
<?php
$paged = ( get_query_var('paged') ) ?get_query_var('paged') : 1;
$today = date('Ymd');
$contest = new WP_Query(array(
'post_type' => 'contests',
'posts_per_page' => '15',
'meta_key' => '_closingdate',
'orderby' => 'meta_value',
'paged' => $paged,
'order' => 'ASC',
'meta_query' => array(
array(
'key' => '_closingdate',
'meta-value' => $value,
'value' => $today,
'compare' => '>=',
'type' => 'CHAR',
)
)
));
?>
Is there someone who can solve this quest for me ?
Cheers
try using php time function:
in your case
<?php
$paged = ( get_query_var('paged') ) ?get_query_var('paged') : 1;
$contest = new WP_Query(array(
'post_type' => 'contests',
'posts_per_page' => '15',
'meta_key' => '_closingdate',
'orderby' => 'meta_value',
'paged' => $paged,
'order' => 'ASC',
'meta_query' => array(
array(
'key' => '_closingdate',
'value' => time(),
'compare' => '>=',
)
)
));
?>

Wordpress 'pre_get_posts' not working on ajax?

Im using a plugin to select featured post which uses 'pre_get_posts' to filter posts.It works fine in normal query_post() but it is not working inside ajax. Here is my code
<?php
add_action('wp_ajax_portscroll', 'portscroll');
add_action('wp_ajax_nopriv_portscroll', 'portscroll');
function portscroll(){
?>
<?php
$offset_click= $_POST['data'];
$offset= 4+$offset_click*2;
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => 2,
'featured' => 'yes',
'orderby' => 'menu_order',
'order' => 'ASC',
'offset'=> $offset
);
$post_osrtfolios = query_posts($args);
if ($post_osrtfolios) :
foreach ($post_osrtfolios as $post_osrtfolio) :
///contents goes here
endforeach;
endif;
wp_reset_query();
} ?>
Everything works fine, query works fine but the parameter 'featured' => 'yes' is not working. This parameter is from plugin.
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => 2,
'meta_query' => array(
array(
'key' => '_is_featured',
'value' => 'yes'
)
),
'orderby' => 'menu_order',
'order' => 'ASC',
'offset'=> $offset
);
Use this

How do I show most viewed posts on a per-month basis?

For last month this query worked, now this 3 days (new month started), no posts at all:
<?php $current_year = date('Y'); ?>
<?php $current_month = date('m'); ?>
<?php endif;
arras_featured_loop( arras_get_option('featured1_display'),
apply_filters('arras_featured1_query', array(
'list' => $featured1_cat,
'taxonomy' => arras_get_option('featured1_tax'),
'query' => array( 'posts_per_page' => 15,
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'year' => $current_year,
'monthnum' => $current_month,
'category_name' => Music,
'posts_per_page' => $featured1_count,
'exclude' => $post_blacklist,
'post_type' => arras_get_option('featured1_posttype')
)
) ) );
?>
Any kind of help will be appreciated.
UPDATE:
This was not pissible.
But now I found way to do this with plugin Wordpres Popular Posts.
Its working alone in template with this code:
<?php
if (function_exists( 'wpp_get_mostpopular' )) {
wpp_get_mostpopular('range=weekly&cat=276&order_by=views&limit=8');
}
?>
Now, what I need to do is to use this code up into this template down:
<?php endif;
arras_featured_loop( arras_get_option('featured1_display'), apply_filters('arras_featured1_query', array(
'list' => $featured1_cat,
'taxonomy' => arras_get_option('featured1_tax'),
'query' => array(
'posts_per_page' => $featured1_count,
'exclude' => $post_blacklist,
'post_type' => arras_get_option('featured1_posttype')
)
) ) );
?>
I think I need to put it inside here:
'query' => array(
Problem is I don't know to turn query from existing to one with arrows 'range=weekly' to 'range' => weekly didnt worked.

WordPress Loop - skip posts without a thumbnail

I want skip every post that has no thumbnail. The code does not work properly yet.
Actually the script doesn't show posts without a thumbnail - that's good, but in the loop the post with no thumbnail is still counted as a post.
So when i have for example 10 posts in my wordpress database. I want show 5 of them. But only the posts who has a thumbnail.
<ul>
<?php
$args = array( 'numberposts' => 5,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish'
);
$my_posts = get_posts( $args );
global $post;
foreach( $my_posts as $post ) : setup_postdata($post);
if ( !has_post_thumbnail() ) {
continue;
} else {
?>
<li>
<div class="clearfix" >
<div class="thumb"><?php the_post_thumbnail('post-image-big'); ?></div>
<?php the_title(); ?>
<p class="category"><?php the_category(', '); ?></p>
</div>
</li>
<?php } ?>
<?php endforeach; ?>
</ul>
Try
$args = array( 'numberposts' => 5,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish' ,
'meta_query' => array(
array(
'key' => '_thumbnail_id',
'compare' => '!=',
'value' => ''
)
)
);
or this if checking for an empty string didn't work for you
$args = array( 'numberposts' => 5,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish' ,
'meta_query' => array(
array(
'key' => '_thumbnail_id',
'compare' => '!=',
'value' => null
)
)
);

Resources