Wordpress use index.php instead of single.php to show post - php

My Wordpress websites are not using single.php to show posts on the website. Every time I open a post, it opens it in index.php.
My single.php looks like this
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<? echo the_content(); ?>
<? endwhile;
endif; ?>
<? get_footer();
?>
How can I fix this?

I had the same problem with neither the single-CUSTOM-TYPE.php nor the single.php being rendered after clicking the single-post-link.... only index.php instead of the correct file...
What helped me was a simple change back to Standard Permalinks in "Settings" -> "Permalinks" and a restore back to "Name of the Post" (Beitragsname)....
...maybe this might help someone else as well...
greetz

This happens if the LOOP is not correctly setup ensure that index.php, and single.php contains the LOOP.
The loop normally looks something like this, but will change to setup requirements.
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
The Wordpress Codex site is pretty awesome and will answer most questions, check out http://codex.wordpress.org/The_Loop
Furthermore questions and discussions such as this one is more ideal if you post on stacks sister site Wordpress Stackexchange. I expect this question will be deleted or moved to https://wordpress.stackexchange.com/.

You should check your loop.php or loop-single.php weather it is routing from these files or not this are the page from where it will bring the data from database

Related

Editable posts WordPress

I'm trying to create my own template in CMS WordPress. I would like to have live editable text on my page http://restaurant.g6.cz/. I want to create something like posts and edit them from the web, because I can't think of anything better. I tried to paste into (page.php) something like
<?php
$my_post = get_post(168);
echo $my_post->post_content;
?>
and tried edit the text with plugin Live Editor but I wasn't successful, so I tried to write
<?php query_posts('cat=5&showposts=1'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
this was editable but every post needed it's own category. Does anyone know, how to do this in PHP or better way without plugins? Thank you all very much :)
Example

How do you integrate comment plugin from your wordpress into your blog.php HTML page?

I've read, watched so many articles and videos and just can't seem to put my hands on one thing. Any help would be appreciated.
So here it goes..
I have a wordpress blog and that has been integrated into my website in the blog.php, so that people can see my blog from my website instead of being linked to wordpress.. I wanted my clients to post comments from my blog.php site and currently it's only showing the default comment_form part(which is too big and not what I wanted) So I installed comments plugin called "DISQUS", but currently it's only showing up on my wordpress page and not my website at blog.php.
Could there be a php code that I'm missing to post on my blog.php?
So far this is what I have on the top of the blog.php page
<?php require('../wordpress/wp-blog-header.php');?>
and where I'm showing my blog part
<?php require('../wordpress/wp-blog-header.php');?>
<?php get_header();?>
<?php $posts = get_posts('numberposts=10&order=orderby=post_date'); ?>
<?php foreach ($posts as $post) : setup_postdata( $post ); ?>
<?php the_title(); ?>
<?php the_time('m/d/y') ?>
<?php get_footer(); ?>
<?php the_content(); ?>
<?php comment_form(); ?>
<?php endforeach; ?>
So am I missing something here? Should I be changing comment_form into something else? Or am I completely off?
Thanks Everyone.

Still need help... Embedding Wordpress page content into a PHP site

've done a lot of searching on the net and here, and cannot find the answer to this, though I know it may be ridiculously simple. I'm missing something...
I am trying to embed the content of a Wordpress PAGE (one which was created automatically by the Wordpress plugin All In One Event Calendar) into a page on my website.
(Note: I've confirmed that "page" and "post" are the same thing...)
When I visited the Wordpress codex, I got this page: http://codex.wordpress.org/Function_Reference/get_page which tells me that the get_page function has been deprecated and send me to the "get post" page of the codex.
The URL of the wordpress PAGE (not POST) that I'm trying to embed looks like http://xxxxxx.com/test/blog/?page_id=4.
I have the following code at the top of my site...
<?php
/* Short and sweet */
define('WP_USE_THEMES', false);
require('/home3/xxxxxx/public_html/xxxxxx/xxxxxx/blog/wp-load.php');
?>
(Note: have confirmed that wp-load works... wp-blog-header.php DOES NOT. Thanks, Bacon!)
And created the loop:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$id = 4;
$p = get_post($id);
echo apply_filters('the_content', $p->post_content);
endwhile; else :
_e( 'Sorry, no posts matched your criteria.' );
endif; ?>
The code I am using to attempt to embed the page content is:
<?php
$id = 4;
$p = get_post($id);
echo apply_filters('the_content', $p->post_content);
?>
It doesn't seem to be working. It returns the error message (Sorry, no posts matched your criteria.) Yet there IS a post (page) with the ID of 4.
What am I missing?
Please be gentle and thank you in advance for any help you can provide.
Require wp-load.php instead of wp-blog-header.php.
get_post($id) should also work as a way to get a page.

Using the loop to display content, every page only displays Homepage

I am building a theme in WordPress and being a little out of practise I am struggling to make The Loop work properly. I have inserted the most basic loop into the theme and it displays the content fine.. but when I click onto another page or the news page etc, it still just displays the home page.
I'm not sure if I'm just being oblivious to some blindingly obvious problem with my code, but I assumed that the loop displayed whichever page you were currently viewing, or do I have to set up a mishmash of if(is_page('home')) then do a certain wp_query etc?
The loop code I have is inserted below, and if theres any information I forgot I will try update this post with it.
<?php query_posts(); ?>
<div class="content">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title() ;?></h2>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts to list</p>
<?php endif; ?>
</div>
Summary: The Loop is only displaying Homepage content on every page.
edit:
Even after disabling my plugin with the first loop in it, the proper Loop isn't working. it is the exact code posted above, and it just won't display the page I am on, or the news on the correct page or anything.... what am i missing
Try removing the query_posts(); line and try again
Apparently... My WordPress install doesn't work with pretty permalinks. As soon as I set it back to default settings, it all worked fine, but if I choose any option other than default, then only the homepage shows up (on any theme).

WordPress: How to display only posts that are in a certain category?

I'm pretty new to WordPress but have spent some 50 odd hours studying up on it, trying things out and such and have the feeling I got a pretty good handle on it now..
However the one thing I simply cannot get working is to have a page spit out a list of posts of a certain category.
Here is my example: http://dev.jannisgundermann.com/zoeikin/graphic-design/typographic-posters
I have a post that if I go to it directly works correctly, but does not show up on this page.
The post direct link.
The category id is '3' while the category name is 'typographic-posters'.
I have a custom page template for the typographic-posters page that looks like this:
<?php
/*
Template Name: Typographic Posters
*/
?>
<?php get_header(); ?>
<?php get_sidebar(); ?>
<?php if (in_category('3')): ?>
<div class="post">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div class="post-description">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</div>
<?=get_image('flutter-image');?>
</div>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div>
<?php endif; ?>
<?php get_footer(); ?>
Using this code however the page only shows gets the header, sidebar and nothing else..
If someone could help me out that would really help me get a handle on this filtering of wordpress categories.
Thanks for reading,
Jannis
in_category will only work outside of the loop on a single page. I suggest using the query_posts function to solve this problem. You may use query_posts('cat=3') or query_posts('category_name=typographic-posters') to get the posts you are looking for.
Once obtained, just use the normal WordPress loop to access these posts.
The easiest way is to create a file called category-3.php and use the standard code from normal index.php or category.php file. Wordpress will take care of fetching posts only from category with id=3 and it's child categories.
in_category will only work outside of the loop on a single page. I
suggest using the query_posts function to solve this problem. You may
use query_posts('cat=3') or
query_posts('category_name=typographic-posters') to get the posts you
are looking for.
Once obtained, just use the normal WordPress loop to access these
posts.
This worked excellent, but make sure that you go into Settings > Reading and set the posts page to the -- Select -- option or it will override this query and dump all recent posts there regardless of category.
Simply add before the loop:
<?php query_posts="cat=3&showposts=5">
This will force the loop to display 5 posts (showposts=5) from category 3 (cat=3).
I would 2nd Eimantas' suggestion. The Template Hierarchy will use the category-3.php to display posts in that category. Usually you can just copy a theme's index.php or category.php to category-3.php and adjust that template for any customization you need. Plus the category template will better support pagination of posts.
But if you need to stick with a Page to display those posts, also see the Page of Posts example.
http://codex.wordpress.org/Template_Tags/query_posts
Just so you know where these answers are coming from...there are a lot more interesting functions you can do with query_posts as well.
This plugin could also help you if you want to be able to change the displayed categories without going through the code :
http://wordpress.org/extend/plugins/advanced-category-excluder/
I have filtered post by category Id using the method below:
query_posts('cat=1&showposts=3');
if (have_posts()) : while (have_posts()) :
// if(1) {
//echo the_category_ID();
the_post();
/**
* The default post formatting from the post.php template file will be used.
* If you want to customize the post formatting for your homepage:
*
* - Create a new file: post-homepage.php
* - Copy/Paste the content of post.php to post-homepage.php
* - Edit and customize the post-homepage.php file for your needs.
*
* Learn more about the get_template_part() function: http://codex.wordpress.org/Function_Reference/get_template_part
*/
$is_post_wrap++;
if($is_post_wrap == '1') {
?><div class="post-wrap clearfix"><?php
}
get_template_part('post', 'homepage');
if($is_post_wrap == '3') {
$is_post_wrap = 0;
?></div><?php
}
endwhile;
else :
get_template_part('post', 'noresults');
endif;
thank you for sharing on your thought its a great thought. Usually you can just copy a theme's index.php or category.php to category-3.php and adjust that template for any customization you need

Categories