How to show posts in custom page template in wordpress? - wordpress

I am trying to make my custom page template,in which i display post with custom styles, i don't know how to show posts in this custom page template,here i am attaching my simple code for custom page template.
<?php
/*
Template Name: Custom Template
*/
get_header();
//custom code for post is here
get_footer();
?>

You can use WP_Query() to add a custom loop to your page template. You can find a few examples in the WordPress Codex

You can always use page template similar to this and make full use of the codes over here writing with our own classes and style you are referring to :
<?php
/*
Template Name: Custom Template
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<header class="entry-header">
<?php the_post_thumbnail(); ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<div class="entry-content">
<?php the_content(); ?>
</div><!-- .entry-content -->
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Related

Disable WordPress auto paragraph

I've been trying to remove the wp auto p. I've tried both remove_filter('the_content', 'wpautop'); inside my theme's functions.php file and any plugin available to do this, but none of them are actually working.
Also i am not using any plugin that could be placing these p tags, so I am very confused.
Any help would be appreciated.
<?php
/*
Template Name: Text template.
*/
get_header(); ?>
<?php
if(have_posts()):
while(have_posts()): the_post(); ?>
<div class="color-1">
<div class="content">
<p><?php the_content(); ?></p>
</div>
</div>
<?php endwhile;
endif;
?>
<?php get_footer(); ?>
The paragraph around <?php the_content(); ?> was the reason why.

Footer in my sidebar

I have read the other answers on SOF, and cannot find out where my error is at. On my homepage and other pages selected to no have a sidebar have the footer credits moving up into the side of my site! :(
Added 4/11/17:
Here is the footer.php:
<div class="site-info">
Proudly created by Ryan Anderson
<br>
Privacy Policy
</div><!-- .site-info -->
Here is the index.php that I created recently that might have issues??
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<?php /* Start the 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/content', get_post_format() );
?>
<?php endwhile; ?>
<?php the_posts_navigation(); ?>
<?php else : ?>
<?php get_template_part( 'template-parts/content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php if (!is_front_page()) {
get_sidebar();
} ?>
<?php get_footer(); ?>
Found what I needed. Stylesheet needed this added to stop the float:
.site-info {
clear: both
}

How to print text from db in special template for specific page in wordpress

I have five pages and I have created a different layout for last two pages, that layout has a div with class infoDiv and that div has a text which I just put manually in the source code, so I can't change it through wordpress. How can I have it available in my dashboard so client no need to change in code?
<?php
/*
Template Name: Special Layout
*/
get_header();
if (have_posts()) {
while (have_posts()) {
the_post();
?>
<article class="borderClass">
<h2> <?php the_title(); ?> </h2>
<div class="infoDiv">
<h4>This is info div</h4>
<p>this is the text I want to edit or add
using dashboard.</p>
</div>
<?php the_content(); ?>
</article>
<?php
}
} else {
echo "<p>No content found</p>";
}
get_footer();
Just move <?php the_content(); ?> like below
<article class="borderClass">
<?php the_title( '<h2>', '</h2>' ); ?>
<div class="infoDiv">
<?php the_content(); ?> <!-- Entered content -->
</div>
</article>

Wordpress theme: Custom page template displays all the website's pages

I'm developping a wordpress theme. I'm making a custom theme for a specific page.
I created a "Home" page with the identifier "home". I created a page-home.php file, with this loop:
<?php get_header();
get_topmenu(); ?>
<div class="catch"></div>
<div id="primary" class="content-area page-home">
<div id="content" class="site-content" role="main">
<?php /* The loop */ ?>
<?php if(have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php the_content(); ?>
</div><!-- .entry-content -->
</article><!-- #post -->
<?php comments_template(); ?>
<?php endwhile; ?>
<?php endif; ?>
</div><!-- #content -->
</div><!-- #primary -->
PAGE HOME.PHP
<?php get_sidebar(); ?>
<?php get_footer(); ?>
But doing this, when I call ?q=home, I've got ALL my pages displayed in the loop, and not just the "home" page... What is the cleanest way to get just the "Home" page ?

Wordpress Placing of the_content() function in custom page

I have made a custom page in my wordpress theme. The page is working fine. But I am facing trouble using the_content(); function. I am using a few custom fields to display some content on the page and I want the content of the page, that is entered in the Editor, to be displayed on a specific place on the page. But Whatever I enter in the Editor, gets placed at the top of the page above all other content.
EDIT:
Here is the full code:
<?php get_header(); ?>
<div id="main-content">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
<div class="mobile-top">
<a href="<?php the_permalink(); ?>">
<p><?php the_title(); ?> price</p>
</a>
</div>
<?php comments_template(); ?>
</div>
</div> <!--main-content Ends-->

Resources