Use different page template if ative content In Sidebar - php

Im using the UnderScore theme and below is the main page.php template file. What im aiming for is if there is active widgets in the sidebar use template with sidebar but if no active widgets or content use template that has the main content as 960px with no sidebar. Im also using ACF (advance custom fields) is the sidebar so would need to check that aswell. Gratefull for any help. I thought maybe using "is_active_sidebar" but unsure how to implerment it properly as template parts are already being check.
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop.
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_sidebar();
get_footer();
Also below the sidebar.php
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
return;
}
?>
<aside id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
<?php the_field('sidebar_info'); ?>
</aside><!-- #secondary -->

Maybe I'm not fully understanding you question, but you can use a simple if-statement for that. See pseudo code below.
if ( active widgets in the sidebar ) {
// use this formatting
} else {
// use that formatting
}

Related

Home Page Full Width No Side Bar

I am experimenting with a new design for my front page - http://www.rosstheexplorer.com/front-page-test/
I have set it so Google does not Index this page.
I set the template to Full Width, No Sidebar, this resulted in the plugins being hid but the text and pictures still do not cover the whole page. How can I address this?
This is my code for fullwidth-page.php
<?php
/**
* Template Name: Full Width, No Sidebar
*
* #package Penscratch
*/
// Access global variable directly to set content_width
if ( is_active_sidebar( 'sidebar-1' ) && isset( $GLOBALS['content_width'] ) )
$GLOBALS['content_width'] = 1091;
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php // If comments are open or we have at least one comment, load up the comment template
if ( comments_open() || '0' != get_comments_number() ) : comments_template();
endif; ?>
<?php endwhile; // end of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_footer(); ?>
To make it easier for you, you can change this line :
<div id="primary" class="content-area">
to this line :
<div id="primary" class="content-area" style="width: 100%;">

get_footer not showing for Wordpress site

For some reason my footer disappeared for my site http://juliannaspizza.com.
I checked the template file for the home page and get_footer is being called as shown below. Any idea why my footer is still not showing up?
<?php
/**
* Template Name: Full Width Page
*
* #package Fortune
*/
get_header();
get_template_part( 'parts/single', 'page-header' ); ?>
<div class="container full-width-page">
<div class="row">
<div id="primary" class="content-area col-lg-12">
<main id="main" class="site-main" role="main">
<?php
while ( have_posts() ) : the_post();
get_template_part( 'content', 'page' );
if ( comments_open() || get_comments_number() ) {
comments_template();
}
endwhile; ?>
</main><!-- #main -->
</div><!-- #primary -->
</div><!-- .row -->
</div><!-- .container -->
<?php
get_footer();
This is what my footer used to look like (https://certifagift.blog/):
Your widgets are gone. From the markup, it looks like your footer (which does appear) is expecting to have widgets, but those are not appearing. Go to Appearance -> Widgets in your dashboard and add your widgets back in, and you should be good.

Wordpress beginner - style.css doesn't affect page.php

Im a beginner in wordpress and while i was learning how to make themes I had a problem.
I use this code in my functions.php to add the css:
function learning() {
wp_enqueue_style('style', get_stylesheet_uri());
}
It works well for my index.php so i designed my default page as how I want. I wanted to change the look of my pages which I created in the WordPress GUI, so I created page-(otherpage).php file in my theme folder and copied the code etc, and gave different classes to the elements in page-(otherpage).php. Finally I made some changes in my style.css for my new classes but it doesn't change anything.
What should i do?
Attach a css file via function.php add following code into functions.php.
(Recommaded don't use function.php because its theme specific)
<?php
function mypage_head() {
echo '<link rel="stylesheet" type="text/css" href="'.get_bloginfo('stylesheet_directory').'/includes/mypage.css">'."\n";
}
add_action('wp_head', 'mypage_head');
?>
method use for add header into a template
<?php get_header(); ?>
Created Template Page here :
<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Start the loop.
while ( have_posts() ) : the_post();
// Include the page content template.
get_template_part( 'template-parts/content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) {
comments_template();
}
// End of the loop.
endwhile;
?>
</main><!-- .site-main -->
<?php get_sidebar( 'content-bottom' ); ?>
</div><!-- .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Make a Blog Template page on underscore.me with wordpress

i am trying to personalize a new theme made in underscore.me, but i can't seem to create a new template page with a loop that can show me posts of one specific category, how can i do this?
I'm gonna paste here the index.php of the underscore.me theme, witch has a generic loop, sadly, copying and pasting this loop on a template page does
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<?php if ( is_home() && ! is_front_page() ) : ?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
</header>
<?php endif; ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'template-parts/content', get_post_format() );
?>
<?php endwhile; ?>
<?php the_posts_navigation(); ?>
<?php else : ?>
<?php get_template_part( 'template-parts/content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
And this is the page.php.
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'template-parts/content', 'page' ); ?>
<?php
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
<?php endwhile; // End of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
Good news for you, you dont need a specific loop for a specific category.
if you have a category.php file in your theme, and assume that your category name is "Lux Cars" with id of "35". if you copy your category.php as category-35.php or category-lux-cars.php (slug of your category). When you open the posts with this category. wordpress call this file and show posts in that loop. you can edit your category-35.php and add any category detail or sth.
But if you still want a loop for a specific category then you can use that code;
<?php
$args = array ( 'category' => ID, 'posts_per_page' => 5);
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post);
?>
//Style Posts here
<?php endforeach; ?>

Underscores Wordpress Theme - Adding second sidebar

Stared a Wordpress site using Underscores theme (_s)
I have got one sidebar working but want to make a second one to be on the same page. (containing different widgets)
I have added the new sidebar to the functions.php and it appears in the Wordpress login screen and i can drop widgets into it. However, I can't get it to show on the actual webpage. (the first sidebar is working fine)
Anyone know how to do this or know a tutorial...
Thanks
You'll need to edit the "sidebar.php" file in your theme folder. It should normally be:
<div id="secondary" class="widget-area" role="complementary">
<?php do_action( 'before_sidebar' ); ?>
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<?php endif; // end sidebar-1 widget area ?>
</div><!-- #secondary -->
You will need to add another if statement that looks out for the other sidebar. Be sure to reference it by whatever you used in the functions.php file.
If you want it to appear below the current sidebar, just be sure to add it before closing the 'div' so it will still be in the same column. I used 'sidebar-lower':
<div id="secondary" class="widget-area" role="complementary">
<?php do_action( 'before_sidebar' ); ?>
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<?php endif; // end sidebar-1 widget area ?>
<?php if ( ! dynamic_sidebar( 'sidebar-lower' ) ) : ?>
<?php endif; // end sidebar-lower widget area ?>
</div><!-- #secondary -->

Categories