How can I show categories with no posts on my wordpress site?
When I enter the urls of the category, it gives a page not found error. I want the blank page to appear even if there is no post linked to the category, how can I do it?
You can do this by editing your theme's template files. Look for the template file that contains the code for displaying your site's categories. In that file, find the code that checks to see if there are any posts in the category. If there are no posts, then that code should display a blank page.
Create a category.php file in your theme root folder.
<?php get_header(); ?>
<?php if( have_posts() ): ?>
<?php while ( have_posts() ) : the_post(); ?>
Category info
<?php endwhile; ?>
<?php else: ?>
There is No categories to show
<?php endif; ?>
<?php get_footer(); ?>
Related
I have three Posts in WordPress that each have the category Event.
I'm assuming that i use a WordPress codex to call those Posts to display when i want to.
What is happening is these Posts are all being displayed on index.php. I want to be able to use the WordPress codex and get the Posts for a certain category and display them. For example, display the posts in a pop up div.
How do i get Posts not to be displayed on the front page?
How do i get Posts of a specific category to display?
Or am i going about this the wrong way? I assume that Posts can be fetched from the database and be put in a popup div.
Here is my main inner html of my index.php
<div id="main">
<div id="nav">
<?php
if(!isset($_GET['page_id'])) {
wp_nav_menu( array( 'theme_location' => 'main-menu'));
}
?>
</div>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
the_content();
endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
</div>
I want it to fetch the current Page content and not the Posts.
<?php
if(!is_home() || !is_front_page) { // dont display on home page
if ( have_posts() ) : while ( have_posts() ) : the_post();
the_content();
endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif;
}
?>
look here for more conditional tags template tags
and to get posts from a particular category you can pass args in wp_query look here category args
Could we hide our full content in wordpress single page ?
Normally; i want to some text for all users instead of full posts on my single.php
Like;
If you read full post Please write your opinion :)
If user commented a post i want to display full posts to commenter is that possible or not ?
any help thanks
Simple Single.php
<?php get_header();?>
<?php the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php comments_template(); ?>
<?php get_footer();?>
I tried everything found in the web, but i'm getting errors or that's not what I am searching for...
I have to make a PAGE in wordpress, to show ONLY the posts of the category with a certain ID ( in my case id=8 )
i tryed to edit the loop-xxxx.php .. the template file... everything but I get always a problem
navigation system doesn't work. I mean... getting back to older posts won't work cause the output shows the last posts instead of older one.
The code I'm using in the loop or in the template file is:
<?php
query_posts('cat=8');
while (have_posts()) : the_post();
the_content();
endwhile;
?>
i tried inserting it before the
<?php while ( have_posts() ) : the_post(); ?>
in loop.php
or before the call of loop inside the index.php
please help me :\
One solution is to use a custom WP_Query. In the custom page's TEMPLATE file, where ID is the id of the targeted category:
<?php $tmp_query = new WP_Query('cat=ID');
while ( $tmp_query->have_posts() ) : $tmp_query->the_post();
the_content();
endwhile;
wp_reset_postdata();
?>
Check this.
<?php query_posts($query_string . '&cat=8'); ?>
<?php if (have_posts()) : ?>
<optional> You can write here: "You are in category X". </optional>
<?php while (have_posts()) : the_post(); ?>
Good luck.
I've built a custom page.php template. Very simple, essentially:
<?php get_header(); ?>
<?php get_sidebar(); ?>
<?php the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php get_footer(); ?>
I've created a few pages, and if I visit their url, I just get the same page title.
I read up in the documentation, and it says to use the_title() and such only when in "the loop".
So presumably, I'm just being shown the first page in the "array".
Is there any way I get get the contents of a single page based on the url?
Edit: In fact, should I even need to do this? Refering to example templates, it looks like I'm doing everything right?
In my sidebar I was using a custom query.
This was called before trying to access the main page content, without resetting.
When doing a custom query you must reset after you've finished your loop like so:
$originalPost = $post;
$sidePosts = get_posts($queryArgs);
foreach($sidePosts as $post) {
setup_postdata($post);
// echo it out like a normal post.
}
$post = $originalPost;
or if you are using query_posts() (which you shouldn't in a sidebar):
wp_reset_query();
Which will take your post back to it's previous value.
For a custom page template please use the following to get everything correct
<?php
/* Template name: My custom template */
get_header();
if ( have_posts() ) while ( have_posts() ) : the_post();
the_title();
the_content()
endwhile;
get_sidebar();
get_footer();
?>
I have a permalink structure of /%catergory%/%postname%/.
When I go to blah.com/categoryname I want all posts in that specific category to be listed.
When I go to blah.com/categoryname/post-name I want just the specific post to be displayed.
I have made a category specific template (category-5.php) and have got as far as...
// Display all post titles in category loop
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; ?>
<?php endif; ?>
// Display specific post in category loop
<?php if ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="storycontent">
<?php the_content(); ?>
</div>
<?php endif; ?>
...but obviously I only want the first loop to display when the url is blah.com/categoryname, and the second loop to display when the url is blah.com/categoryname/post-name.
Any thoughts? thanks
You can't have two loops running on the same page as you do here.
I believe you need to separate out the two things you're trying to do. To have a unique look/feel for the category, create a category-1.php file. To create a unique look/feel for the posts within that category, create a separate 'single' template.
This WP support thread explains how to create the 'single' template: http://wordpress.org/support/topic/266638
There are also a few "post template" plugins that help accomplish the same thing, if you prefer to go that route, for instance:
http://wordpress.org/extend/plugins/post-template/
Full list here: http://wordpress.org/extend/plugins/search.php?q=post+templates
Good luck!