my wordpress theme i created shows just the first timestamp of the first article of multiple article on the page. On the rest of them there is just a empty space, so php generated no echo.
I think that there is something wrong with the loop, but i found similar loops on the wp page. Can someone help me ?
here is my code
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="entry">
<h2 class="title"><?php the_title(); ?></h2>
<div class="time-text">added on: <?php the_date('d.m.Y'); ?> - Author: <?php the_author(); ?></div>
<div id="text_post" style="margin-top:20px;">
<?php the_content(); ?>
</div></div>
<?php endwhile;endif?>
It's how the the_date function works. Quoting the "special note" on that page:
SPECIAL NOTE: When there are multiple posts on a page published under
the SAME DAY, the_date() only displays the date for the first post
(that is, the first instance of the_date()). To repeat the date for
posts published under the same day, you should use the Template Tag
the_time() or get_the_date() (since 3.0) with a date-specific format
string.
Try using <?php echo get_the_date('d.m.Y'); ?> instead of <?php the_date('d.m.Y'); ?>. That's untested - I'm just going by that quote.
First you need to open these three files:
index.php
single.php
page.php
Then you will need to locate the following code:
<?php the_modified_time('F jS, Y');?>
Note: Since there are so many formats of displaying dates, you might not see the exact code, but something along this line.
Replace it with:
<?php $u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
echo "and last modified on ";
the_modified_time('F jS, Y');
echo " at ";
the_modified_time();
echo ", "; } ?>
Related
I am using a custom post type to allow a client to add job listings to their site using the Avada Theme. The desired archive layout involves using pre-built fusion toggles to display each job post (individual job posts use Advanced Custom Fields). I have created a custom archive-employment.php to run my code for this page in and was successfully able to create toggles for each post, however, each toggle acts independently and does not close when another one opens. Here is what I have so far:
<?php echo do_shortcode ('[fusion_accordion type="accordions" boxed_mode="" border_size="" border_color="" background_color="" hover_color="" divider_line="" title_font_size="" icon_size="" icon_color="" icon_boxed_mode="" icon_box_color="" icon_alignment="" toggle_hover_accent_color="" hide_on_mobile="" class="" id="hr-employment"]'); ?>
<?php if(have_posts()) :
while(have_posts()) : the_post();?>
<div class="entry-content">
<?php $title = get_the_title(); ?>
<?php $dept = get_field("department"); ?>
<?php $jobType = get_field("job_type"); ?>
<?php $salary = get_field("salary"); ?>
<?php $desc = get_field("job_description"); ?>
<?php $addInfo = get_field("additional_info"); ?>
<?php echo do_shortcode ('[fusion_toggle title="'.$title.'" open="" ]Department: '.$dept.' </br> Job Type: '.$jobType.' </br> Salary: $'.$salary.' </br> Description: PDF[/fusion_toggle]'); ?>
</div>
<?php endwhile;
endif; ?>
<!--<?php echo do_shortcode ('[/fusion_accordion]'); ?> Plain Text Error; Not a Valid Shortcode Operator -->
How do I make it so that the [fusion_accordion] shortcode is executed only once and is wrapped around the [fusion_toggle] shortcodes that run in the while loop?
I can't seem to display only the content I request. I am using the Advanced Custom Fields (ACF) plugin with my Wordpress site, and using a repeater field with a multiple select field for "departments \ job titles".
With the code below, I am looking to display only the content which has the value that equals what I select. Maybe I am looking at this wrong but the content displays whether the strpos is true or not.
<?php if (get_field('policy_links') ): ?>
<center><h3><a name="All"></a>All Employees</h3></center>
<hr>
<ul class="bullets">
<?php while (has_sub_field('policy_links')) : ?>
<?php $jobtype = get_sub_field('who_is_this_for'); ?>
<?php if (strpos ($jobtype, 'ma') !== false) { ?>
<li><a href="<?php the_sub_field('link_to_the_document'); ?>">
<?php the_sub_field('display_name'); ?></a><span> - <small>
<?php the_sub_field('link_notes'); ?></small></span>
<?php the_sub_field('who_is_this_for'); ?></li>
<?php } else { ?><p>fail </p>
<?php }; // end of the loop. ?>
<?php endwhile; // end of the loop. ?>
</ul>
<?php endif; ?>
Your if statement should be done like this:
<?php if(get_sub_field('who_is_this_for') == 'strpos') { ?><?php }?>
Where "strpos" is the value you select (if I follow correctly).
It would probably be beneficial to actually see your fields.
I was on the right track. It turns out the ACF is converted to an array when multiple values are selected. I performed an implode to the variable then used the converted string performed the validation.
thanks for the help
I am trying to list authors on a page, but exclude the admin (myself). I am using a child theme of squirrel and this is my code so far:
<?php
$authors = $wpdb->get_results('SELECT DISTINCT post_author FROM '.$wpdb->posts);
if($authors):
foreach($authors as $author):
?>
<div class='author' id='author-<?php the_author_meta('user_login', $author->post_author); ?>'>
<h3><?php the_author_meta('display_name', $author->post_author); ?></h3>
<?php if(get_the_author_meta('description', $author->post_author)): ?>
<div class='description'>
<?php echo get_avatar(get_the_author_meta('user_email', $author->post_author), 80); ?>
<p><?php the_author_meta('description', $author->post_author); ?></p>
</div>
<?php endif; ?>
<?php
$recentPost = new WP_Query('author='.$author->post_author.'&showposts=1');
while($recentPost->have_posts()): $recentPost->the_post();
?>
<h4>Recent Article: <a href='<?php the_title();?>'><?php the_title(); ?></a></h4>
<?php endwhile; ?>
</div>
<?php endforeach; endif; ?>
I tried using the solution from this discussion, but I don't think I am doing it right because when I add this line of code:
if(get_the_author_meta('display_name', $author->post_author) != 'admin'):
under:
foreach ($authors as $author):
it just breaks the entire site (the screen is white). This is all new to me, so can someone please help me figure out what I am doing wrong?
Thanks a lot!
The white screen you are experiencing is a fatal PHP error. You are not seeing what the error is, for security reasons.
However, during development, you want this feature off. Just edit wp-config.php and set WP_DEBUG to true.
As for your question, you might want something like:
if($author->post_author == 1) continue;
...as the first line inside the foreach. The id 1 should be your userid because the first user created in WP has 1, and the keyword continue jumps to the end of the foreach, thus skipping your user.
If you prefer doing this by username, use this:
if(get_the_author_meta('user_login', $author->post_author) == 'admin') continue;
This loop brings in all the pages and shows it on a single page. How can I edit it so that I only bring in one page identified by its ID? (the page wont change)
Thanks
<section id="<?php echo $post->post_name;?>" class="page-area<?php echo $bgClass;?>"<?php echo $style;?>>
<div class="wrapper"<?php if($fullEmbed<>''):?> style="width:100%"<?php endif;?>>
<?php if($hideTitle!='Yes'):?>
<hgroup class="title">
<h1<?php echo $font;?>><strong><?php echo $mainHeading;?></strong></h1>
<?php if($subHeading<>''):?><p<?php echo $font;?>><?php echo $subHeading;?></p><?php endif;?>
</hgroup>
<?php endif;?>
<?php if($fullEmbed<>''):?>
<div class="full-embed"><?php echo van_shortcode($fullEmbed);?></div>
<?php else:?>
<div class="entry"<?php echo $font;?>>
<?php van_content(true,true);?>
</div>
<?php endif;?>
</div>
</section>
<?php endwhile;?>
You mean like:
<?php
$page_id = 123; // 123 should be replaced with a specific Page's id from your site, which you can find by mousing over the link to edit that Page on the Manage Pages admin page. The id will be embedded in the query string of the URL, e.g. page.php?action=edit&post=123.
$page_data = get_page( $page_id ); // You must pass in a variable to the get_page function. If you pass in a value (e.g. get_page ( 123 ); ), WordPress will generate an error. By default, this will return an object.
echo '<h3>'. $page_data->post_title .'</h3>';// echo the title
echo apply_filters('the_content', $page_data->post_content); // echo the content and retain WordPress filters such as paragraph tags. Origin: http://wordpress.org/support/topic/get_pagepost-and-no-paragraphs-problem
?>
Straight from the WP Codex http://codex.wordpress.org/Function_Reference/get_page
Using the magicfields 2.0 plugin for Wordpress 3.1.
Here's the broken page:
http://sseko.wecreativeagency.com/style/
and here's a page with it working:
http://sseko.wecreativeagency.com/university-bound/
Note the footer on the first page is receiving the id info from the magicfields
<?php get_header(); ?>
<div id="content">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>">
<?php the_content(); ?>
<div id="note" class="grid_12"><p class="note grid_6 alpha"><span class="special">Style your Ssekos!</span> There are so many ways to tie your Ssekos. Watch the videos and learn how! Then, come up with your own!</p><h1 class="grid_6 omega"><?php wp_title(' ','true','right'); ?></h1></div>
<?php $styles = getFieldOrder('image');
if(is_array($styles))
{foreach($styles as $style)
{
echo "<div class='grid_3'>";
echo "<a rel='styles' href='#info$style'class='inlineimg grid_3'>";
echo "<img src='";
echo get_image('image',1,$style,$tag_img=0);
echo "'class='grid_3' title='";
echo get('name',1,$style);
echo "'alt='";
echo get('name',1,$style);
echo "'";
echo "</a>";
echo "<h2 class='grid_3'>";
echo get('name',1,$style);
echo "</h2></div>";
echo "<div style='display:none'><div id='info$style' class='grid_8 lightbox'>";
echo get('link',1,$style);
echo "</div></div>";
}
}
?>
<div class="clear"></div>
</article>
<?php endwhile; endif; ?>
I've check the database for extra entries but I can't find the reason for it continuing to iterate out into the elements below.
For some reason I could not check your site .. but I believe this is hapenning because you have 2 nested loops ..
One is the Wordpress loop if--> while , and then your Foreach loop.
When the Wordpress loop encounters posts , it will iterate your second loop FOR EACH ONE of the posts ...
for example, on a page where there are 10 $post, it will iterate 10 times for each $style ...
When you have 1 post , it will iterate once .
Like I said, for some reason your site was not available to me , but seeing your URL construction, My guess is that it does not work on the first example, because it is some kind of category (which returns multiple posts ) and the second url is a SINGLE post ...