- This topic is empty.
-
AuthorPosts
-
February 21, 2015 at 8:51 pm #196509
Historical Forums User
ParticipantMy first wordpress theme is giving me some trouble. I know it’s pretty buggy, so my apologies in advance. A lot of that is due to syntax errors, I’m sure, as I’m really, really new to PHP and js. For instance, in the Codenvy project I’m sharing here, I know I don’t need to put “echo” at the start of every line, but it’s the only way I was able to get it to function at all.
The beta site is up here. Please note that the site at the root of that address is not my work.
- One of the main problems I’m having is that in the right hand column of the main content area of the home page, in each category, only the first blog post excerpt title shows the date of the post.
- You’ll also see in the 4th box in the right hand column, the author’s name is repeated twice. Same thing in the next box.
Any help is appreciated!
February 22, 2015 at 7:59 am #196542Alen
Participant@adjmedia Links do not work for me.
February 22, 2015 at 8:29 am #196543Historical Forums User
ParticipantSorry about that. The beta site is at http://www.akilahtzuberi.com/blog. I’ll have to grab the other link later.
February 22, 2015 at 9:28 am #196547Senff
ParticipantIt’s impossible for us to diagnose some of these problems if we don’t see the source code, and only the output.
I suggest you put your theme on Github or something, so we can see all the source PHP. Alternatively, isolate the code that’s giving you trouble and post that here (if you know the exact parts of the code that are relevant).
February 22, 2015 at 1:18 pm #196548Historical Forums User
ParticipantSorry, I thought that codenvy link would show the source code for you (you have to double click on the project name for it to open), Here is the source code that is outputting the blog posts in the right hand column of the main content area (the middle column if you count the sidebar). The live site is at http://akilahtzuberi.com/blog.
<?php //OUTPUT SECTION 1 POSTS $args = array( 'post_type' => 'section-1', 'posts_per_page' => 3 ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); echo '<div class="post_introbox">'; echo '<div class="post_titlebox">'; echo '<h3 id="post-<?php the_ID(); ?>"><a href="'; echo the_permalink(); echo '">'; echo the_title(); echo '</a></h3>'; echo '<p><span><a href="author/"'; echo get_the_author_link(); echo '</span></a>'; //echo the_author(); </span></a>; echo ' • '; echo the_date('m.d.Y'); '</p>'; echo '</div>'; //close titlebox echo '<div class="containerz">'; echo '<a href="'; echo the_permalink(); echo '">'; echo add_image_size( 'front-featured', 374, 250, array( 'center', 'center' ) ); // Hard crop left top if ( has_post_thumbnail() ) {; // check if the post has a Post Thumbnail assigned to it. the_post_thumbnail( 'front-featured' ); } echo '</a></div>'; echo '<div class="section_link_box"> '; echo '<span class="section1">'; echo '<a href="/blog/'; echo get_post_type( $post ); echo '">'; $category = get_the_category( $custompost ); echo $category[0]->cat_name; echo '</a></span></div>';//CLOSE SECTION_LINK_BOX echo '<div class="spacer_one"></div>'; echo '<div class="introtext section1">'; echo the_excerpt(); echo '<p class="more">'; echo '<a href="'; echo the_permalink(); echo '">'; echo 'Continue Reading</a></p>'; echo '<div class="clearfloat"></div>'; echo '</div></div>'; //close introtext endwhile; ?> <?php //OUTPUT SECTION 2 POSTS $args = array( 'post_type' => 'section-2', 'posts_per_page' => 2 ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); echo '<div class="post_introbox">'; echo '<div class="post_titlebox">'; echo '<h3 id="post-<?php the_ID(); ?>"><a href="'; echo the_permalink(); echo '">'; echo the_title(); echo '</a></h3>'; echo '<p><a href="author/'; echo get_the_author(); echo '"><span>'; echo the_author(); '</span></a>'; echo ' • '; echo the_date('m.d.Y'); '</p>'; echo '</div>'; //close titlebox echo '<div class="containerz">'; echo '<a href="'; echo the_permalink(); echo '">'; echo add_image_size( 'front-featured', 374, 250, array( 'center', 'center' ) ); // Hard crop left top if ( has_post_thumbnail() ) {; // check if the post has a Post Thumbnail assigned to it. the_post_thumbnail( 'front-featured' ); } echo '</a></div>'; echo '<div class="section_link_box"> '; echo '<span class="section2">'; echo '<a href="/blog/'; echo get_post_type( $post ); echo '">'; $category = get_the_category( $custompost ); echo $category[0]->cat_name; echo '</a></span></div>';//CLOSE SECTION_LINK_BOX echo '<div class="spacer"></div>'; echo '<div class="introtext section2">'; echo the_excerpt(); echo '<p class="more">'; echo '<a href="'; echo the_permalink(); echo '">'; echo 'Continue Reading</a></p>'; echo '<div class="clearfloat"></div>'; echo '</div></div>'; //close introtext endwhile; echo wp_reset_query(); ?> <?php //OUTPUT SECTION 3 POSTS $args = array( 'post_type' => 'section-3', 'posts_per_page' => 2 ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); echo '<div class="post_introbox">'; echo '<div class="post_titlebox">'; echo '<h3 id="post-<?php the_ID(); ?>"><a href="'; echo the_permalink(); echo '">'; echo the_title(); echo '</a></h3>'; echo '<p><a href="author/'; echo get_the_author(); echo '"><span>'; echo the_author(); '</span></a>'; echo ' • '; echo the_date('m.d.Y'); '</p>'; echo '</div>'; //close titlebox echo '<div class="containerz">'; echo '<a href="'; echo the_permalink(); echo '">'; echo add_image_size( 'front-featured', 374, 250, array( 'center', 'center' ) ); // Hard crop left top if ( has_post_thumbnail() ) {; // check if the post has a Post Thumbnail assigned to it. the_post_thumbnail( 'front-featured' ); } echo '</a></div>'; echo '<div class="section_link_box"> '; echo '<span class="section3">'; echo '<a href="/blog/'; echo get_post_type( $post ); echo '">'; $category = get_the_category( $custompost ); echo $category[0]->cat_name; echo '</a></span></div>';//CLOSE SECTION_LINK_BOX echo '<div class="spacer"></div>'; echo '<div class="introtext section3">'; echo the_excerpt(); echo '<p class="more">'; echo '<a href="'; echo the_permalink(); echo '">'; echo 'Continue Reading</a></p>'; echo '<div class="clearfloat"></div>'; echo '</div></div>'; //close introtext endwhile; echo wp_reset_query(); ?> <?php //OUTPUT SECTION 4 POSTS $args = array( 'post_type' => 'section-4', 'posts_per_page' => 2 ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); echo '<div class="post_introbox">'; echo '<div class="post_titlebox">'; echo '<h3 id="post-<?php the_ID(); ?>"><a href="'; echo the_permalink(); echo '">'; echo the_title(); echo '</a></h3>'; echo '<p><a href="author/'; echo get_the_author(); echo '"><span>'; echo the_author(); '</span></a>'; echo ' • '; echo the_date('m.d.Y'); '</p>'; echo '</div>'; //close titlebox echo '<div class="containerz">'; echo '<a href="'; echo the_permalink(); echo '">'; echo add_image_size( 'front-new644-featured', 1000, 582, array( 'top', 'left' ) ); // Hard crop left top if ( has_post_thumbnail() ) {; // check if the post has a Post Thumbnail assigned to it. the_post_thumbnail( 'front-featured' ); } echo '</a></div>'; echo '<div class="section_link_box"> '; echo '<span class="section4">'; echo '<a href="/blog/'; echo get_post_type( $post ); echo '">'; $category = get_the_category( $custompost ); echo $category[0]->cat_name; echo '</a></span></div>';//CLOSE SECTION_LINK_BOX echo '<div class="spacer"></div>'; echo '<div class="introtext section4">'; echo the_excerpt(); echo '<p class="more">'; echo '<a href="'; echo the_permalink(); echo '">'; echo 'Continue Reading</a></p>'; echo '<div class="clearfloat"></div>'; echo '</div></div>'; //close introtext endwhile; echo wp_reset_query(); ?>
February 22, 2015 at 3:20 pm #196556Anonymous
InactiveThere’s definitely some incorrect code in there:
echo '<h3 id="post-<?php the_ID(); ?>"><a href="';
And I suspect:
echo '<p><span><a href="author/"'; echo get_the_author_link(); echo '</span></a>'; //echo the_author(); </span></a>;
Wasn’t doing what you were expecting it to either. As far as I can tell from the documentation,
get_the_author_link()
spits out the anchor tag anyway.As you rightly acknowledge, the repeated
echo
s are unnecessary and make the code much harder to visualise. I’ve cleaned up the first section in a pastebin:That should be functionally the same, although I did take the liberty of removing the malformed lines. Hopefully the problems won’t persist after you’ve applied the same principle to the rest of the code.
February 22, 2015 at 6:41 pm #196565Alen
Participant@adjmedia just a note, in @BenWalker code you don’t need to put
echo
in front of<?php the_title(); ?>
.In WordPress if the function starts with
the_
it already echos the value. If you’re trying to get the value and do something with it you’ll need to use:$author = get_the_author(); echo $author; # is the same as the_author();
February 28, 2015 at 7:39 pm #197030Historical Forums User
Participant@BenWalker and @Alen thank you both for your help! This is definitely an improvement, markup wise, but the lack of a date in subsequent posts after the first post in a post type is still a problem. Any tips? Do I need to reset the query? I think I’ve done that, but doesn’t seem to be helping. The live site is at akilahtzuberi.com/blog. Here is the section 1 code that @BenWalker cleaned up for me with the edits that @Alen suggested.
Unfortunately, my client only wants to show two articles total in one post type for the next month, so it’s not possible to test the subsequent post type sections in a way that I can share. Maybe I can work something out on github.
March 1, 2015 at 5:17 am #197043Alen
Participantbut the lack of a date in subsequent posts after the first post in a post type is still a problem. Any tips?
@adjmedia
Try using
wp_reset_query()
at the end of each output section. Note that in your code above you haveecho wp_reset_query();
you don’t need echo here, this function sort of “rewinds” stuff back, and it’s probably the reason your dates don’t work. In some cases your widgets will break as well.March 10, 2015 at 3:38 pm #197832Historical Forums User
ParticipantHello, so I think I’ve resolved the problem on the home page by changing “the_date(m.d.Y)” to “the_time(m.d.Y)” as suggested in this forum.
I’m still having the same trouble with the date on my archive pages, but there I’m using:
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
I’m going to try to play around with this for a while longer because I like that you get the author name and the date for free with that bit of code, rather than having to ask for each individually, but I’ll likely set up my archive pages (i.e. http://www.akilahtzuberi.com/blog/section-1/) like the home page and use “the_time()” instead.
March 10, 2015 at 3:39 pm #197833Historical Forums User
ParticipantAlso, I tired the wp_reset_query() suggestion but it doesn’t seem to solve the problem. That was my hunch too, but unless I’m misusing the function somehow, it doesn’t seem to be having an effect.
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.