loop wordpress Posts NOT in index , in another template - php

did read alot on stackoverflow and wordpress documentation but nothing works
iam using newest WP version
i createt a template named contact.php
<?php
/*
* Template Name: Contact Template
* description: >-
Page template
*/
get_header();
?>
everything works , you can choose the template in wp admin dashboard when creating a new site
but the post loop dosent work. only on the index.php
this code i use in index. works fine. if i copy over to my template it will not load the posts
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="col-12 mt-4 mb-4 justify-content-center text-center">
<a href="">
<h1><a href="<?php the_permalink(); ?>">
<?php the_title(); ?> </a></h1>
</a>
<hr>
<p> <?php the_excerpt(); ?> <br> </p>
<style>
img {
height: 200px;
width: 200px;
border-radius: 20%;
}
</style>
<?php if (has_post_thumbnail()) : ?>
<?php the_post_thumbnail(); ?>
<?php endif; ?><br>
<p> <?php the_author(); ?> <?php the_date(); ?><br> </p>
<p></p>
</div>
<?php endwhile; ?>
<!--end the while loop-->
<?php else : ?>
<!-- if no posts are found then: -->
<p>No posts found</p> <!-- no posts found displayed -->
<?php endif; ?>
<!-- end if -->
</div>

Actually when you create a new template into Wordpress theme folder directory you should copy from the one that is used from your template to render the post list.
As you can see here from wordpress documentation index.php is just the deepest level wordpress reach if it doesn't find any other suitable template.
If you are unsure of what template to use i suggest you to install query monitor and see from the wpadmin top bar in your frontend which is the template for a standard post loop page.
If you copied from the correct template there should be no standard reason of why that should fail. If it doesn't work for you what i can suggest is to see if the problem still happens with default template (like twentytwenty) or disabling all your plugins.

Related

How to add custom div in wordpress static page

Here I have a Wordpress theme, which is working fine.
Now I want to append my custom div under existing content. here are 2 existing panels which are following:
I'm new comer in WordPress so kindly assist me, how to achieve this requirement. your kind efforts would be heartily appreciated.
STEP 1: Open your wp-content->themes->your Theme Name-> footer.php
at very top beginning add div there but make sure it will show on all page.
Example:
<div class="infooterfile"></div>
<footer>
<div class="footer-wrap">
<div class="icoach-section">
<div class="footer-logo fadeIn animated">
<?php
$icoach_dark_logo=get_theme_mod('icoach_dark_logo');
$icoach_dark_logo=wp_get_attachment_url($icoach_dark_logo);
?>
<?php if($icoach_dark_logo != '' && !empty($icoach_dark_logo)): ?>
<img class="img-responsive" src="<?php echo esc_url($icoach_dark_logo); ?>" alt="<?php esc_attr_e('Logo','icoach');?>">
<?php endif; ?>
</div>
NOTE: If you want to show it only home page then you need to add div above <?php get_footer(); ?> in home page separate template.
EXAMPLE: in homepage separate template
<?php
/**
* The main template file
**/
get_header(); ?>
<div class="heading-wrap blog-heading-wrap" >
<div class="heading-layer">
<div class="heading-title">
<h1><?php _e('Blog ','icoach'); ?></h1>
</div>
</div>
</div>
<div class="yourdiv"></div>
<?php get_template_part('content'); get_footer(); ?>

Blog Posts Wordpress Customizing

