Wordpress: category page not for post's - wordpress

Please at first let me explain my question. I use wordpress to create web sites for flash games, so I don't have certain page for post's. I add each game by
<code>
post-new.php?post_type=game
</code>
and u can see it's not the regular post for wordpress.
I try to use this code from codex:
<code>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$i = 0;
$loop = new WP_Query(array('post_type' => 'game', 'post_per_page' => 5 ));
while ($loop->post_type()) : $loop->game();
?>
</code>
<code>
<?php if ( in_category('') ) { ?>
<div class="post-cat-three">
<?php } else { ?>
<div class="post">
<?php } ?>
<h2><?php the_title(); ?></h2>
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
<div class="entry">
<p>Category: <?php single_cat_title(); ?></p>
</div>
<p class="postmetadata">Posted in <?php the_category(', '); ?></p>
</code>
I think it really have to works for posts, but in such case I try to change post for games, try many ways, but don't sucseed yet.
Could anyone tell me what I have change in this code?
i think that promblem in the begining with 'have post' and 'the loop'.
Thanks.

I hope this will help. This is from my WordPress custom post type (loop):
<?php query_posts('post_type=clients&showposts=1000');
if (have_posts()) : while (have_posts()) : the_post();
$nameofclient = get_post_meta($post->ID,'name_of_client',true);
$clientcompany = get_post_meta($post->ID,'company_of_client',true);?>
<div <?php post_class();?> id="ka-<?php the_ID(); ?>">
<h2 class="categorytitle"><?php the_title(); ?></h2>
<?php the_content(); ?><p class="ats_autors">/ <?php if($nameofclient): echo '<span class="client">'.$nameofclient.'</span>'; endif; if($clientcompany): if($nameofclient){echo ', ';} echo '<span class="client-company">'.$clientcompany.'</span>'; endif; ?></p></div><?php endwhile; endif;wp_reset_query();?>

Just found one mistake: in_category('') MUST be filled with category ID in slug. http://codex.wordpress.org/Function_Reference/in_category#Parameters
Correct would be in_category('some-game-cat-slug')
plus worth to read http://new2wp.com/noob/query_posts-wp_query-differences/

Related

Search results that include words in the category and tags? WP

EDIT: Solved my main question.
I'm going around in circles here, finding similar questions but nothing quite right.
Q: I'm trying to add search results that include words in the category and tags.
For example; I have posts with documentary in the title and or description but not the title of the said documentary. If I search for the name of this documentary that isn't mentioned in the title and or description but it's filed under category x and or tags then I'd like it to show up in search. Reason being, I made posts about the documentary before I knew the name of it yet.
Also, is there a way to divide search results up, such as:
News (Posts) results found:
Page results found:
Or somewhere in the title that says what type of result each one is (post or page)
If too complicated, don't worry about that one. I'm mainly focusing on the main question.
I'm ever so grateful for your help. Thank you in advance.
My search.php is this:
<?php get_header(); ?>
<?php get_sidebar(); ?>
<div id="content">
<div class="article">
<?php if ( have_posts() ) : ?>
<?php
global $wp_query;
$total_results = $wp_query->found_posts;
?>
<?php printf( __( 'Search results for: %s', 'shape' ), '<span>' . get_search_query() . '</span>' ); ?>
<br/><br/>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="date">
<?php the_time('M j, Y') ?> </div><div class="posttitle"><?php the_title(); ?></div>
<?php endwhile; ?>
</div>
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { ?>
<div class="right"><?php next_posts_link('Next Page »') ?></div>
<div class="left"><?php previous_posts_link('« Previous Page') ?></div>
<?php } ?>
<br><br><br>
<?php else : ?>
<div class="posttitle">Nothing found. Try something else?</div>
This page doesn't exist
<?php endif; ?>
<?php get_footer(); ?>

wordpress comment form styling

