How Can i Remove all sidebars from specific wordpress pages? - php

hi everyone im trying to remove all of the sidebars from a specific video page im creating on a wordpress site ive found tutorials on google on how to do this if the sidebars are called to the page using the
<?php get_sidebar(); ?>
method however my theme uses following method to call sidebars to a page
<?php include(TEMPLATEPATH."/sidebar.php");?>
i cant find any good methods for removing the sidebars that calls them to a page the same way as my theme does. here is the code to my page.php file on my website any help understanding how to remove them would be greatly appreciated =)
<?php get_header(); ?>
<div id="breadcrumb"><?php breadcrumbs(); ?></div>
<?php include(TEMPLATEPATH."/sidebar.php");?>
<div id="kontenutama">
<div class="postingan">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="bookmark">
<?php the_title(); ?></a></h2><?php the_content(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<br style="clear:both;">
</div>
</div>
<?php include(TEMPLATEPATH."/r_sidebar.php");?>
<br style="clear:both"><div style="clear:both">
</div>
<?php get_footer()?>

Why not create a new WordPress page template and remove the sidebar include on that page?
The theme is pretty dodgy, it shouldn't ever include files like that in template pages.

Related

Wordpress WP-PageNavi Not working with specific category post on homepage

I'm using the following code to display recent posts from a specific category on the homepage of my WordPress website.
<div class="frontleft">
<div id="four-columns" class="grid-container" style="display:block;">
<?php $catquery = new WP_Query( 'cat=3&posts_per_page=24' ); ?>
<ul class="rig columns-4">
<?php while($catquery->have_posts()) : $catquery->the_post(); ?>
<li>
<a href="<?php the_permalink() ?>">
<?php the_post_thumbnail( 'single-post-thumbnail' ); ?>
</a>
<h3>
<?php the_title(); ?>
</h3>
</li>
<?php endwhile; ?>
</ul>
</div>
<div class="navigation">
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
<?php } ?>
</div>
</div>
Issue: WP-pageNavi plugin isn't working correctly.
Note: I'm able to open website.com/page/2 without having any issues. But the post list is precisely the same on each page.
How to fix it?
If I were you I would just use different Page Templates for homepage and other pages.
It's hard to debug a plugin that we aren't using.
There is a function in Wordpress is_page() where you can input the name of the page in the para. Throwing that in an if statement is also another way to separate the posts.
There are a ton of ways to achieve what your looking for without the use of a plugin.

Blog Posts Wordpress Customizing

