Hi i have an wp website and i'm using avada theme. I want to hide header according to its category. For example if posts category is "A" then i dont want to show header on the top automatically. I know i can manually adjust that in the post settings on every posts, or set a layout and select that layout on the below but i dont want to deal that every time.
So i try a if statement in the archives.php.
its something like this:
<?php if(has_category( 'A' )) : ?> //i also try in_category and on_category
<?php else: ?>
<?php get_header(); ?>
<?php endif; ?>
but its probably for category page itself but not for posts.
Can anybody help with that?
Thanks :)
hi you can go with following links and follow the given solution it may worked..
here it show that how to hide specific c***ategorize header post*** ...
https://wpquestions.com/Remove_header_or_styling_from_specific_category_of_posts/11505
I'm very new to wordpress and was just wondering if anyone
could point me in the direction of a tutorial which will explain
how to add my own code to wordpress pages.
So far all that I've been able to find is that I'm supposed
to copy the page.php from my template and use that as the
template for a page added in wordpress. This however only
gives me control over the body and not the header/nav menu/sidebar.
Am I correct is assuming I must replace the method calls such as
get_header(), etc with the code it would generate and manipulate
it from there? Also is it correct if I change the arguments to
get_template_part( 'content', 'page' ); and add a php page with
the appropriate name for the body?
Way 1 You can do this:
1) add new page
2) add these code to index.php or page.php
<?php
if (is_page('About 3C')) {?>
<div>Display this particular div</div>
<?php }
else { ?>
<div>Display that particular div</div>
<?php }?>
or
<?php
if (is_page('About 3C')) {
<div>Display this particular div</div>
}
else {
<div>Display that particular div</div>
}
?>
assume your added page name is: About 3C
and you can call the database from above code
OR way 2: please refer:
http://line25.com/tutorials/how-to-create-a-wordpress-custom-page-template
I am looking for a way to present search results in my custom wordpress theme.
I was hoping being able to present the results like this:
Displaying 4 search results for "test"
Pages
testpage 1
testpage 2
Posts
testpost 1
testpost 2
I wrote a function is_type_page that I can use inside the loop (2 loops), but this breaks the pagination functionality.
Any suggestions how to achieve this?
I would run 2 separate loops on the page, after the first loop for pages run rewind_posts() and then run the loop again. Also the key to pagination is making sure the global $paged variable is being picked up on by both loops. $paged is how wordpress separates posts into pages. i.e. if you go to page 2 of something then the global $paged = 2.
Hope that helps
Multiple loops using rewind_posts here
Running two loops is the way to go if you want them displayed with separate headers. Here is code to get them to show intermingles as they come up by date created...
<?php while (have_posts()) : the_post(); ?>
<?php if ( $post->post_type == 'page' ) { ?>
**DISPLAY PAGE**
<?php } else { ?>
**DISPLAY POST**
<?php else : endif; ?>
I am modifying a wordpress template and need to slightly separate rendering logic for a post and a page, specifically in relation to how the date renders out. The problem is that I cannot find any code to do this, I am sure that it exists. Is there a variable that exists within wordpress that tells me whether the item being displayed is a page or a post?
In an ideal world it would look something like this:
<?php if (is_page()) : ?>
page logic
<?php else: ?>
post logic
Would appreciate any help!
Pages are a type of post, so get_post_type should return appropriately different values for pages vs normal blog posts.
I found this link: http://wordpress.org/support/topic/sidebar-logic-for-postblogroll-and-page-type which seemed to do the business for me.
The answer (copied straight from the page) was:
<?php if(is_singular($post)): ?>
Page Content
<?php else:?>
Post Content
<?php endif;?>
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