In wordpress i need to display post on home page from a specific category.
Need Five Post With Title
Category Is News
Display On Main home page
i use plugin business news but when i activate this plugin nex gen gallery plugin will be conflict now i dont know how to resolve this please suggest.
Following is the code to display post of a specific category. To display on home page, you will have to make following changes in your index.php file.
$query = new WP_Query( array('category_name'=>'news', 'posts_per_page'=> '5') );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
get_template_part( 'content', get_post_format() );
endwhile;
endif;
Related
I want to display only one author's post say "abc_author" .
i have use the validation using if clause but THE PROBLEM is that i get pagination below the post where page 1 is blank (as an other author post is skipped) , page 2 (as an other author post is skipped) is blank and soon i get my desired post on page 6 . commenting the verbosa_pagination() hide the pagination navigation but the starting pages are blank and
I am a new to WordPress , i have also tries different plugin but they facilitate me to filter it on pages not post (though i can change the home page to a particular page but i want it on default blog post for few reasons )
<?php if ( have_posts() ) : ?>
<div id="content-masonry">
<?php /* Start the Loop */
while ( have_posts() ) : the_post();
if(get_the_author()=='abc_author')
{
get_template_part( 'content/content', get_post_format() );
}
endwhile; ?>
</div> <!-- content-masonry -->
<?php verbosa_pagination();
else :
get_template_part( 'content/content', 'notfound' );
endif;
Can you please try this code before the while loop?
<?php query_posts( array( 'author' => 'your author ID' ) ); ?>
Ref: https://developer.wordpress.org/reference/functions/query_posts/#usage
I'm running Wordpress 4.1. I have two blog pages on my site, and though I don't really know php, I've done some tinkering and figured out how to modify the page templates so each page only displays posts for a specific category. That bit of code looks like this:
<?php query_posts('cat=2'); ?>
That works fine. Page A displays posts from category 1, and Page B displays posts from category 2.
What I'd like to do is disable post title links for one specific category. In other words, Page A would display posts from category 1 (with standard clickable title links), and while Page B would display posts from category 2 (with non-clickable title links).
I'm an HTML/CSS guy, so really out of my depth here, but if there's a way to modify the loop to achieve this, I'd love to learn how. Thanks in advance for any help.
Yes, you can do this using the category.php theme file. When this page is hit, it loads a specific category requested and the posts that fall into that category.
Your theme and loop may look something like this:
<?php single_cat_title(); ?>
<?php echo category_description(); ?>
if (have_posts()) : while (have_posts()) : the_post();
/// display posts from specific category
endwhile; endif;
Or if you don't want to use that page which is designed for that, you can create your own loop:
query_posts( array ( 'category_name' => 'my-category-slug', 'posts_per_page' => 50 ) );
All together like this:
<?php
/* retrieve unlimited # of posts with an category slug of music */
query_posts( array ( 'category_name' => 'music', 'posts_per_page' => -1 ) );
// set $more to 0 in order to only get the first part of the post
global $more;
$more = 0;
// the Loop
while (have_posts()) : the_post();
the_content( 'Read the full post ยป' );
endwhile;
?>
By default WordPress homepage shows latest posts. How can I display the latest posts on a page that is not the homepage ?
My first goal "GOAL A" is for the homepage to display a specific category called "popular posts" (instead of latest posts).
"GOAL B" is to have a link on the menu to ALL posts ordered by date, aka "the latest posts".
I have accomplished GOAL A with code below. How can I accomplish "GOAL B" ? I can make a category called "New" and make that a link on the menu, but how can I make it display all posts ordered by date ? Or is there a better method ?
.
"GOAL A" CODE: display specific category on homepage
function popular_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'category_name', 'popular' );
}
}
add_action( 'pre_get_posts', 'popular_category' );
I think the best here will be is to create a static front page with a blog page. This seems to be fit for what you are trying to do
Here is how:
STEP 1
You should delete the code in your question. This will not be necessary here
STEP 2
Make a copy of your page.php (or index.php) and rename it front-page.php. Open it up, and replace the loop with a custom query which will only display posts from the desired category. Unfortunately, pre_get_posts does not work on a static front page, so here you will have to make use of a custom query.
<?php
// set the "paged" parameter (use 'page' if the query is on a static front page)
$paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1;
// the query
$the_query = new WP_Query( 'category_name=popular&posts_per_page=10&paged=' . $paged );
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php
// the loop
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<?php the_title(); ?>
<?php endwhile; ?>
<?php
// next_posts_link() usage with max_num_pages
next_posts_link( 'Older Entries', $the_query->max_num_pages );
previous_posts_link( 'Newer Entries' );
?>
<?php
// clean up after the query and pagination
wp_reset_postdata();
?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
Just remember, for paging on a static front page, you have to use page, not paged as you would for all other custom queries.
STEP 3
Make a copy of your index.php and rename it home.php. This will be your blog page template
STEP 4
You can now set your static front page and blog page in the back. You should have a read here about setting up a static front page and a blog page
I am creating a new theme for my blog where I checked some posts as a Sticky post from wp-admin and on front-end I have given some CSS to highlight those sticky post.
Now I want to give link on that highlight area which redirect to particular page having all sticky posts.
I also want to do the same for other post formats as well, like IMAGE, LINK, etc.
Can someone help me on this?
You can do it with custom wordpress template and query.
Create custom page template for each post format lists page Like for sticky posts list, create page template page-sticky.php
Inside this page add custom query with loop of posts something like below :
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_format' => 'sticky', 'posts_per_page' => 10, 'paged' => $paged );
query_posts($args);
if ( have_posts() ) : while (have_posts()) : the_post();
get_template_part( 'content', get_post_format() );
endwhile;
endif;
wp_reset_query();
You can change sticky word with any post format you want. also make sure you put everything in php quote.
Currently I am trying to develop wordpress one page portfolio theme. Now it shows blog posts and page posts. I have created a custom page template for displaying one page portfolio items. It will display post from those pages which user will create from theme menu.
Now I need to create that, but I have no idea how to do that. Please note that it will display only those page posts which user created from theme menu , and it will show those page navigation link(although I dont need any help about that , but I need help to show pages post) , and another thing is that , it will not display blog posts.
Run a WP_Query on your index page, and inside the loop add the page contents
<?php $args = array(
'post_type' => 'page', // Calling pages only
'order' => 'ASC',
'posts_per_page'=> '-1', // display all pages published
);
$loop = new WP_Query( $args ); if( $loop->have_posts() ): while( $loop->have_posts() ): $loop->the_post();?>
<?php the_title(); //Page Contents etc.?>
<?php endwhile; endif; wp_reset_postdata();?>