This is a single.php and for example url is
http://url.com/sample-post/
I added some extra content with Advanced Custom Fields plugin and show it in the content. Everything is all right here but I want to show this extra content like http://url.com/sample-post/extra-content/
Is it possible? If yes how can I make it? I've been searching for hours but I have not found anything.
I hope you understand me and so sorry for my bad english. Thank you everyone who will help.
<?php get_header(); ?>
<main class="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php the_field('some-extra-content'); ?> // Extra Content
<?php endwhile; ?>
</main>
<?php get_footer(); ?>
please try below code for ACF
<?php get_header(); ?>
<main class="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php echo get_field('some-extra-content', $post->ID); ?>
<?php endwhile; ?>
</main>
<?php get_footer(); ?>
Not exactly the same url but you could use a query string.
http://url.com/sample-post?extra=true
<?php
if($_GET['extra'] === 'true'){
the_field('some-extra-content');
}
?>
Related
I have created a group field in ACF to display on posts, pages and custom post type. Please see below screenshots.
And here's the code I'm trying for front-end.
<?php $footerCTA = get_field('footer_cta');
echo $footerCTA['title']; ?>
The code above doesn't output anything on the front-end. Am I missing here something?
Thanks.
try this:
if( have_rows('footer_cta') ):
while( have_rows('footer_cta') ) : the_row();
?>
<p><?php the_sub_field('title'); ?></p>
<?php
endwhile;
endif;
?>
Try using.
echo the_field('footer_cta');
Other Way.
You can do this by adding a second parameter to the get_field or the_field functions. This second parameter will contain the correct ID which can be found using get_option('page_for_posts') like so
<h1><?php the_field('footer_cta', get_option('page_for_posts')); ?></h1>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php if ( have_posts() ) : ?>
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div><!-- #content -->
</div><!-- #primary -->
I am new to wordpress. I have a problem with pagination when I click to the next post it shows "not found". I installed the plugin wp pagenavi, and I put code in my blog post <?php wp_pagenavi(); ?>. It shows the pagination, but I have a problem with the link to the next post. Example when I click to the next post — http://westecmedia.com/events/page/2/ — it shows:
Something went Wrong!
404
-->
You can see at: http://westecmedia.com/events/
And this is my code in event-page.php:
<?php
/*
* Template Name: Page - Events Page
*/
?>
<?php get_header(); ?>
<div id="content-events">
<div id="head-event"><h3>EVENTS</h3></div>
<div id="main-event">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else: endif; ?>
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="part-event">
<div id="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<div id="event-dess">
<h2><?php the_title(); ?></h2>
<p>
<?php
$content = get_the_content();
$content = strip_tags($content);
echo substr($content, 0, 300);
?>
</p>
<div id="read-more">Read More</div>
</div>
</div>
<div id="line-bottom"></div>
<?php endwhile; else: endif; ?>
<?php wp_pagenavi(); ?>
</div>
</div>
<?php get_footer(); ?>
Who can help me please?
https://codex.wordpress.org/Function_Reference/paginate_links
Please try using this instead of plugin. Also add this code before the if loop ends.
I have a signifiantly big problem up there.
I'm trying to design my search restult page on WordPress, but if it comes that the search find a page with the keyword I just entered, it display the entire page instead of the title();
My code
<?php
/**
* The template for displaying search results pages.
*
* #package miller
*/
get_header(); ?>
<section id="primary" class="content-area">
<main id="int_top_main" class="internal blue_top" style="min-height:80px;">
<div class="wrapper">
<h2 class="page_title uppercase"><span class="parent_page">Search results</h2>
<div id="infinite_blue_top_bar"></div>
</div>
</main><!-- #main -->
<div id="int_content_main" class="internal">
<div class="wrapper physician_headline">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
<?php else : ?>
<h2><?php _e( 'Nothing Found', 'miller' ); ?></h2>
<div class="page-content">
<?php if ( is_search() ) : ?>
<p><?php _e( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'miller' ); ?></p>
<?php else : ?>
<p><?php _e( 'It seems we can’t find what you’re looking for. Perhaps searching can help.', 'miller' ); ?></p>
<?php endif; ?>
</div><!-- .page-content -->
<?php endif; ?>
</div>
</div>
</section><!-- #primary -->
<?php get_footer(); ?>
If it finds nothing, it will go into the else: but if it do finds something they display all the pages (fullpage) of what it finds out there.
It should only display the_title(); but no..
Even if I completly destruct the search.php file it stills automaticly goes to the "suggested" page.
First time I am getting this kind of thing and I do not know how to solve it :(
It's calling for the post before the title, which is why it pulls for the full post.
Try:
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_title(); ?>
<?php endwhile; ?>
<?php else : ?>
I have some categories like about-us, services etc and want to show different templates for these categories. I have read from wp site to make files name like category-slug.php where slug may be about-us or services. I made these files but they didn't worked for me. Instead of these templates the index file displays the posts. I want to display posts from these categories in custom files.
Can any one tell me how to do this?
Are you looking for something like this?
<?php /*
Template Name: ListPostsInCategoryThatHasSameNameAsPage
*/ ?>
<?php get_header(); ?>
<div id="content">
<div id="main">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; else: endif; ?>
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?>
<?php endwhile; else: endif; ?>
</div>
</div>
<?php get_footer(); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
I'm using the loop to pull a few custom posts to display on the site. I have a designated <div> to hold the posts. I've run into the problem when there are no posts to be pulled, the div box still displays with no content in it. How would I insert the code of my div container within the "if" statement so that the div is only created if there are posts?
<?php if (have_posts()) : ?>
<div>
<?php while (have_posts()) : the_post(); ?>
…
<?php endwhile; ?>
</div>
<?php endif; ?>
You may find the documentation on PHP's alternative syntax useful
Try the following code snippet:
<?php if (have_posts()) { ?>
<div>
<?php } ?>
<?php while (have_posts()) : the_post(); ?>
...
<?php endwhile; ?>
<?php if (have_posts()) { ?>
</div>
<?php } ?>
<?php endif; ?>
I hope this helps!
Create a 404.php for your theme and drop the if (have_posts()) completely. You can start the loop with the while statement, and WordPress will use the 404.php if there are no posts.