I want to get post into my wordpress homepage, I tried to search lot from google but I am not geting any proper solutions, So if any one have idea please help me.
Thanks in advance.
Here is my tried code so far :
<?php
$args = array(
'cat' => '5',
'post_type' => 'post',
'posts_per_page' => 8,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
);
query_posts($args);
while (have_posts()) : the_post(); ?>
<div id="part-event">
<div id="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<div id="event-dess">
<h2><?php the_title(); ?></h2>
<p>
<?php
$content = get_the_content();
$content = strip_tags($content);
echo substr($content,0,300)." . . . ";
?>
</p>
<div id="read-more">Read More</div>
</div>
</div>
<div id="line-bottom"></div>
<?php
endwhile;
?>
</div>
<div id="page-gina">
<?php
//wp_pagenavi();
wp_reset_query(); // Restore global post data
?>
</div>
Two Ways is possible,
i)Create a custom template.
ii)In your page.php check condition.
Ex:
<?php if(is_front_page()){
echo "This Home";//Here Your code
}
?>
Related
I have some task which try to solve may be not in smartest way, but so far I got only this idea. I have 5 custom post types. In each of this - one post. Want these posts loop and appear on my index.php .Also these posts has the_field() functions from ACF plugin.
The result not what I expected. This is the code in index.php
<?php
$posttypes = array( 'plays','watch','news','shop','contact' );
$args = array(
'post_type' => $posttypes
, 'posts_per_page' => 5 );
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : ?>
<div id="owl-demo" class="owl-carousel owl-theme">
<?php foreach($posttypes as $posttype){?>
<?php $the_query->the_post(); ?>
<div class="item">
<?php get_template_part( 'single', $posttype ); ?>
</div>
<?php };?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</div>
Also I will post one of the post's code, like single_news.php
<?php get_header();
while ( have_posts() ) : the_post() ;?>
<div class="container-fluid "> <!-- play section -->
<div class="row">
<div class="col-xs-12 col-sm-2 col-md-2 col-lg-2">
<h2 class="" style="text-transform:uppercase"><?php the_field('name');?></h2>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-2 col-md-2 col-lg-2">
<h2 class="" style="text-transform:uppercase"><?php the_field('news_name');?></h2>
</div>
</div>
</div> <!-- row -->
</div>
Actually the end of this file I couldnt post but it itself correct with closing dives and endwhile.
In args you have post_per_page set to 5 – this means it will only return the 5 latest posts, regardless of Custom Post Type (CPT).
Try '-1' (return everything) for debugging.
`$args = array(
'post_type' => $posttypes,
'posts_per_page' => -1
);`
Do you want it to return 1 latest post from each CPT?
Maybe try this...
<?php while( $the_query->have_posts() ) : ?>
<?php $the_query->the_post(); ?>
<div class="item">
<?php get_template_part( 'single', get_post_type() ); ?>
</div>
<?php endwhile; ?>
Or run query for each posttype...
<?php foreach( $posttypes as $posttype ) : ?>
<?php
$args = array(
'post_type' => $posttype,
'posts_per_page' => 5 );
$the_query = new WP_Query( $args );
?>
<?php while( $the_query->have_posts() ) : ?>
<?php $the_query->the_post(); ?>
<div class="item">
<?php get_template_part( 'single', $posttype ); ?>
</div>
<?php endwhile; ?>
<?php endforeach; ?>
//I think endforeach exists, otherwise use curly braces
Not sure exactly what you want without seeing it visually.
Hi all I am a new of wordpress I have problame with pagination, I used plugin Wp-pagnavi ,When I click link to page 2 it same as page 1,How to to fix it.
You can see it at
http://westecmedia.com/?page_id=758
And this my code in page-event.php
<?php
/*
* Template Name: Page - Events Page
*/
?>
<?php get_header(); ?>
<div id="content-events">
<div id="head-event"><h3>EVENTS</h3></div>
<div id="main-event">
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="part-event">
<div id="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<div id="event-dess">
<h2><?php the_title(); ?></h2>
<p>
<?php
$content = get_the_content();
$content = strip_tags($content);
echo substr($content, 0, 300);
?>
</p>
<div id="read-more">Read More</div>
</div>
</div>
<div id="line-bottom"></div>
<?php endwhile; endif; ?>
<?php wp_pagenavi(); ?>
<?php wp_reset_query(); ?>
</div>
</div>
<?php get_footer(); ?>
Help me please :(
Include paged, documentation: https://codex.wordpress.org/Pagination
<?php
$args = array(
'cat' => '5',
'post_type' => 'post',
'posts_per_page' => 6,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
);
query_posts($args);
while (have_posts()) : the_post();
/* Do whatever you want to do for every page... */
endwhile;
wp_pagenavi();
wp_reset_query(); // Restore global post data
?>
Also don't use query_posts to fetch data in WordPress, consider using https://codex.wordpress.org/Class_Reference/WP_Query.
Please ask WordPress related question here: http://wordpress.stackexchange.com
I hope this helps.
I am a new of wordpress. I have a problem with pagination when I click to the next post it shows "not found". I installed the plugin wp pagenavi, and I put code in my blog post . It shows the pagination, but I have a problem with the link to the next post. Example when I click to the next post it is show
Something went Wrong!
404
-->
You can see at: http://westecmedia.com/events/
And this is my code in event-page.php:
<div id="content-events">
<div id="head-event"><h3>EVENTS</h3></div>
<div id="main-event">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else: endif; ?>
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="part-event">
<div id="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<div id="event-dess">
<h2><?php the_title(); ?></h2>
<p>
<?php
$content = get_the_content();
$content = strip_tags($content);
echo substr($content, 0, 300);
?>
</p>
<div id="read-more">Read More</div>
</div>
</div>
<div id="line-bottom"></div>
<?php endwhile; else: endif; ?>
<?php wp_pagenavi(); ?>
</div>
</div>
<?php get_footer(); ?>
Help me please ?
Maybe you missed the object here. You can try the code below:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => get_option('posts_per_page'),
'paged' => $paged,
'category_name'=>get_the_title(),
'post_status'=> array('publish', 'future')
);
query_posts($args);
instead:
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
Evening all.
I need a little help. I have the following code which brings in a list of portfolios, and places them on a page in a grid format. At present the code brings in all the portfolio types (of which there are 3, divided into different categories). Is there a way I can edit the code so that I can bring in just one category type?
I have tried the following:
<?php query_posts( array( 'post_type' => 'myportfoliotype', 'category_name' => 'news','paged' => $paged, 'posts_per_page' => 12));
but it displays a blank page.
If I remove:
'category_name' => 'news',
it returns a page will all the categories listed. I have checked the category name and all is correct but I'm clearly missing something.
I would be greatful if anyone could help.
Many thanks
The full code is:
<?php /* Template Name: Modular Gallery */ ?>
<?php get_header(); ?>
<div id="folio-wrap">
<ul id="portfolio-list" class="centerrow">
<?php query_posts( array( 'post_type'=>'myportfoliotype', 'category_name' => 'news','paged' => $paged, 'posts_per_page' => 12)); if ( have_posts() ) : while ( have_posts() ) : the_post();?>
<?php $large_image=w p_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'fullsize', false, '' ); $large_image=$ large_image[0]; $another_image_1=g et_post_meta($post->ID, 'themnific_image_1_url', true); $video_input = get_post_meta($post->ID, 'themnific_video_url', true); ?>
<li id="post-<?php the_ID(); ?>" class="centerfourcol item_full">
<span class="imgwrap">
<?php the_post_thumbnail('folio',array('title' => "")); ?>
<a class="hoverstuff-zoom" rel="prettyPhoto[gallery]" href="<?php if($video_input) echo $video_input; else echo $large_image; ?>"><i class="icon-zoom-in"></i></a>
<a class="hoverstuff-link" href="<?php the_permalink(); ?>"><i class="icon-link"></i></a>
</span>
<div style="clear:both"></div>
<h3><?php echo short_title('...', 6); ?></h3>
<?php echo themnific_excerpt( get_the_excerpt(), '290'); ?>
</li>
<!-- #post-<?php the_ID(); ?> -->
<?php endwhile; endif; ?>
</ul>
<div class="clear"></div>
<div class="pagination">
<?php pagination( '«', '»'); ?>
</div>
<?php wp_reset_query(); ?>
</div>
</div>
<?php get_footer(); ?>
Your code should work if "news" is your category SLUG, not necessary the name.
But on some older versions of wordpress there is a bug with category_name in query_posts, try it with cat_name
Hello Im new to Wordpress , But I styled some elements, and had the recent posts in them . My question, can I have them for 5 posts repeated after each other ? thanks :)
<div id="main_content">
<h2>Latest Products</h2>
<div class="latest_products">
<div class="group">
<?php query_posts("post_per_page=1"); the_post(); ?>
<h3 class="stick_note"><?php the_title(); ?></h3>
<div class="pro_content">
<div class="product_thumbnail"> <?php the_post_thumbnail('thumbnail'); ?> </div>
<p><?php the_excerpt(); ?></p>
</div>
</div>
</div> <!-- END LATEST PRODUCTS -->
</div> <!-- END Main Content -->
You forgot to implement The Loop (click for detailed info).
A full Wordpress loop is as follows:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
...render your post here, it will keep repeating...
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
Since you don't have an actual loop implemented it can only render 1 post.
You can use:
get_archives('postbypost', 5);
OR
query_posts("showposts=5");
This help you? Be more specific in your question.
You can find the answer in documentation of wordpress:
http://codex.wordpress.org/Template_Tags/get_posts
http://codex.wordpress.org/Template_Tags/query_posts
http://codex.wordpress.org/Template_Tags/wp_get_archives
EDIT:
$args = array('numberposts' => 5, 'order'=> 'ASC');
$postslist = get_posts( $args );
EDIT2:
You can do:
$args = array('numberposts' => 5, 'order'=> 'ASC');
$postslist = get_posts( $args );
foreach( $postslist as $post ) : setup_postdata($post); ?>
<li>
<?php the_title(); ?>
</li>
<?php endforeach; ?>