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();?>
Related
I have an anime website in WordPress where I add episodes as posts.
I'm using a theme that i created by myself, what i want is to display the list of episodes of the anime that the user is watching by looping through the posts with the same title to display them all using PHP. I tried a lot of solutions but none of them worked.
In brief, I want to display posts with the same title to make a list of episodes
This is one of the solutions that i tried and didn't work.
<div class="episodes">
<?php
$EpisodesList = new WP_Query('post_title='the_title()'');
if ($EpisodesList->have_posts()) {
while(have_posts()) {
the_post();
echo the_title( );
}
}
?>
</div>
You must get the post type 'EpisodesList' in your WP Query. WP_Query is a class used in WordPress theming that accepts a variety of parameters to request and fetch posts around those parameters. The example below allows you to set a list of parameters, fetch the posts matching those parameters, and display the title and excerpt of the post on the website.
Code goes in your custom template file where you want to render the posts.
/**
* Setup query to show the ‘EpisodesList’ post type with ‘8’ posts.
* Output the title with an excerpt.
*/
$args = array(
'post_type' => 'EpisodesList',
'post_status' => 'publish',
'posts_per_page' => 8,
'orderby’ => 'title',
'order’ => 'ASC',
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
print the_title();
the_excerpt();
endwhile;
wp_reset_postdata();
Actually i've a static website and i'm trying to convert it into wordpress, i'm new to wordpress. I have successfully created following page.
header.php
footer.php
sidebar.php
functions.php
index.php
Then i have created a main-template.php page for my other pages like about, contact, gallery, etc, They will all be using same template. The website is almost completed but only two pages are left.
1. Jobs
2. News & Events
So in these pages, There will be new jobs coming, and same for news & events. So i think these two pages will be like a blog post.
Jobs page will display all the jobs with title and 100 words description and read more button, Then it will open in new page for that particular job.
I have will different job categories like electrician, plumber,mason,english language,call center etc
I want to show all categories jobs on Jobs page.
So I have created a Page in wp-admin>pages>add new called Jobs and newsEvents and selected template main-template that i have used for all pages. But this page will be blog type to show all jobs.
As you know I will be having two blog type pages one for JObs and one for News Events So I have only created two categories Jobs & NewsEvents
Now If i add a new job, I will go to wp-admin>posts>add New then add title, description, select category Job if it is job, similarly for newsevents.
So the question is How do i show jobs on jobs page and newsevents on newsevents page?
How to create single.php?
How many single.php do i have to create?
I have created `single.php`
<?php
/**
* The template for displaying Jobs
*/
/*get_header();*/
get_header();
?>
<?php
while ( have_posts() ) : the_post();
get_template_part( 'content', 'Jobs' );
endwhile;
?>
<?php
get_footer();
?>
and I have created Empty jobs page in wp-admin>pages>Job its link is localhost/MyProject/jobs I want to show jobs on this page, all jobs that i will post..
I have created content-jobs.php page too, Now what should i do next? how will i show jobs?
my content-jobs.php
<?php the_content() ?>
I have already read wordpress documentation but unable to understand properly, this is my first time doing it, Help me?
1) you need create separate template for these pages.
2) Create the pages with receptive names
3) Use these templates on these pages in admin
4) Create custom post type News& Events
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'News',
array(
'labels' => array(
'name' => __( 'News' ),
'singular_name' => __( 'News' )
),
'public' => true,
'has_archive' => true,
)
);
}
add this code in function.php
after that post some data in this post type
and to show this on front end in your template file use.
$args = array( 'post_type' => 'News', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile;
use this it will help you
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.
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;
i am beginner to WordPress, i have created the index.php it automatically shows my posts.. but i wanna posts to show also in another php file like blog.php.. how can i retrieve the same posts which is shown in index.php.........
The scenario is, i am developing theme for http://themeforest.net show that i wanna make some features in my blog page like without sidebar, left sidebar, right sidebar... but my home(index.php) contains posts.. whenever i starts new page with same coding(like blog.php), it doesn't show the index.php 's posts..
This sample piece of code retrieves 3 posts from categpry id 4
<?php
$args = array( 'numberposts' => 3, 'order'=> 'DESC', 'orderby' => 'post_date', 'category' => 4 );
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post);
$a= get_the_date();
?>
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?></p>
<?php endforeach; ?>
Refer the WordPress documentation http://codex.wordpress.org/The_Loop
it contain different example how to display post include or exclude post from specific categories etc..