/    Sign up×
Community /Pin to ProfileBookmark

how to show a single category posts on a coustom page

i have created a new template with name coustom.php and copy my home template code in it . because its basically home template code which is showing all latest posts but i only want to show posts by category name or slug

here is my code

[CODE]<?php /* Template Name: Custompage */ get_header(); ?>

<?php
/* Blog Options */
$post_template = ddp_blog_post_template();
?>

<div id=”primary” class=”content-area”>
<main id=”main” class=”site-main” role=”main”>

<?php if ( have_posts() ) : ?>

<?php /* Start the Loop */ ?>
<div class=”posts-loop”>
<?php while ( have_posts() ) : the_post(); ?>

<?php
/* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( ‘template-parts/’ . $post_template );
?>

<?php endwhile; ?>
</div><!– / .posts-loop –>

<?php the_posts_pagination( array(
‘mid_size’ => 2,
‘prev_text’ => esc_html( ‘&#8592;’ ),
‘next_text’ => esc_html( ‘&#8594;’ ),
) ); ?>

<?php else : ?>

<?php get_template_part( ‘template-parts/content’, ‘none’ ); ?>

<?php endif; ?>

</main><!– #main –>
</div><!– #primary –>

<?php get_sidebar(); ?>
<?php get_footer(); ?>
[/CODE]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@edcedcauthorOct 10.2017 — i did this

`<?php /* Template Name: Custompage */ get_header(); ?>

<?php

/* Blog Options */

$post_template = ddp_blog_post_template();

?>

<div id="primary" class="content-area">

<main id="main" class="site-main" role="main">

<?php if ( have_posts() ) : ?>

<?php /* Start the Loop */ ?>

<div class="posts-loop">

<?php

global $paged; global $wp_query;

$temp = $wp_query; $wp_query= null; $wp_query = new WP_Query();

$wp_query->query('showposts=10&cat=13'.'&paged='.$paged);

while ($wp_query->have_posts()) : $wp_query->the_post();

?>

<?php

/* Include the Post-Format-specific template for the content.

*
If you want to override this in a child theme, then include a file

* called content-___.php (where ___ is the Post Format name) and that will be used instead.

*
/

get_template_part( 'template-parts/' . $post_template );

?>

<?php endwhile;

?>

</div><!-- / .posts-loop -->

<?php the_posts_pagination( array(

'mid_size' => 2,

'prev_text' => esc_html( '&#8592;' ),

'next_text' => esc_html( '&#8594;' ),

) ); ?>

<?php $wp_query = null; $wp_query = $temp;?>

<?php else : ?>

<?php get_template_part( 'template-parts/content', 'none' ); ?>

<?php endif; ?>

</main><!-- #main -->

</div><!-- #primary -->

<?php get_sidebar(); ?>

<?php get_footer(); ?>

its showing posts but thumnail is not showing correctly . on home page thumbnail is showing on left side but after editing query post thumnail is showing above the posts
×

Success!

Help @edcedc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...