WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Theme Overriding Help (13 posts)

  1. TheDillDesign
    Member
    Posted 12 months ago #

    Fairly new to WordPress, I am recently coming over from Drupal. I am having a trouble overriding my theme for one simple function, maybe someone can help! I am using a custom theme Five3.me, and I have made a child theme out of that that I have been editing. I have not modified any source theme files.

    What I am trying to do, is create custom fields on "Posts", so include a name and picture. this is pretty standard stuff.

    First, I copied single.php into my theme directory, and changed the code to:

    get_header(); ?>
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    <?php get_template_part( 'custom-content', 'single' ); ?>
    <nav id="single">
    <span class="nav-previous"><?php previous_post_link( '%link', __( '← Previous', 'five3' ) ); ?></span>
    <span class="nav-next"><?php next_post_link( '%link', __( 'Next →', 'five3' ) ); ?></span>
    </nav><!-- #single -->
    <?php comments_template( '', true ); ?>
    <?php endwhile; // end of the loop. ?>
    <?php get_footer(); ?>

    As you can see I only changed get_template_part( 'content', to get_template_part( 'custom-content',.

    I then copied content.php and renamed it custom-content.php. I add this bit into the body:

    <?php
    $membername = get_post_meta( $post->ID, 'membername', true );
    echo '<div class="memberdiv">';
    foreach( $membername as $member){
    echo '<h3>' . $member['name'] . '</h3>';
    echo '<img src="' . $member['member-picture'] . '" class="mem-pic" />';
    echo '</div>';
    }?>

    This works, if I go to any post, I see my custom tags. But I also have a page, with a slug god-stories. This is set as my summary post page inside of reading settings.

    Now I am trying to get the same meta to show up on this post reel page. What I did was make a custom template for the page with this code:

    <?php
    /**
     * Template Name: Custom Page Template
     *
     *
    */
    get_header(); ?>
    	<?php the_post(); ?>
    	<?php get_template_part( 'custom-content', 'page' ); ?>
    	<?php comments_template( '', true ); ?>
    <?php get_footer(); ?>

    I open up the god-stories page and I select "Custom Page Template" and save it, and nothing happens. Through troubleshooting, I find that this page is still using content.php from the parent theme directory. If I change the main theme my changed show up... but then they are applied to all pages, which doesn't work.

    First, what am I doing wrong? Second, is there a better way for me to get custom fields to show up not only on every post but also on one page in my child theme? I tried if statements but unfortunately my PHP is not that strong.

  2. TheDillDesign
    Member
    Posted 12 months ago #

    If you would like to see the code the page is http://wordpress.christianlife.org/god-stories and posts are after that, the one test post is at /icu-healing

  3. alchymyth
    The Sweeper & Moderator
    Posted 12 months ago #

    But I also have a page, with a slug god-stories. This is set as my summary post page inside of reading settings.

    the 'posts page' does not use a page template, it always uses index.php or home.php

    http://codex.wordpress.org/Creating_a_Static_Front_Page
    http://codex.wordpress.org/Template_Hierarchy

    you might need to use a conditional statement to restricht your new code to the posts page;
    is_home() http://codex.wordpress.org/Function_Reference/is_home

  4. TheDillDesign
    Member
    Posted 12 months ago #

    Man thanks a bunch! I made a child index.php and put my code in there, and it started working. I have a different post type from a sermon module, which was throwing up error- so I put an is_home in and everything is working.

    One more small problem, maybe you can help out. I created a custom field called Picture, which is of the type upload. When I upload a picture (or select it from library), it completes successfully and shows up in the admin portal. But when I visit the page, the picture is in error... this is what is actually being inserted:

    <img src="710" class="mem-pic">

    My loop uses the code:

    echo '<img src="' . $member['member-picture'] . '" class="mem-pic" />';

    Its like when I upload it it does not pull the full path of the link into the ending page display. Any hints?

  5. alchymyth
    The Sweeper & Moderator
    Posted 12 months ago #

    My loop uses the code:

    echo '<img src="' . $member['member-picture'] . '" class="mem-pic" />';

    what is the full code of the loop?

    possibly related: the ID of a page set as posts page would be get_option( 'page_for_posts' ) ...

    possibly replace this line of your earlier posted code:

    $membername = get_post_meta( $post->ID, 'membername', true );

    with:

    $page_ID = get_option( 'page_for_posts' ) ? get_option( 'page_for_posts' ) : $post->ID;
    $membername = get_post_meta( $page_ID, 'membername', true );
  6. TheDillDesign
    Member
    Posted 12 months ago #

    Here is the full code:

    <?php if ( is_home() ) :?> <!-- This is to designate the custom fields only on god-stories slug -->
    <?php
    $membername = get_post_meta( $post->ID, 'membername', true );
    echo '<div class="memberdiv">';
    foreach( $membername as $member){
    echo '<h3>' . $member['name'] . '</h3>';
    echo '<img src="' . $member['member-picture'] . '" class="mem-pic" />';
    }?>
    <?php endif; ?> <!-- End of loop for God Story title/picture -->

    With your code it gives me a foreach error. on line 54 which is
    foreach( $membername as $member){

  7. TheDillDesign
    Member
    Posted 12 months ago #

    You can see the broken picture link now at http://clpress.christianlife.org/god-stories/

  8. alchymyth
    The Sweeper & Moderator
    Posted 11 months ago #

    this is the line with the broken image:

    <div class="memberdiv"><h3>Will Radford</h3><img src="710" class="mem-pic" />

    could it be that the ['member-picture'] field is containing a attachment ID ??

    what exactly is inserted into your custom field?

  9. TheDillDesign
    Member
    Posted 11 months ago #

    Lets see:

    I use a plugin called: Types - Complete Solution for Custom Fields and Types (http://wordpress.org/plugins/types/)

    All this does is insert the PHP necessary to support these types:

    CUSTOM FIELDS
    Types includes support for a wide list of custom fields.

    Single-line text
    Multi-line text
    WYSIWYG (WordPress Visual Editor)
    Checkbox
    Multi-value Checkboxes
    Radio group
    Drop-down Select
    File upload
    Image (Types includes a robust image-resize and caching engine)
    Date (includes a JS date-picker)
    Email
    Numeric
    Phone
    Skype
    URL
    Post reference (using Types Parent / Child relationships management)

    In the module, I create a Meta Box with the following characteristics:

    Meta name: membername
    Post Type: post
    Repeater: true
    Sortable: true
    Post ID:
    Page Template:

    I then create two fields:

    Field Title: Member Picture
    Slug:member-picture (Note:changing the slug when you already have a lot of existing entries may result in unexpected behavior.)
    Field Type: upload
    Description: The member picture for the post.
    Required: false
    Default Value:
    Attach upload to post: No (I tried both no and yes)

    Then I use the above code that we have been discussing, and neither the yes or no image option works.

    Perhaps its the module? Do you have another module you might recommend that could help with this? I only want to be able to display fields for name and picture on each story so my client does not have to position things in the WYSIWYG.

  10. alchymyth
    The Sweeper & Moderator
    Posted 11 months ago #

    possibly ask at the plugin's support section http://wordpress.org/support/plugin/types

  11. TheDillDesign
    Member
    Posted 11 months ago #

    Yeah I am investigating other modules now, as apparently this ones not working well.

  12. TheDillDesign
    Member
    Posted 11 months ago #

    I actually named the wrong module in the prior posts, I was using WCK. I am asking in the support forum there, will link for reference. Thanks for all of the help!

    http://wordpress.org/support/topic/upload-field-is-using-attachment-id

  13. TheDillDesign
    Member
    Posted 11 months ago #

    Ok, I got this up and running, thank you for the help. Can you perhaps continue with this same project and help me to link to the post dynamically with a custom field meta data? What I have is a meta for Post Title, which is filled in by the user. How do I make that link back to the full post?

    Here is my attempt at it, but WordPress puts the literal link into the address bar and does not execute the PHP.

    <?php
    		if ( is_home() || is_single() ):?>
    			<?php $members = get_post_meta( $post->ID, 'memberinfo', true );
    					echo '<div class="memberdiv">';
    				foreach( $members as $member){
    					echo '<h2><a href="<?php echo get_permalink(ID); ?>" rel="bookmark" class="god-story-title" title="Permanent Link to <?php the_title_attribute(); ?>">' . $member['god-story-title'] . '<?php the_title(); ?></a></h2>';
    
    			   		echo '<h4 class="member-name">' . $member['member-name'] . '</h4>';
    
    			    	$image = $member['member-picture'];
    					$attachment_image = wp_get_attachment_image_src( $image, 'full' );
    					$src = $attachment_image[0];
    
    					if( !empty( $src ) )
    						echo '<div class="member-picture-wrapper">';
      						echo '<img src="' .$src. '" class="member-picture"/>';
      						echo '</div>';}?>
    
    	<?php endif; ?>

Reply

You must log in to post.

About this Topic