I am creating my own custom theme from scratch and have run into a bit of trouble. On the blog page, each time a new post is displayed, it is smaller than the last. This is due to me setting the width of the blog post to 33.3%. Also each blogpost gets displayed slightly right of the one previous to it. How can I have each blog post be 33.3% of the content area and be displayed side by side, 3 per row? I am using wordpress functions to call each blog post. I am only displaying the blog posts thumbnail and when you click the thumbnail it takes you to the post. So basically 3 images side by side.
[BONUS]: How could I get text to display horizontally and vertically on hover over each blog post image?
I know this is a lot to ask, but I have been trying to work this out for days. A JS Fiddle or Codepen would be greatly appreciated.
Index.php:
<?php get_header(); ?>
<div class="blog-posts">
<?php while (have_posts()) : the_post(); ?>
<div id="page-content">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
<h3><?php the_title(); ?></h3>
</a>
<?php endwhile; ?>
</div>
</div>
<?php get_footer(); ?>
You should use bootstrap and do something like this :
<?php get_header(); ?>
<div class="blog-posts">
<?php while (have_posts()) : the_post(); ?>
<div class="col-md-4">
<div id="page-content">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
<h3><?php the_title(); ?></h3>
</a>
</div>
</div>
<?php endwhile; ?>
</div>
<?php get_footer(); ?>
Take care to remove the width: 33.33%; CSS rule and close your <div> tags in the loop, not after.
Hope it helps
[EDIT]
See this link for more information about how to use column classes with bootstrap : grid example basic
[EDIT #2]
You could do it without bootstrap but it will be a bit more difficult. You'll have to set the "display" to "inline-block" and set the width of the divs with taking care of the inherit margin of these tags. In this example, I had to set it to 32%. Here is the fiddle

AJAX Page Loading on Wordpress

I'm trying to install the "Advanced AJAX Page Loader" plugin on my Wordpress site. The theme installation says to "make sure your theme has the content area wrapped in a tag such as a DIV with an id attribute called "content"".
My theme has what looks like a variable div wrapper around my content in the page.php file:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="page-<?php the_ID(); ?>" class="type-page" itemscope itemtype="http://schema.org/Article">
<!-- page-title -->
<?php if($themify->page_title != "yes"): ?>
<h1 class="page-title" itemprop="name"><?php the_title(); ?></h1>
<?php endif; ?>
<!-- /page-title -->
<div class="page-content entry-content" itemprop="articleBody">
<?php the_content(); ?>
My questions are, does it look like I am looking at the right section of code, i.e.
If so, how would I identify the corresponding div wrapper, which looks like it's variable based on page ID: ?
The instructions are asking you to wrap your content area in a div with an id of 'content'. Your code above doesn't have that;
<div id="content">
// content here
</div>

How Can i Remove all sidebars from specific wordpress pages?

hi everyone im trying to remove all of the sidebars from a specific video page im creating on a wordpress site ive found tutorials on google on how to do this if the sidebars are called to the page using the
<?php get_sidebar(); ?>
method however my theme uses following method to call sidebars to a page
<?php include(TEMPLATEPATH."/sidebar.php");?>
i cant find any good methods for removing the sidebars that calls them to a page the same way as my theme does. here is the code to my page.php file on my website any help understanding how to remove them would be greatly appreciated =)
<?php get_header(); ?>
<div id="breadcrumb"><?php breadcrumbs(); ?></div>
<?php include(TEMPLATEPATH."/sidebar.php");?>
<div id="kontenutama">
<div class="postingan">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="bookmark">
<?php the_title(); ?></a></h2><?php the_content(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<br style="clear:both;">
</div>
</div>
<?php include(TEMPLATEPATH."/r_sidebar.php");?>
<br style="clear:both"><div style="clear:both">
</div>
<?php get_footer()?>
Why not create a new WordPress page template and remove the sidebar include on that page?
The theme is pretty dodgy, it shouldn't ever include files like that in template pages.

Custom Post Meta Search Template

I'm struggling with getting wordpress to search custom post meta from a page template. I've looked all over the internet and can't seem to find anything that will work. No plugins seem to work either.
On my posts, I have the custom meta: "rate" and the value: "10" - Wordpress delivers no result when searching any of these.
I'd be very appreciated if someone could write me a searchpage.php page template or point me in the right direction (I'm not good with php).
Here's my current PHP code:
<?php
/*
Template Name: Search Custom Meta
*/
?>
<?php get_header(); ?>
<div id="content">
<div class="container clearfix fullwidth">
<div id="left-area">
<?php query_posts('meta_value='.$s); ?>
<?php if (!empty($wp_query->posts)) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
</div> <!-- end #left-area -->
</div> <!-- .container -->
</div> <!-- #content -->
<?php get_footer(); ?>
You checking incorrect variable in if so try removing that one,
query_posts('meta_value='.$s);
while ( have_posts() ) : the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;

Categories