I am creating my own custom theme from scratch and have run into a bit of trouble. On the blog page, each time a new post is displayed, it is smaller than the last. This is due to me setting the width of the blog post to 33.3%. Also each blogpost gets displayed slightly right of the one previous to it. How can I have each blog post be 33.3% of the content area and be displayed side by side, 3 per row? I am using wordpress functions to call each blog post. I am only displaying the blog posts thumbnail and when you click the thumbnail it takes you to the post. So basically 3 images side by side.
[BONUS]: How could I get text to display horizontally and vertically on hover over each blog post image?
I know this is a lot to ask, but I have been trying to work this out for days. A JS Fiddle or Codepen would be greatly appreciated.
Index.php:
<?php get_header(); ?>
<div class="blog-posts">
<?php while (have_posts()) : the_post(); ?>
<div id="page-content">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
<h3><?php the_title(); ?></h3>
</a>
<?php endwhile; ?>
</div>
</div>
<?php get_footer(); ?>
You should use bootstrap and do something like this :
<?php get_header(); ?>
<div class="blog-posts">
<?php while (have_posts()) : the_post(); ?>
<div class="col-md-4">
<div id="page-content">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
<h3><?php the_title(); ?></h3>
</a>
</div>
</div>
<?php endwhile; ?>
</div>
<?php get_footer(); ?>
Take care to remove the width: 33.33%; CSS rule and close your <div> tags in the loop, not after.
Hope it helps
[EDIT]
See this link for more information about how to use column classes with bootstrap : grid example basic
[EDIT #2]
You could do it without bootstrap but it will be a bit more difficult. You'll have to set the "display" to "inline-block" and set the width of the divs with taking care of the inherit margin of these tags. In this example, I had to set it to 32%. Here is the fiddle

How to include comments under posts in a clean build template?

I am new to wordpress theme development and currently building building my first one from scratch, I have hit an issue with adding comments with blog posts.
I have the loop the that returns each post:
<div class="eachPost">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php the_title_attribute(); ?>"><?php
the_title();?></a></h2>
<p class="entry-meta">by <?php the_author_meta('first_name'); ?>
<?php the_author_meta('last_name'); ?> in <?php the_category(", ")
?></p>
<p class='right'><a class='comments-count' href='<?php the_permalink() ?>'><?php comments_number('0', '1', '%')
?></a></p>
<?php comments_template(); ?>
</article>
<h4>Posted on <?php the_time('F jS, Y') ?></h4>
<p><?php the_content(__('(more...)')); ?></p>
<hr> <?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p><?php endif; ?>
</div>
I believe that I need to call the function:
<?php comments_template(); ?>
but adding this to the code has no effect.
I have comments.php and comment-template.php in the same folder as the file and believe that I need to include these in the page as follows
<?php get_template_part('comments.php'); ?>
<?php get_template_part('comments_template.php'); ?>
Using in config
<?php define('WP_DEBUG', true);?>
<?php define('WP_DEBUG_LOG', true);?>
<?php define('WP_DEBUG_DISPLAY', true);?>
Create no error in logs or info.
In a clean build template how do you include comments under posts?
The comments.php needs to be inside the Template root folder, please take a look at the Wordpress Codex http://codex.wordpress.org/Function_Reference/comments_template
If you want to have it somewhere else, here's the Wordpress recommendation:
The path to the file used for an alternative comments template should
be relative to the current theme root directory, and include any
subfolders. So if the custom comments template is in a folder inside
the theme, it may look like this when called:
<?php comments_template( '/custom-templates/alternative-comments.php' ); ?>
You see no errors because there's no mistake there. The system is calling a function that should load a file that if it doesn't exist, no error is thrown.

Switching between posts in wordpress

I have created a sidebar.php-file with the code;
<section class="sidomeny"><p class="Senastenytt2"><?php get_search_form();?></p></section><!--Slut på sidomeny-->
<div id="nyhet3">
<?php
query_posts('category = all');
if (have_posts()) :
while (have_posts()) : ?>
<?php the_post(); ?>
<p class="datum2"><?php the_time('Y-m-d'); ?></p>
<p class="Nyhetsrubrik3"><a style="orange"; href="<?php the_permalink() ?>" ><?php the_title(); ?></a></p>
<?php the_excerpt(); ?>
<p class="textnyhet2"></p>
<?php
endwhile;
endif;
?>
</div><!--Slut på Nyhet3-->
And now I would like to add the function that if you press the sidebar news section, the "textnyhet2" section will get updated with the news you clicked on. That is how it's working now.
But the problem is that the sidebar vanished whenever you click on one of those "latest news" links. So what I need help with is to edit the sidebar.php-file so the "latest news" function with links is still there so you don't have to go back one page whenever you would like to read about another post.
Im not sure how to do this. If it's php involved or if you can do it by simple visiting the posts/pages section in wordpress.
Would be grateful if anyone could help me. If I have forgotten any necassary information please tell me and I will the post.
Thanks!
<?php
get_header();
?>
<section class="textinnehall">
<?php
if (have_posts()) :
while (have_posts()) :
the_post();
the_content();
endwhile;
endif;?>
</section>
<section class="sidomeny">
<?php
get_sidebar(); ?>
</section>
<?php
get_footer();
?>
This is my page.php file. Don't know if it will be to any help. But the sidebar is already active.
May be the sidebar is not called in your single page.
you need to have the same design in your themes single.php page(As per twenty ten theme standard).
<p class="Nyhetsrubrik3"><a style="orange"; href="<?php the_permalink() ?>" ><?php the_title(); ?></a></p>
The href <?php the_permalink() ?> takes the post to single page for full view
Just call the sidebar in your theme's single page.

Showing Wordpress posts on two pages

I have three pages on my site. Let's call them home, page2, and page3.
My 'home' page is set as a static front page. My 'page2' is set up as the blog page.
What I want is the following:
I want page2 to display blog posts with a certain category (of which ID is known).
AND
I want page3 to display blog posts with a certain category (of which ID is known).
The PHP code to only show posts with a certain category (or actually in my case, show posts excluding two categories) is the following:
<?php query_posts($query_string . '&cat=-3,-8'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h3><a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a></h3>
<?php the_excerpt('Read the rest of this entry »'); ?>
</div><!-- /.post-->
Now, in my page.php, I have the following code to display posts with one category:
<?php
// BEGIN IF PAGE is newspaper articles page
if ( is_page('newspaper') ) {
//BEGIN POST REGION
query_posts($query_string . '&cat=8'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h3><?php the_title(); ?></h3>
<?php the_content('Read more »'); ?>
</div><!-- /.post-->
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
<?php
} //end if is_page
?>
But it doesn't show the proper posts on the newspaper page (or page3 in this question). It does, however, work for the articles page (main index.php blog page).
EDIT: I've also tried the following (but it doesn't work). I put this in the index.php file:
<?php
if ( is_page('newspaper') || is_home() ) { // START if is home
?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h3><a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to
<?php the_title_attribute(); ?>">
<?php the_title(); ?></a></h3>
<!--<p><?php the_time('F jS, Y') ?> <?php //the_author() ?></p>-->
<?php the_excerpt('Read the rest of this entry »'); ?>
</div><!-- /.post-->
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
<?php
} //end if is_home() or is_page()
?>
Again, this shows the posts on the main blog page, but doesn't show any posts on the newspaper page...
The question is therefore simple (I think). How do I show posts on another page OTHER than the main blog page?
Thanks!
Amit
Rather than exclude categories and exclude pages and change the standard Wordpress loop, use a new query, like this:
<?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h3><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a></h3>
<?php the_excerpt('Read the rest of this entry »'); ?>
<?php endwhile; ?>
This can be used inside the standard WP loop and be used mutiple times in a page/post or page template without conflicting. (Enable php execution to use it in the page/post editor). Function Reference/WP Query « WordPress Codex
This also works well to use page templates to create different pages with blog posts: Page Templates « WordPress Codex, but don't forget that WP also uses category pages, too, depending on your theme: Category Templates « WordPress Codex.
I think you have to make different templates for different page. Check this link http://codex.wordpress.org/Pages
I think this thread answers the question and does what you want.
http://wordpress.org/support/topic/show-only-x-category-posts-on-page?replies=9#post-1053767
Using the string 'newspaper' in is_page('newspaper') is a potential source of the problem. It might be misspelled easily.
Have you ever tried using the page id? Something like
is_page('999')

Categories