I've inserted the following code to the template loop (in the correct place), but it is not outputting any comments. Why?
<?php
$withcomments = true; // force comments form and comments to show on front page
comments_template( '', true );
?>
I'm trying to display comments for each post on the main-home-page stream of posts.
I'm using the Twenty Ten theme.
Try this before the <?php endwhile; ?> of the loop in loop.php:
<?php
$withcomments = "1";
comments_template();
?>
Try this:
<?php global $withcomments; $withcomments = 1; comments_template(); ?>
There is a much simpler way that doesn't involve editing PHP code. First make sure you can create comments on other pages and if that is working, go back to the home page.
On the top right, click the gear icon to show settings and near the bottom of settings change the "page attributes" "template" from "front page template" to "default template". Save and you will have comments.
However, you may lose other features of the home page (you can always change the template back). For me I didn't lose anything.
Understand that a normal WordPress blog is intended to have comments on the blogs (posts), but not on the home page. By default you shouldn't even have comments on any pages (just posts), but that is easily enabled. That is why normally there aren't any comments allowed, but if you have a one-page site this is a problem.
Also note that there are many different themes and some do allow comments on the home page.
Related
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
So, i finally got my css and js scripts to load on WP
Now there is but one thing i need to get done.
i have my own theme, including header.php, footer.php, page.php
header.php and footer.php is working just fine, loading scripts and showing properly, but now i need to add all the other content.
my page.php is currently:
<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header(); ?>
<?php the_content(); ?>
<?php get_footer(); ?>
I would need to somehow add html content to pages, i have about 20 ready made .php pages which needs to be transfered to WP.
Soooo how do i go about making new page (pages -> add new) and using page template while getting the html content to show up?
I've tried to just make new page and in text mode add up all the html into page, but it only shows empty page with header and footer, so the problem is most likely the page.php and i have no idea how to get it to work.
You can do look like this:
<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header(); ?>
<?php
while ( have_posts() ) : the_post();
the_content();
endwhile;
?>
<?php get_footer(); ?>
You are on the good way. While developing a custom theme from scratch is a great challenge it's not too hard.
I could recommend to take it easy and follow this tutorial I found really helpful some time ago, I learned a lot there:
Developing a WordPress Theme from Scratch
You must have the official source documentation always in your mind:
Theme Development
Do some reading and you will see that making themes is really fun and gratifying :)
EDIT:
I would recommend picking a good starter theme or framework and work using child themes. You have plenty of them to pick.
To get started adding a new page to your WordPress site, find the Pages menu in the WordPress Dashboard Navigation menu. Click Add new.
The WordPress page editor looks nearly identical to the post editor, except for a few different boxes located on the right side of the screen.
Add the title of the page, like About. Note: If you have pretty permalinks set up, the title of your page will also be the URL slug.
Next, add some content.
The Publish section of the page editor is exactly the same as for writing posts. When you’re ready to publish, you can either publish immediately, save this or a draft, or schedule the page to be published later.
The Page Attributes section applies a parent page and template to your new page. For the Parent section, you can arrange your pages into hierarchies. For example, you could create this new page with additional pages under it. There are no limits to how many levels you can nest pages.
Some WordPress themes have custom page templates, so the next Template section allows you to apply a template to your new page.
The Order box allows you to order your page numerically. Pages are usually ordered alphabetically, but you can choose your own order by entering a number in this field.
Preview the page one last time, then click Publish. You’ve added a new page to your WordPress site.
This is how your
your index.php should look like :
<?php
get_header();?>
<div class="YourContainer">
<div class="Whatever">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="ContentSectionDiv">
<?php the_content();?>
</div>
<?php endwhile; ?>
<?php else: ?>
<?php endif; ?>
</div>
</div>
<?php get_footer();?>
you can make also a custom loop
<?php
$arg = array("post_type" => "services",
"posts_per_page" => 9,
"order_by" => "date",
"order" => "ASC",
);
$services = new WP_Query($arg);
if ($services->have_posts()):;
while ($services->have_posts()):$services->the_post();
the_content();
endwhile;
endif;
?>
I'm trying to use as few plugins on my WP site as possible. Therefore I created custom fields for posts and pages to create a title tag and meta description.
The code look as follows:
<title>
<?php $title = get_post_meta($post->ID, 'Title', true);
if ($title) { ?>
<?php echo $title; ?> | domain.com
<?php }
else { ?>
<?php wp_title(''); ?> | domain.com
<?php } ?>
</title>
The code works like a charm, unless for one cause. The homepage titletag is similar to the most recent blog posted (my homepage is a blog overview). Obviously I don't want that.
I found that inserting the following code right under <title> works
<?php if(is_home()) { echo "My desired homepage title tag"; } ?>
However, the title tag now contains both the desired title tag AND the title from the custom field. I first thought I could simply solve that by using the logical if, elseif, else contruction and change the following:
if ($title) { ?>
into elseif.
However then my whole site breaks and I get a blank page in return for every URL I try to access.
Then my PHP knowledge stops. I have no idea how to solve the double title. Can someone help me out and point what I'm doing wrong? Why doesn't the conditional statements work
The main reason should be that when you access $post->ID you get the ID of the latest inserted post, not the homepage.
By default wordpress loads the latest post an you have them ready to use in the loop.
To avoid that you have to set a different homepage than "latest posts" in "settings" -> "reading".
Once you do that you'll se the correct title loading up.
Anyway I would advise to use the super useful WordPress SEO plugin by yoast, is the de facto standard for this kind of things and is used by a lot of high traffic wordpress installation.
let me know
Goal - have a section of my sidebar that is conditional depending on what page I'm on. All child pages of the selected page should also show the conditional section.
There are at least two ways to do this - 1) have all the conditional hooks and resulting code in one sidebar file and, 2) have multiple sidebar.php documents and call them based off what pages are being visited.
I've pretty much failed at both ways so far... :( I'm working on the second method right now though, because I think it might be more flexible long term. Anyway, in my page.php I replaced:
<?php get_sidebar() ?>
With
<?php
if (is_page(1997) || $post->post_parent) {
get_sidebar('sidebar-test-may12.php')
}
else { get_sidebar()
} ?>
With the hope of testing the method. What I want to happen is that if the page is page id 1997 or any of its child pages please show sidebar-test-may12.php. Otherwise show the regular sidebar. With the new code the whole page goes blank. Any suggestions or solutions for me? Seems like a common problem, but I haven't been able to figure it out yet. Thanks!
You have a few problems with your code example:
1) $post->post_parent is not being checked against anything else, so it will only return true if it is a child page (not necessarily the child of the page you want to target)
2) get_sidebar() is being called incorrectly. If you want to get 'sidebar-test-may12.php' from your theme folder, you need to call get_sidebar('test-may12')
3) You're missing semicolons after your function calls
So your code should look like this:
<?php
if(is_page(1997) || $post->post_parent == 1997) {
get_sidebar('test-may12'); //get sidebar-test-may12.php
}
else{
get_sidebar(); //get sidebar.php
}
?>
Let me know if that helps.
UPDATE: Bear in mind, $post->post_parent does NOT get the top-most ancestor ID of a child page. If you want to grab the top-level ID regardless of depth, consider doing this:
<?php
$ancestors = get_ancestors(get_the_ID(), 'page');
if(is_page(1997) || end($ancestors) == 1997)
get_sidebar('test-may12'); //get sidebar-test-may12.php
else
get_sidebar(); //get sidebar.php
?>
POSSIBLE SOLUTION: Building off your example and my proposed ancestry check, one thing you can do is have your template check to see if a special sidebar exists in your theme based on the parent page's slug. This way, if you decide a particular page needs a special sidebar for it and all of its children/grandchildren/great-grandchildren/etc. you just need to add it into your theme with a name of 'sidebar-{parent_slug}.php'. So:
<?php
$id = get_the_ID();
$ancestors = get_ancestors($id, 'page');
$top_page = $ancestors ? get_page(end($ancestors)) : get_page($id);
if(locate_template('sidebar-'.$top_page->post_name.'.php'))
get_sidebar($top_page->post_name);
else
get_sidebar();
?>
This way, you don't need a ton of conditionals to decide which Sidebar file to load on a general Page template.
Use some error trapping to show what's going on with your php, either toggling an error log in .htaccess of a simple widget: http://wordpress.org/extend/plugins/error-log-dashboard-widget/
I've hardcoded logic for sidebars, but I've also used WordPress › Widget Logic « WordPress Plugins for my own and client sites. It's easy to use with a simplified version of WP conditionals, like is_category and is_page ('101')
For someone else tackling this same problem -- there is a new plugin out that solves this problem very well. It even makes creating the sidebars easy. You can check it out here:
http://wordpress.org/extend/plugins/custom-sidebars/
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;?>