I am create post with advance custom field (movie-page.php) I want to create single page(single-movie.php) each post of movie-page.php when I am click on each post it link to full details but I can not do it. Help me please!!!. thanks you.
And here is my code movie-page.php
<?php
/*
* Template Name: Page - Movie Page
*/
?>
<?php get_header(); ?>
<?php
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'movie'
));
if( $posts ): ?>
<ul>
<?php foreach( $posts as $post ):
setup_postdata( $post )
?>
<div class="jol">
<?php the_title($post->ID); ?>
<?php get_post_field('descriptionii',$post->ID ); ?>
<?php the_content() ?>
<?php the_field("descriptionii") ?>
</div>
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php get_footer(); ?>
<?php
/*
* Template Name: Page - Movie Page
*/
?>
<?php get_header(); ?>
<?php $args = array(
'posts_per_page' => -1,
'post_type' => 'movie',
'post_status' => 'publish',
);
$posts_array = get_posts($args);
foreach ($posts_array as $key => $value) {
echo "".$value->post_title."</br>";
echo $value->post_content;
}
?>
<?php get_footer();
Related
I use WP-PostRatings WP-PostViews plugins and was able to display pages using functions
<?php if (function_exists('get_highest_rated')): ?>
<ul><?php get_lowest_rated(); ?></ul>
<?php endif; ?>
<?php if (function_exists('get_most_viewed')): ?>
<ul><?php get_most_viewed(); ?></ul>
<?php endif; ?>
but they are displayed as plain text and I cannot edit them, add a thumbnail of the post and do other things is it possible to not display them as if using get_posts() like this
<?php
global $post;
$args = array(
'post_type' => 'post',
'orderby' => 'comment_count',
'order'=> 'ASC'
);
$myposts = get_posts( $args );
foreach( $myposts as $post ){ setup_postdata($post);?>
<li><?php the_title(); ?></li>
<?php } wp_reset_postdata(); ?>
but only for rating and views
I want to display the specific post title/content in the front static page.Remember not all posts just specific. So can anybody guide me how to do that..
Yes you can get specific posts in front page by passing post ids with array in include parameter something like this,
<ul>
<?php
global $post;
$args = array(
'offset'=> 1,
'include' => array(1,2,3) // PASS POST ID IN ARRAY
'post_type' => 'post', );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<li>
<?php the_title(); ?>
<?php the_content(); ?>
</li>
<?php endforeach;
wp_reset_postdata();?>
</ul>
Hope this works.
<?php
$titles=array();
$contents=array();
$links=array();
// the query
$the_query = new WP_Query( array(
'posts_per_page' => 3,
));
?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php $titles[]=get_the_title(); ?>
<?php $contents[]=get_the_content(); ?>
<?php $links[]=get_the_permalink();?>
<?php endwhile; ?>
and now printed the value in my page wherever i wanted
<?php echo $titles[0]; ?>
<?php echo $titles[1]; ?>
<?php echo $titles[2]; ?>
And same for other declared arrays. :)
I have only the following code in a Wordpress template file, and though there are only two posts in the database, it goes to infinite loop.
$args = array(
'posts_per_page' => '‐1',
'post_type' => 'products',
);
$myProducts = new WP_Query( $args );
// The Loop
while ( $myProducts->have_posts() ) : $myProducts‐>the_post();
echo 'loop body';
endwhile;
// Reset Post Data
wp_reset_postdata();
If I print the $myProducts variable, I can see the two posts there. Why the infinite loop then?
<?php
$params = array(
'posts_per_page' => 5,
'post_type' => 'product'
);
$wc_query = new WP_Query($params);
?>
<?php if ($wc_query->have_posts()) : ?>
<?php while ($wc_query->have_posts()) : $wc_query->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p>
<?php _e( 'No Products' ); ?>
</p>
<?php endif; ?>
This works fine for me.
Can't seem to find the right answer for what I thought would be trivial.
I have some categories arranged like this...
Parent Category 1
- Child Category 1
- Child Category 2
- Child Category 3
...and I have some posts that are in Child Category 2. I want my page to display all posts from the category I am currently in.
This is what I am doing right now:
<?php
query_posts('cat=2&showposts=10');
if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="timeline">
<h3><?php the_title(); ?></h3>
<?php the_content();?>
<?php endwhile; else: ?>
<?php _e('No Posts Sorry.'); ?>
<?php endif; ?>
</div>
As you can see I am having to manually specify the category (cat=2), but instead I want it to automatically detect the category I am already in and display the posts (that way if I'm in a different category it will display those posts).
Any suggestions?
Thanks in advance. (SO Community = Awesome Sauce).
try below code:
<?php
$current_cat_id = get_query_var('cat');
$showposts = 10;
$args = array('cat' => $current_cat_id, 'orderby' => 'post_date', 'order' => 'DESC', 'posts_per_page' => $showposts,'post_status' => 'publish');
query_posts($args);
if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="timeline">
<h3><?php the_title(); ?></h3>
<?php the_content();?>
<?php endwhile; else: ?>
<?php _e('No Posts Sorry.'); ?>
<?php endif; ?>
</div>
If you are using category.php, you can omit the query_posts and it will auto fill in the posts for you.
<?php
// Start the loop.
$categories = get_categories('child_of=1');//Parents category id
foreach ($categories as $cat) {
$option = '<a href="/category/archives/'.$cat->category_nicename.'">';
$option .= $cat->cat_name;//parents sub category name
$option .= '</a>';
echo $option;
query_posts('cat=$cat->cat_ID&showposts=10');
if (have_posts()) : while (have_posts()) : the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_content();?>
<?php endwhile; else: ?>
<?php _e('No Posts Sorry.'); ?>
<?php endif; }?>
<ul>
<?php
global $post;
$args = array( 'posts_per_page' => 5, 'offset'=> 0, 'category' => 1 );
// 1 is a cat id.
//
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<li>
<?php the_title(); ?>
</li>
<?php endforeach; ?>
</ul>
try
$args = array( 'posts_per_page' => 5, 'offset'=> 0, 'cat' => 1 );
Try this, this is better solution for this and you can also use it to show Related Post by a category id...
Just call the function that mentioned below by using this line. Put this in your template or page.php/single.php file.
Call by put this line: related_post_title('enter cat id here..');
Here is the Function and put this in function.php file.
Related posts function:
function related_post_title($cat_id){
$cat = $cat_id;
// Check if it is page only
if ( is_page() || is_single()) {
$args=array(
'cat' => $cat,
'order' => DESC,
'orderby' => rand,
'post__not_in' => array($post->ID),
'posts_per_page' => 9999,
'caller_get_posts' => 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo ' <ul> ';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><?php the_title(); ?></li>
<?php
endwhile;
echo '</ul>';
}
wp_reset_query();
}
}
If any query please let me know, i will help you...
I'm developing a wordpress 3.3.1 theme and I'm having troubles with the single.php file.
It displays - no matter what post (&p=111 e.g.) you select - only the content of the newest post.
This is my loop:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<h1 class="page-title"><?php the_title() ?></h1>
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<img src="<?php echo $image[0]; ?>" class="cover" />
<?php endif; ?>
<p class="page-text">
<?php the_content(); ?>
</p>
<?php endwhile; ?>
<?php endif; ?>
What could be wrong? I hope you've understood my problem. Thank you!
edit:
I recently updated the header file. When I delete this loop, it works fine:
<ul class="nav-dropdown">
<?php
$cat_args = array(
'orderby' => 'name',
'order' => 'ASC',
'child_of' => 5,
'exclude' => '1,2,3,4,5,6,8,9,10,11,12,13,14'
);
$categories = get_categories($cat_args);
foreach($categories as $category) {
$post_args = array(
'category' => $category->term_id
);
$posts = get_posts($post_args);
foreach($posts as $post) {
?>
<li class="nav-dropdown"><?php the_title(); ?></li>
<?php
}
}
?>
</ul>
I'd change your variable names in the header as ones such as $post are reserved by Wordpress for handling single post pages.
I am not sure but please change the $post variable to any other variable and than try
may be your problem be solved.
Because $post is global variable of post.