Forum Replies Created

Viewing 15 replies - 1 through 15 (of 40 total)
  • Thread Starter moymadethis

    (@moymadethis)

    I added what I needed to the web.config and nothin broke so I guess I’m good!

    To eliminate children I changed the depth from 0 to 1, that also worked a treat. I copied all the code from my parent theme functions.php and edited that line. Does the method you’re suggesting allow me to only amend the one line of code instead of copying it all?

    I’ve decided I’m going to look into PHP contact forms. I tried a few plugins but they’re difficult to style. I assume I don’t need to look at WordPress specific forms if I’m building it from scratch. As long as it’s a PHP/AJAX contact from I should be good. Just looking to follow a YouTube tutorial, so any suggestions are welcome! 🙂

    Thread Starter moymadethis

    (@moymadethis)

    Thanks for the replies. Before I go into the previously discussed items I forgot to ask about web.config.

    I’m getting some console errors to do with .woff and .woff2 fonts. I’ve read (here: https://hotcakescommerce.zendesk.com/hc/en-us/articles/210926903-HTTP-404-Not-Found-Error-with-woff-or-woff2-Font-Files) that I need to edit that file. I just wanted to check that it’s fine to edit directly and I don’t have to do anything with my child theme?

    Widgets (sidebar)
    That makes sense, I might just leave remove the sidebar from page.php. I appreciate it mightn’t work on every site but it should be ok here.

    Dropdown menu
    I’d rather just hide/turn off the dropdown all together and stay away from creating a menu in Appearance > Menu. I have child page navigation in the sidebar so they can be accessed by clicking on a main menu link and the child pages links are in a menu in the sidebar.

    The only code in my functions.php for the main navigation is:

    
    function html5blank_nav()
    {
    	wp_nav_menu(
    	array(
    		'theme_location'  => 'header-menu',
    		'menu'            => '',
    		'container'       => 'div',
    		'container_class' => 'menu-{menu slug}-container',
    		'container_id'    => '',
    		'menu_class'      => 'menu',
    		'menu_id'         => '',
    		'echo'            => true,
    		'fallback_cb'     => 'wp_page_menu',
    		'before'          => '',
    		'after'           => '',
    		'link_before'     => '',
    		'link_after'      => '',
    		'items_wrap'      => '<ul>%3$s</ul>',
    		'depth'           => 0,
    		'walker'          => ''
    		)
    	);
    }
    

    Parent Link
    I seem to have the back link working with this:

    
    <?php global $post;
    	if ( $post->post_parent ) { ?>
    		<a class="back-link" href="<?php echo get_permalink( $post->post_parent ); ?>" >
    		<?php echo get_the_title( $post->post_parent ); ?>
    		</a>
    <?php } ?>
    

    Someone made a comment about using global $post to get it to work outside of a loop by with and without work for me just pasting the above code onto a page.

    Thread Starter moymadethis

    (@moymadethis)

    That’s ok. I don’t fully understand but by using the array I set the resolution I need so I won’t worry about it too much. It’s my first WordPress site so I need to get into my head it’s not going to be perfect and with every website I build I’ll understand and find out more. There’s not a single dev who doesn’t look back and their older work and thinks “Why did I do that” / “I can’t believe I did that” and that’s the way it should be as you should always be improving.

    I need to add some contact forms but I think I’ll leave creating one from scratch until my next website, when I can spend a bit more time on it. So I’ll look at plugins for now.

    My website is nearly there and a very large amount of the build it down to your help so thanks a lot! I know I’ve said this before but I have a couple of smaller questions but when I think I can leave this thread alone haha!

    Archives (widgets)
    I’ve noticed these display on every page. Is there a way to only show them on post pages?

    Main menu dropdown
    When child pages are added to a parent page in the main nav, a dropdown (nested list) is created called ‘children’ and the list-item with a dropdown has an additional class of ‘page_item_has_children’. I can’t find anything to do with this in my parent theme functions.php, so I guess it’s the default WordPress behaviour?

    The question is, can you turn off the dropdown via the CMS? Or do you need to write some code in functions.php to turn it off? I’ve created a sub-menu in the sidebar instead so I don’t need it. I created a custom menu in Appearance > Menus and turned off child pages – is that the best way to do it?

    Back (up a level) link
    On child pages I want to add a link to return to the parent page. I thought I could achieve this with the following code but it’s not quite there:

    <a href="'.get_permalink($post->post_parent).'">'.get_the_title($post->post_parent).'</a>

    Can you see what I’m missing? Also I’d need to add a condition so the link isn’t shown if the current page is the parent – otherwise it’ll show on every page wether it’s a child page or a parent, with or without children?

    Thread Starter moymadethis

    (@moymadethis)

    Thanks, I found the media settings!

    The thumbnail sizes seems a bit odd. I found it strange how if I set a lower value in the array it was ignored completely. Yet anything higher than the default 150×150 worked – but only the width? So if I set array(200,200) it would be 200px wide but seemed to honour the aspect ratio of the uploaded image, so set the width to be 200×120?

    Either way, I only need my images one size so that works for me. I take it the small/medium/large generated versions are for responsive designs? I notice if I leave the size as the default there’s only one image size created. But if I set the array to anything higher it generates 4 for different resolutions?

    Thread Starter moymadethis

    (@moymadethis)

    Managed to get the thumbnail placeholder working. People suggested if/else statements but not of them would work. I copied an if/else from a post page of the theme and based it off that and it worked with this:

    
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="h-entry__image-link">
    	<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
    		<?php the_post_thumbnail(array(120,120),array('class' => 'u-featured')); // Declare pixel size you need inside the array ?>
    	<?php else: ?>
    		<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/interface/placeholder-image.png" alt="<?php the_title(); ?>"/>
    	<?php endif; ?>
    </a>
    

    Wordpress didn’t seem to like the else statements we declared, even though they were there we got browser errors like “”PHP Parse error: syntax error, unexpected ‘else’ (T_ELSE)”. Seems to work now though, maybe an issue with using brackets instead of colons.

    Now I just need the image sizes and side menu sorted 🙂

    Thread Starter moymadethis

    (@moymadethis)

    Sounds a bit complicated so maybe I’ll leave that for now, it’s no biggie for me! It was more for future use. It was a bit of a problem when I had custom main nav so I had a few menus set up but now, for ease, I’ve decided to use what WordPress gives to me rather than try and reinvent everything!

    I have a couple of small questions then I’ll leave you be haha! I know I’ve gone a bit off topic but I thought it was better here than polluting the forum with lots of little posts.

    Side navigation
    Just wondering if WordPress can generate sub/child page menu in the sidebar? I know categories/meta/archive etc go in there by default but I can’t see an option for child pages?

    I don’t want a dropdown in the main menu. I couldn’t find a way to stop child pages from showing in the main menu so I needed to create a new menu for the header in Appearance > Menus, adding all the high-level pages but turning off the children – is that the way to do it? Or did I miss something on the page options?

    Thumbnails
    Just wondering if there’s somewhere in the CMS where image thumbnails are set?

    My code looks like this, (120,120) is meant to set the image size but on the page it renders as 150px x 150px?

    
    <?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
    	<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="h-entry__image-link">
    		<?php the_post_thumbnail(array(120,120),array('class' => 'u-featured')); // Declare pixel size you need inside the array ?>
    	</a>
    <?php endif; ?>
    

    However, if I change the value to (608,342) it works. Yet if I change it to (151,151) it renders as 151px x 85px?! But (150,150) renders on the page as 150px x 150px – very odd?

    The only reference I can find in the parent theme functions.php is this:

    
    if (function_exists('add_theme_support'))
    {
        // Add Menu Support
        add_theme_support('menus');
    
        // Add Thumbnail Theme Support
        add_theme_support('post-thumbnails');
        add_image_size('large', 700, '', true); // Large Thumbnail
        add_image_size('medium', 250, '', true); // Medium Thumbnail
        add_image_size('small', 120, '', true); // Small Thumbnail
        add_image_size('custom-size', 700, 200, true); // Custom Thumbnail Size call using the_post_thumbnail('custom-size');
    
        // Enables post and comment RSS feed links to head
        add_theme_support('automatic-feed-links');
    
        // Localisation Support
        load_theme_textdomain('html5blank', get_template_directory() . '/languages');
    }
    

    And it doesn’t mentioned 150 anywhere. Even searching the entire functions.php for ‘150’ there are no results?

    I also want to add a placeholder image if an image isn’t uploaded but I guess that can wait until I have the size sorted!

    Thread Starter moymadethis

    (@moymadethis)

    Great, yeah I tried just copying and pasting the sidebar related code into my functions.php and editing what I needed – adding an additional class to “before_widget” but the class wasn’t added. So I guess I need to give it a new name and adjust the template accordingly.

    Speaking of copy/pasting from the functions.php, my parent them has this handy bit of code for new menus:

    
    function register_html5_menu()
    {
        register_nav_menus(array( // Using array to specify more menus if needed
            'header-menu' => __('Header Menu', 'html5blank'), // Main Navigation
            'sidebar-menu' => __('Sidebar Menu', 'html5blank'), // Sidebar Navigation
            'extra-menu' => __('Extra Menu', 'html5blank') // Extra Navigation if needed (duplicate as many as you need!)
        ));
    }
    

    Editing the names in the parent them works and they’re updated in the CMS …but obviously I don’t want to be doing that 😉

    I copied this code into my child theme and tried to amend it but I got a PHP Fatal error: Cannot redeclare register_html5_menu().

    So I guess I need to give this a new name to be able to edit/add menus. The only thing is I couldn’t find where to change the call – any ideas? As this is CMS based maybe it’s something I shouldn’t be touching?

    Thread Starter moymadethis

    (@moymadethis)

    Thanks, I added the wp-reset_postdata() like this:

    
    <?php if (have_posts()): while (have_posts()) : the_post(); ?>
    			
    <?php get_template_part('loop'); ?>
    
    <?php endwhile; ?>
    <?php else: ?>
    	<!-- article -->
    	<article>
    		<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
    	</article>
    	<!-- /article -->
    <?php endif; ?>
    
    <?php wp_reset_postdata(); ?>
    
    <?php get_template_part('pagination'); ?>
    

    I couldn’t wrap it in PHP tags on the front-page as the entire block of code is already wrapped in PHP tags. I assume that’s ok? I just included it right before the closing PHP tag.

    Yeah sorry I should’ve said. I didn’t intend on editing the parent theme functions.php. I was going to copy/paste the entire block into my child theme functions.php file and edit what I need. Then give it a new name and up it in the relevant templates – which are also duplicated and placed in my child theme folder 🙂

    Thread Starter moymadethis

    (@moymadethis)

    Great, I managed to add wp_reset_postdata(); like in the (2nd) example I gave above.

    However, I found it a bit difficult on pages where the code appears like this:

    
    <?php if (have_posts()): while (have_posts()) : the_post(); ?>
    
    <?php get_template_part('loop'); ?>
    
    <?php endwhile; ?>
    <?php else: ?>
    	<!-- article -->
    	<article>
    		<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
    	</article>
    	<!-- /article -->
    <?php endif; ?>
    
    <?php get_template_part('pagination'); ?>
    

    Does that mean I need to include the code like <?php wp_reset_postdata(); ?> but just after <?php get_template_part('loop'); ?>? Or is there a better place to put it?

    I noticed my parent theme had the following code in it’s functions.php:

    
    if (function_exists('register_sidebar'))
    {
        // Define Sidebar Widget Area 1
        register_sidebar(array(
            'name' => __('Widget Area 1', 'html5blank'),
            'description' => __('Description for this widget-area...', 'html5blank'),
            'id' => 'widget-area-1',
            'before_widget' => '<div id="%1$s" class="%2$s">',
            'after_widget' => '</div>',
            'before_title' => '<h3>',
            'after_title' => '</h3>'
        ));
    
        // Define Sidebar Widget Area 2
        register_sidebar(array(
            'name' => __('Widget Area 2', 'html5blank'),
            'description' => __('Description for this widget-area...', 'html5blank'),
            'id' => 'widget-area-2',
            'before_widget' => '<div id="%1$s" class="%2$s">',
            'after_widget' => '</div>',
            'before_title' => '<h3>',
            'after_title' => '</h3>'
        ));
    }
    

    I thought about amending the before_widget bit to read:

    
    'before_widget' => '<div id="%1$s" class="%2$s side-nav">',
    

    Which seemed to add the class ok, I just wanted to check that will just target the navigation/category lists before proceeding?

    Thanks again! 🙂

    Thread Starter moymadethis

    (@moymadethis)

    Great!

    No the pagination wouldn’t go on the homepage, just on the Post and Custom Post index pages. Thankfully I added 10+ Posts to both and the pagination automatically appeared when I included <?php get_template_part('pagination'); ?> on both pages!

    To reset everything, do you mean put wp_reset_postdata() before the closing PHP tag? So…

    
    <!-- article -->
    <article id="post-<?php the_ID(); ?>" <?php post_class('h-entry'); ?>>
    
    	<!-- post thumbnail -->
    	<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
    		<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="h-entry__image-link">
    			<?php the_post_thumbnail(array(120,120),array('class' => 'your-class-name')); // Declare pixel size you need inside the array ?>
    		</a>
    	<?php endif; ?>
    	<!-- /post thumbnail -->
    
    	<!-- post title -->
    	<h2 class="p-name">
    		<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    	</h2>
    	<!-- /post title -->
    
    	<!-- post details -->
    	<time datetime="<?php the_time('Y-m-j'); ?>" class="dt-published"><?php the_time('jS F Y'); ?></time>
    	<!-- /post details -->
    
    	<?php html5wp_summary('html5wp_index'); // Build your custom callback length in functions.php ?>
    	
    	<p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="arrow-link">Read the full article</a></p>
    
    	<?php edit_post_link(); ?>
    	
    	 <!--  Restore original Post Data -->
    	wp_reset_postdata();
    
    </article>
    

    Or do you mean on the page the loop is pulled into like…

    
    <div class="h-feed featured-projects">
    	<?php
    	    $args = array(
    		    'posts_per_page'    => 3,
    		    'post_type'     => 'html5-blank',  //choose post type here
    		    'order' => 'DESC',
    		);
    		// query
    		$the_query = new WP_Query( $args );
    		
    		
    		if( $the_query->have_posts() ):
    		    while( $the_query->have_posts() ) : $the_query->the_post();
    		        get_template_part('loop-html5-blank');
    		    endwhile; 
    		else :
    		
    		endif;
    		
    		<!--  Restore original Post Data -->
    		wp_reset_postdata();
    
    	?>
    </div>
    

    Thanks for all the help, made real progress. All I need to do now is find out how I can add a generic class to the UL elements in the sidebar so I can style them. Worried targeting .widget > ul might style lists in other widgets that aren’t categories/sub-pages/archives etc.

    Thread Starter moymadethis

    (@moymadethis)

    Ok, this is the solution I’ve ended up using. It seems to work but I’d appreciate any pointing out flaws if they see any…

    I amended my loop.php so the wrapping if/else statement was removed. This left loop.php looking like this:

    
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
        <!-- post thumbnail -->
        <?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="h-entry__image-link">
                <?php the_post_thumbnail(array(120,120)); // Declare pixel size you need inside the array ?>
            </a>
        <?php endif; ?>
        <!-- /post thumbnail -->
    
        <!-- post title -->
        <h2 class="p-name">
            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
        </h2>
        <!-- /post title -->
    
        <!-- post details -->
        <time datetime="<?php the_time('Y-m-j'); ?>" class="dt-published"><?php the_time('jS F Y'); ?></time>
        <!-- /post details -->
    
        <?php html5wp_summary('html5wp_index'); // Build your custom callback length in functions.php ?>
    
        <p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="arrow-link">Read the full article</a></p>
    
        <?php edit_post_link(); ?>
    
    </article>
    

    The part this was removed was this:

    
    <?php if (have_posts()): while (have_posts()) : the_post(); ?>
    
       [ARTICLE CODE WAS IN HERE]
    
    <?php endwhile; ?>
    
    <?php else: ?>
    
        <!-- article -->
        <article>
            <h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
        </article>
        <!-- /article -->
    
    <?php endif; ?>
    

    This allowed me to use the following code on the homepage to pull in the latest 3 posts:

    
    <div class="h-feed featured-blog">
    	<?php
    	    $args = array(
    		    'posts_per_page'    => 3,
    		    'post_type'     => 'post',  //choose post type here
    		    'order' => 'DESC',
    		);
    		// query
    		$the_query = new WP_Query( $args );
    		
    		
    		if( $the_query->have_posts() ):
    		    while( $the_query->have_posts() ) : $the_query->the_post();
    		        get_template_part('loop');
    		    endwhile; 
    		else :
    		
    		endif;
    	?>
    </div>
    

    This gets the posts working on the homepage (front-page.php) great. I had to wrap the code in the parent div markup. This mightn’t be ideal on other sites but it actually works quite well for me here as I need to be able to add different classes on the blog/home page.

    The big issue with this was that only 1 post was displayed on the blog page as the code loading it looked like this:

    
    <?php get_template_part('loop'); ?>
    

    I amended this by wrapping the if/else statement around the get_template_part so it now looks like this:

    
    <?php if (have_posts()): while (have_posts()) : the_post(); ?>
    
    <?php get_template_part('loop'); ?>
    
    <?php endwhile; ?>
    
    <?php else: ?>
    
    	<!-- article -->
    	<article>
    		<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
    	</article>
    	
    	<!-- /article -->
    	
    <?php endif; ?>
    
    <?php get_template_part('pagination'); ?>
    

    That all seems to work. I was even able to use the same code for my Custom Post Type changing 'post_type' => 'post' to 'post_type' => 'custom-post-name' to pull those posts onto the homepage.

    I’ve not checked if the pagination still works and what happens when 10+ posts are on the page but can anyone see any problems with what I’ve done?

    Thanks again for all your help and time giving me information on this. I still don’t fully understand but at least we’re getting there haha!

    Thread Starter moymadethis

    (@moymadethis)

    Using the code I pasted:

    
    <?php
        $latest_blog_posts = new WP_Query( array( 'posts_per_page' => 3 ) );
        if ( $latest_blog_posts->have_posts() ) : while ( $latest_blog_posts->have_posts() ) : $latest_blog_posts->the_post();
    
            get_template_part('loop');
    
        endwhile; endif;
    ?>
    

    It does display 3 posts on front-page.php but all 3 posts are called “Home”, have the same date and all link to the Homepage. I guess this is because it’s a query, within a query. Is there a way to adjust my loop.php so this works using the code above or something similar?

    The only way I managed to get the 3 latest posts to display on the homepage was to copy and paste the code from loop.php onto front-page.php. That worked …but I guess it’s not ideal to maintaining two lots of code in different locations that essentially do the same thing/are the same thing?

    Unless this is the only way it can be achieved?

    Thread Starter moymadethis

    (@moymadethis)

    Noooo! This is why I’ve always had back-end dev’s around to do this haha!

    Can I use wp_reset_query(); to reset the WordPress query after looping through the custom query so it reverts back to the default query for the current page? I friend told me to use that but I couldn’t get it to work. Is that due to how my loop.php is set up?

    There has to be an easier/better way than just duplicating the code from loop.php onto the homepage, right? Though I am tempted to do that just to get it done haha!

    Thread Starter moymadethis

    (@moymadethis)

    I figured out I could just duplicate loop.php, rename it to loop-custom.php (for example), change what I needed and then load it on my Custom Post page with <?php get_template_part('loop-custom'); ?>. Didn’t realise get_template_part would pull in a php file of that name …see, that’s how much of a noob I am!

    If I paste <?php get_template_part('loop'); ?> onto the homepage it will load all the posts onto that page as it would the blog page, minus pagination, correct?

    Is there away of wrapping that snippet of code in a condition to only show the latest 3 posts? Rater than pasting the contents of loop.php onto the homepage? Figured maybe it’s not a good idea to maintain 2 identical loops over 2 pages?

    EDIT

    Sorry, I forgot that the homepage was the main query like you said. So I need to look at another approach. Am I on the right track with something like:

    
    <?php
        $latest_blog_posts = new WP_Query( array( 'posts_per_page' => 3 ) );
        if ( $latest_blog_posts->have_posts() ) : while ( $latest_blog_posts->have_posts() ) : $latest_blog_posts->the_post();
    
            get_template_part('loop');
    
        endwhile; endif;
    ?>
    

    Though this just spits out 3 posts with the heading “Home” for now!

    • This reply was modified 9 years, 2 months ago by moymadethis.
    • This reply was modified 9 years, 2 months ago by moymadethis.
    Thread Starter moymadethis

    (@moymadethis)

    Is that covered in the code provided by @poonam9?

    I think this might be a little too advanced for me, so maybe I’m getting ahead of myself a little!

    I get what you’re saying about the custom post types. If I create a Custom Post and ‘view’ it. I can see part of the URL is /html5-blank/. So I created a page called “Case Studies” and edited the URL to match that and it seems to work. Is that the way you meant me to do it?

    Do Custom Post Types use the same loop as the default post type? If so, I guess I’ll need to duplicate that php file and set the Custom Post Type to use that instead?

Viewing 15 replies - 1 through 15 (of 40 total)