WORDPRESS: Disable comments in "News" Category and Enable in "Blog" Category? - wordpress

I have a News page that displays all the posts within the "News" Category. This category has sub-categories such as "Merchandise, Music, Events" ect.
I am aiming to remove comments from ALL News/Sub-category posts but only display them with the "Blog" Category posts.
Right now I have my single.php set up so posts with the "Gallery" post_format structure are displayed differently.
Here is the single.php file//
http://pastebin.com/YNf3TxT6
I am wondering what I have to fix in order to get this working...

Edit: For future viewers, here is the updated paste from the conversation below for a single.php that will only show the comments template if the post is in the "Blog" Category: pastebin.com/y9ZtCN5U
Assuming you put your Blog posts on a page separate from your news posts, you should be able to use different templates based on category.
http://codex.wordpress.org/Category_Templates
So, you could make a category-blog.php template file that doesn't include the comments code.
If all of your categories are being listed on the same page, use this instead of the in_category stuff on line 50.
<?php
foreach (get_the_category() as $category) {
if ( $category->name == 'Blog' ) {
comments_template();
}
}
?>
Not 100% sure that will work, but try it out and let me know what happens.

Related

WordPress: display full post AND excerpts on one page

Is there a way my category archive display both full posts and excerpts?
What I want is the first two or three latest posts display as full content posts, and all the others as excerpts with just title and a read more button. These are displayed on one page. I am currently using a category archive, on the twentyfifteen theme.
I know I can set a page to either display full or just excerpts, but not a combination. Is this possible?
Thanks!
You can get these in your wordpress loop on page or post.
<?php
$content = get_content($post->ID); //full content of post
$excerpt = substr($content,0,150); //you can limit charaacter like 150
?>

SEO & WordPress: Changing category links manually

I'm not too sure about SEO on WordPress as I read somewhere (I think) that Google penalises category pages for duplication and was hoping someone could tell me whether or not it's a good idea to cut out the links to the category pages all together?
My permalink structure for my main navigation does not link to the category pages. I have created a page specifically for tutorials like so:
myurl.com/tutorials/tutorial-type
and then on the pages there is an if-statement that gets posts from a specified category for that page.
so myurl.com/tutorials/tutorial-type will get only posts in the tutorial-type category.
What i'm planning is instead of using the:
<?php the_category(', '); ?>
in the typical Posted in: Tutorials format under the title of the post to a quick function that will direct someone to the main page for that category. like so:
function changeCategoryToPage() {
if (in_category( 'tutorial-type' )) { ?>
Tutorial Type
<?php }
}
I would appreciate your feedback and wisdom :)

How to make Wordpress Category menu items display the category as title?

I have been looking for this function everywhere but cannot seem to find a clear way to do it.
I have created a blog with a category-based menu but I was wondering how I could get the menu item to display its category as a title whenever it is clicked. I need this because on my website I have post items which share the same category therefore I need to be able to tell the user of his/her location. Once the user clicks on the post however, it is the first category which will be displayed as a title and this seems to be working with:
$category = get_the_category();
echo $category[0]->cat_name;
The only time that this is a problem is when the posts that share the categories do not have their main category listed first.
I hope that I am making myself clear,
Thanks.
You can look at the category slug in the URL, and get the category by its slug.
$cat = get_category_by_slug( $slug );
echo $cat->name;
http://codex.wordpress.org/Function_Reference/get_category_by_slug

Wordpress - Exclude a category from appearing in menu or sidebar widgets

Is there a simple solution (e.g a plugin) for excluding categories appearing in a menu or sidebar?
I created a category of posts called "videos" which display youtube videos (naturally!!) but then i realized they were displaying in my "recent posts" sidebar, and i was looking for a simple way to exclude them
Any ideas would be greatly appreciated
Thank you!
I found this code in WordPress forum which seems to do exactly what you need:
<?php
function exclude_widget_categories($args)
{
$exclude = "3,6,18"; // The IDs of the excluding categories
$args["exclude"] = $exclude;
return $args;
}
add_filter("widget_categories_args","exclude_widget_categories");
?>
Put the code in functions.php of your theme.
You can use a simple plugin widget instead where you can specify certain categories
http://wordpress.org/extend/plugins/custom-recent-posts-widget

wordpress : how to add categories and tags on pages?

I have generated pages using a custom template by creating a php file in my theme directory
something like :
<?php
*
* Template Name: Contact Page
*/
?>
<html ..... </html>
and then adding a new page on the dashboard selecting this new template
How can i now associate tags and categories to each pages ?
Is creating posts instead of pages the only solution?
Even better is to add to functions.php in your theme folder:
function myplugin_settings() {
// Add tag metabox to page
register_taxonomy_for_object_type('post_tag', 'page');
// Add category metabox to page
register_taxonomy_for_object_type('category', 'page');
}
// Add to the admin_init hook of your theme functions.php file
add_action( 'init', 'myplugin_settings' );
Tried using the accepted answer but for some reason it only shows the Post types and none of the Pages shows in the category page. E.g. /category/entertainment/
To fix that, I have to do this:
// add tag and category support to pages
function tags_categories_support_all() {
register_taxonomy_for_object_type('post_tag', 'page');
register_taxonomy_for_object_type('category', 'page');
}
// ensure all tags and categories are included in queries
function tags_categories_support_query($wp_query) {
if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
if ($wp_query->get('category_name')) $wp_query->set('post_type', 'any');
}
// tag and category hooks
add_action('init', 'tags_categories_support_all');
add_action('pre_get_posts', 'tags_categories_support_query');
Try this:
add_action( 'init', 'wpse34528_add_page_cats' );
function wpse34528_add_page_cats(){
register_taxonomy_for_object_type('post_tag', 'page');
register_taxonomy_for_object_type('category', 'page');
}
Not at all helpful to say 'download plugin' for beginners who are most likely not going to have downloaded wordpress and are therefore not able to install said plugin. Here is some short code for those like me that have been scouring the web for something that actually works on regular pages with regular accounts - ie you're not a developer.
First, make sure you have your pages in your menu set up properly.
YOU DO NOT NEED TO MAKE YOUR PAGES 'Categories' or 'Tags'!
This wouldn't give you actual pages to then go and edit, so if you are wanting to add sliders, text, an intro, or anything for that matter, you wouldn't be able to.
Then go to WP Admin > Pages
Select a page to edit and go to the text editor instead of visual editor (far right hand side tab)
Then past the following short code:
[display-posts category="hair,makeup,reviews,beauty" posts_per_page="10" include_date="true" text-decoration: none date_format="F j, Y" order="DESC" include_excerpt="true" wrapper="div" image_size="large"]
<
(The shortcode collects all the posts that you have assigned certain categories in your blog posts i.e. mine was hair and beauty. So obviously change yours to ones that are appropriate. It then allocates how many posts (mine was 10), the date (in descending order,) with a large image and an excerpt of the post)
this plugin sorted me out :
http://wordpress.org/extend/plugins/add-tags-and-category-to-page/
with the standard instructions :
Upload the plugin files to the /wp-content/plugins/ directory
Activate the plugin through the 'Plugins' menu in WordPress
Use the setting page of the plugin from Settings > Add Tags And Category For Page.

Resources