I have integrated a HTML Template into Wordpress theme. In, menu area there is a menu called Blog. On click of that menu I want to show all the posts. On clicking some particular posts title one should go to the single post`s page. On that page there should be comments shown which are being posted earlier by some one as well as the comment form through which one can comment on that post.
Below is my blog.php code
<?php
/*
Template Name: Blog
*/
?>
<?php get_header(); ?>
<div id="inner_contant">
<div id="all_post">
<?php
$myposts = get_posts('');
foreach($myposts as $post) :
setup_postdata($post);
?>
<h2><?php the_title(); ?></h2>
<div class="author">Posted by <?php the_author(); ?></div>
<div class="post_excerpt"><?php the_excerpt(); ?></div>
<?php endforeach; wp_reset_postdata(); ?>
</div>
</div>
<?php get_footer(); ?>
Below is my single.php code
<?php
/*
* The template for displaying all single posts and attachments
*/
?>
<?php get_header(); ?>
<div id="single_post_wrap">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="time_and_author"><?php the_time('F jS, Y') ?> by <?php the_author() ?></div>
<div class="post_content"><?php the_content(); ?></div>
<p>Posted in <?php the_category(', ') ?> | <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
<?php endwhile; endif; ?>
<?php foreach (get_comments() as $comment): ?>
<div><?php echo $comment->comment_author; ?> said: "<?php echo $comment->comment_content; ?>".</div>
<?php endforeach; ?>
<?php comments_template(); ?>
</div>
</div>
<?php get_footer(); ?>
Below is my comments.php code
<?php $comment_args = array(
'comment_notes_after' => '',
'title_reply' => 'Have something to say?'
) ?>
<?php comment_form($comment_args); ?>
I want to add some styling to that comment form. I have tried every thing but not worked for me. Thanks in advance for those who will help me.
WordPress' comment_form function prints a form with id 'commentform'. So you can use CSS to style this form.
form#commentform {
// your styles.
}
form#commentform input {
// your styles for inputs
}
/* default class of submit button is 'submit'. For changing it: add a
* key=>value to comment_form args like
* 'class_submit' => 'your_submit_class'
*/
form#commentform .submit {
// your submit button styles.
}
Also, you can change ID of comment form like this:
<?php $comment_args = array(
'comment_notes_after' => '',
'title_reply' => 'Have something to say?',
'id_form' => 'myAwesomeCommentForm'
) ?>
<?php comment_form($comment_args); ?>

Wordpress Search result page display entire content

I have a signifiantly big problem up there.
I'm trying to design my search restult page on WordPress, but if it comes that the search find a page with the keyword I just entered, it display the entire page instead of the title();
My code
<?php
/**
* The template for displaying search results pages.
*
* #package miller
*/
get_header(); ?>
<section id="primary" class="content-area">
<main id="int_top_main" class="internal blue_top" style="min-height:80px;">
<div class="wrapper">
<h2 class="page_title uppercase"><span class="parent_page">Search results</h2>
<div id="infinite_blue_top_bar"></div>
</div>
</main><!-- #main -->
<div id="int_content_main" class="internal">
<div class="wrapper physician_headline">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
<?php else : ?>
<h2><?php _e( 'Nothing Found', 'miller' ); ?></h2>
<div class="page-content">
<?php if ( is_search() ) : ?>
<p><?php _e( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'miller' ); ?></p>
<?php else : ?>
<p><?php _e( 'It seems we can’t find what you’re looking for. Perhaps searching can help.', 'miller' ); ?></p>
<?php endif; ?>
</div><!-- .page-content -->
<?php endif; ?>
</div>
</div>
</section><!-- #primary -->
<?php get_footer(); ?>
If it finds nothing, it will go into the else: but if it do finds something they display all the pages (fullpage) of what it finds out there.
It should only display the_title(); but no..
Even if I completly destruct the search.php file it stills automaticly goes to the "suggested" page.
First time I am getting this kind of thing and I do not know how to solve it :(
It's calling for the post before the title, which is why it pulls for the full post.
Try:
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_title(); ?>
<?php endwhile; ?>
<?php else : ?>

Category permalink redirects to index.php

When I type "localhost/?cat=3" for example, to show all posts of category whose ID is 3, instead of doing it, it shows all posts of all categories (which is the job of my index.php), so I guess that a redirection to homepage is happening. I really don't know what to do. Can you help me? Here is the code of index.php to retrieve posts:
<?php
$tmp = $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$wp_query = new WP_Query('cat=-4&posts_per_page=5&paged=' . $paged);
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<div id="wrapper2">
<div id="topicos" >
<p id="titulo"><?php the_title(); ?></p>
<p id="data_public">Publicado em <b><?php the_time('j') ?> de <?php the_time('F, Y') ?> </b> por <?php the_author() ?></p>
<?php if(has_post_thumbnail()){
?> <div id="thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<?php
}
?>
<div id="prv_texto"><?php the_excerpt(); ?></div>
<p id="cont_lendo">Continuar lendo...</p>
</div>
<?php endwhile; ?>
<?php endif; ?>
Have you tried making an archive.php file in your theme, and running a bare bone Wordpress loop without a custom query before it?

Wordpress blog isn't showing posts. Does adding a custom portfolio post field effect this?

Now I've done this a couple other times with no problem, I have a main page using home.php and the blog as another page using "blog-home.php" blog template with all the right code to grab the posts but it's not displaying. The only difference is I've added a custom portfolio post field to the functions, would this be effecting it or could it be something else? I can access a post from the home page under latest post putting the code below but that's it.
<?php query_posts("post_per_page=1"); the_post(); ?>
<p><?php the_excerpt(); ?></p>
<?php wp_reset_query(); ?></div>
*UPDATE: I've tried another code but now it is only displaying the blog page as a post. *
<?php
/*
Template Name: Blog Home
*/
?>
<?php get_header(); ?>
<div id="contentwrapper">
<?php query_posts( array ( 'category_name' => 'Blog', 'posts_per_page' => 5 ) ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div class="blogentry">
<h4><?php the_title(); ?> </h4>
<?php the_content(); ?>
<div class="postmetadata">
<?php the_tags('Tags: ', ', ', '<br />'); ?>
</div>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
</div>
</div>
<?php endwhile; ?>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
</div>
<?php get_footer(); ?>
Maybe if you use
$posts = get_posts(array('numberposts' => 1));
global $post;
$post = $posts[0];
the_excerpt();
instead
query_posts();
is never a good idea change the global query if get_posts dosn't work for you try with WP_Query()

Resources