WordPress, Posts are being displayed on front page(index.php)? - wordpress

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

Related

how to display categories without topics

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(); ?>

can I have widget appear in single post for specific category

i would like to have a sidebar appear in a single posts for a specific category. I not great at php so this is what i have been able to come up with. It does not work of course lol. Your help will be very much appreciated!
<?php if( in_category('9') ) : ?>
<div>
<h1>Other Products I Recommend</h1>
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('products2')) : ?>
[ do default stuff if no widgets ]
<?php endif; ?>
</div>
<?php endif; ?>`
There are two options for that:
There is a plugin that can help you with this. It's called jetpack. When it is installed and activated, when you add any widget to a sidebar there will be a visibility option, click that and choose which pages/categories/etc to show the widget it.
Code:
As for your code:
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('products2')) : ?>
that says if the dynamic_sidebar function doesn't exists or if it's not the products2 sidebar then do X. That function will exist as sidebars are set in that function, so nothing inside that if statement will run.
You will want something like:
<?php if( in_category('9') ) : ?>
<div>
<h1>Other Products I Recommend</h1>
<?php dynamic_sidebar('products2'); ?>
</div>
<?php endif; ?>
that should display the contents of what you have added to the products2 sidebar only when you are in a post that has a category id of 9.

Wordpress Post by Category

I'm developing a website with Wordpress. What i need is make a page which shows only post with a specific category. What shall I do?
For instance, page Javascript, only displays post with the cateogry Javascript.
I don't know how good you are with PHP, but you need to create a Wordpress template where it queries the posts from your category.
You can read about the archive page here where it displays all your posts:
http://wp.tutsplus.com/tutorials/create-a-wordpress-archives-template-for-your-theme/
Just before this:
<?php while ( have_posts() ) : the_post(); ?>
Add this to query it to a specific category:
<?php query_posts('category_name=News'); ?>
Where 'News' is your category name!
<?php query_posts('cat=1'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_title();?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
You can read more about query_post here http://codex.wordpress.org/Function_Reference/query_posts

Display post content from wp_nav_menu?

I have made a wp menu that lists a bunch of posts.
I am able to list these posts' titles but not its content.
wp_nav_menu(array( 'menu' => 'Compatibility Matrix') );
How do i display the contents of each item (post title) ?
You can't list the post's content with the wp_nav_menu function, that is solely used to create a navigation menu with the post/page titles or custom title that you assign the menu item.
You need to use a loop to display the content. This is a very basic loop:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
You can modify it to suit your needs. Here are a couple resources to help you out:
http://codex.wordpress.org/The_Loop
http://wp.tutsplus.com/tutorials/theme-development/a-beginners-guide-to-the-wordpress-loop/

Wordpress : List posts in category on '.com/categoryname' and display post on '.com/categoryname/post-name'

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!

Resources