Display Advanced Custom field on Wordpress Taxo Term - php

I am unable to get ACF to display on an archive page for the term itself.
<?php the_field('download_link'); ?>
I added the above code to my theme and it doesn't work. I also tried
<p><?php the_field('download_link', $term); ?></p>
Below is the default code on my page (content-archive.php). i'd like this to show up before.
<div <?php post_class(); ?>>
<?php do_action( 'archive_post_before' ); ?>
<article>
<div class='post-header'>
<?php do_action( 'sticky_post_status' ); ?>
<h2 class='post-title'>
<?php the_title(); ?>
</h2>
<?php get_template_part( 'content/post-byline' ); ?>
</div>
<div class="post-content">
<?php ct_chosen_excerpt(); ?>
</div>
</article>
<?php do_action( 'archive_post_after' ); ?>

Related

Show three full posts on catgegory page, then rest of posts as titles only

I'm building a theme and on my category.php page I want to show several full posts (let's say 3, but need to be able to change this to 2 or 1 easily), and then the rest of the posts in the category as title links.
I have quite a bit of HTML in my loop for styling my posts and adding custom fields so sorry about all the code, but this is what my category.php page looks like now. I've tried a few things that haven't worked so have edited this to show my original code which just has a normal list of posts. I'm somewhat new to editing The Loop so would appreciate as much explanation/clarity as possible.
<?php
/**
* The template for displaying Category Archive pages.
*/
get_header(); ?>
<div id="primary" class="<?php
$category = get_the_category();
echo $category[0]->cat_name;
?>">
<div id="feature-container" class="full-width-container">
<div class="full-width-container content-page" id="tagline-wrapper">
<div id="left-black"></div>
<div class="page-width-container">
<div id="tagline-box">
<h1 class="category-title">Transactions</h1>
</div>
</div>
</div>
</div>
<div id="content-wrapper">
<div id="project-menu" class="page-width-container">
<?php wp_nav_menu( array( 'theme_location' => 'project-types' ) ); ?>
</div>
<div id="content" role="main" >
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="story-container" class="module-container">
<div class="our-story">
<div class="story-image">
<?php
// check if the post has a Post Thumbnail assigned to it.
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
</div>
<div class="story-text">
<article class="post" id="post-<?php the_ID(); ?>">
<div class="entry-container">
<h2><?php the_title(); ?></h2>
<div class="project-details">
<p><span class="details-location"><?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, '_project-location', true);
wp_reset_query();
?></span><br />
<span class="details-funding"><?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, '_funding-type', true);
wp_reset_query();
?> | <?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, '_funding-source', true);
wp_reset_query();
?></span><br />
<span class="details-value"><?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, '_project-value', true);
wp_reset_query();
?></span></p>
</div>
<div class="entry">
<?php the_content(); ?>
<?php wp_link_pages(array('before' => __('Pages: ','html5reset'), 'next_or_number' => 'number')); ?>
</div>
<?php edit_post_link(__('Edit this entry','html5reset'), '<p>', '</p>'); ?>
</div>
</article>
</div>
</div>
</div>
<?php endwhile; endif; ?>
</div><!-- #content -->
</div>
</div><!-- #primary -->
<?php get_footer(); ?>
You can achive above thing using following code:
First you have to loop all post and and put counter when it reach more then 2 its stop to print a content.but title will be there always.
<?php $countPost=1;?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post">
<h2 id="post-<?php the_ID(); ?>">
<?php the_title(); ?></h2>
<?php if($countPost>2) : /*Condition for Content*/
the_content();
endif;
?>
</div>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft">
<?php posts_nav_link('','','« Previous Entries') ?>
</div>
<div class="alignright">
<?php posts_nav_link('','Next Entries »','') ?>
</div>
</div>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center"><?php _e("Sorry, but you are looking for something that isn't here."); ?></p>
<?php endif; ?>
</div>
For more details please refer :
https://codex.wordpress.org/The_Loop_in_Action
I figured out a bit of a workaround solution on my own, although it relies on using plugins/widgets which isn't what I'd prefer.
I simply set the Reading settings to display 2 posts, and then below the Loop I added a widget area and used the Recent Posts Extended widget to display a list of titles/links. This widget allows you to skip a certain amount of posts in the list, so I set it to start at post #3. There was no option to show posts from the current category only, so I had to use the Widget Context plugin as well and make individual widgets with a specific category to show on each corresponding category page. As I said, a bit of a convoluted solution, but the end result is exactly what I wanted to achieve.

How to add post format to theme?

For classipress theme. I can register post_formats the normal way in functions (works - I can select "link" type in the editor), but I can't figure out how to get it to actually use a template file for link posts.
I have used the get_template_part('content', get_post_format()); in the past successfully,
but I can't figure how to inject that into the single.php's code for this theme:
Single.php
<?php
/**
* The Template for displaying all single posts.
*
* #package ClassiPress\Templates
* #author AppThemes
* #since ClassiPress 1.0
*/
?>
<div class="content">
<div class="content_botbg">
<div class="content_res">
<div id="breadcrumb"><?php cp_breadcrumb(); ?></div>
<div class="content_left">
<?php appthemes_before_blog_loop(); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php appthemes_before_blog_post(); ?>
<?php appthemes_stats_update( $post->ID ); //records the page hit ?>
<div class="shadowblock_out">
<div class="shadowblock">
<div class="post">
<?php appthemes_before_blog_post_title(); ?>
<h1 class="single blog"><?php the_title(); ?></h1>
<?php appthemes_after_blog_post_title(); ?>
<div style="margin-top:10px; text-align:center;">
<?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) { ADDTOANY_SHARE_SAVE_KIT(); } ?>
</div>
<?php appthemes_before_blog_post_content(); ?>
<?php if ( has_post_thumbnail() ): ?>
<div id="main-pic">
<?php cp_get_blog_image_url(); ?>
</div>
<?php endif; ?>
<?php the_content(); ?>
<div class="dotted"></div>
<div class="pad5"></div>
<?php appthemes_after_blog_post_content(); ?>
</div><!-- .post -->
</div><!-- .shadowblock -->
</div><!-- .shadowblock_out -->
<?php appthemes_after_blog_post(); ?>
<?php endwhile; ?>
<?php appthemes_after_blog_endwhile(); ?>
<?php else: ?>
<?php appthemes_blog_loop_else(); ?>
<?php endif; ?>
<div class="clr"></div>
<?php appthemes_after_blog_loop(); ?>
<div class="clr"></div>
<?php comments_template(); ?>
</div><!-- .content_left -->
<?php get_sidebar( 'blog' ); ?>
<div class="clr"></div>
</div><!-- .content_res -->
</div><!-- .content_botbg -->
</div><!-- .content -->
Content.php
<?php
/**
* Post loop content template.
*
* #package ClassiPress\Templates
* #author AppThemes
* #since ClassiPress 3.4
*/
?>
<div <?php post_class( 'shadowblock_out' ); ?> id="post-<?php the_ID(); ?>">
<div class="shadowblock">
<?php appthemes_before_blog_post_title(); ?>
<h3 class="loop"><?php the_title(); ?></h3>
<?php appthemes_after_blog_post_title(); ?>
<?php appthemes_before_blog_post_content(); ?>
<div class="entry-content">
<?php if ( has_post_thumbnail() ) the_post_thumbnail( 'blog-thumbnail' ); ?>
<?php the_content( __( 'Continue reading ...', APP_TD ) ); ?>
</div>
<?php appthemes_after_blog_post_content(); ?>
</div><!-- #shadowblock -->
</div><!-- #shadowblock_out -->
Tried a lot of things, unsuccessful in doing anything but breaking the page.
Thanks
Post formats are used to customize the presentation of post items. If you check out some theme that supports post formats (For example Twenty Fifteen), you will see that the single.php file is not used to output the contents of the post - which is delegated to content-*.php files. (For example, the the_content() function, which outputs a post's content is not in single.php, but in content.php (and content-link.php and others).
Your single.php does not seem to be built this way, so it does not support post formats, but it can be refactored easily, just split it into two files (in single.php you should keep the "frame" code that is common for every post format, then move the rest into a new content.php file, which will be used as the default format):
single.php
<?php
/**
* The Template for displaying all single posts.
*
* #package ClassiPress\Templates
* #author AppThemes
* #since ClassiPress 1.0
*/
?>
<div class="content">
<div class="content_botbg">
<div class="content_res">
<div id="breadcrumb"><?php cp_breadcrumb(); ?></div>
<div class="content_left">
<?php appthemes_before_blog_loop(); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php appthemes_before_blog_post(); ?>
<?php appthemes_stats_update( $post->ID ); //records the page hit ?>
<?php
// Note the below line which loads the desired content*.php
get_template_part('content', get_post_format());
?>
<?php appthemes_after_blog_post(); ?>
<?php endwhile; ?>
<?php appthemes_after_blog_endwhile(); ?>
<?php else: ?>
<?php appthemes_blog_loop_else(); ?>
<?php endif; ?>
<div class="clr"></div>
<?php appthemes_after_blog_loop(); ?>
<div class="clr"></div>
<?php comments_template(); ?>
</div><!-- .content_left -->
<?php get_sidebar( 'blog' ); ?>
<div class="clr"></div>
</div><!-- .content_res -->
</div><!-- .content_botbg -->
</div><!-- .content -->
content.php
<div class="shadowblock_out">
<div class="shadowblock">
<div class="post">
<?php appthemes_before_blog_post_title(); ?>
<h1 class="single blog"><?php the_title(); ?></h1>
<?php appthemes_after_blog_post_title(); ?>
<div style="margin-top:10px; text-align:center;">
<?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) { ADDTOANY_SHARE_SAVE_KIT(); } ?>
</div>
<?php appthemes_before_blog_post_content(); ?>
<?php if ( has_post_thumbnail() ): ?>
<div id="main-pic">
<?php cp_get_blog_image_url(); ?>
</div>
<?php endif; ?>
<?php the_content(); ?>
<div class="dotted"></div>
<div class="pad5"></div>
<?php appthemes_after_blog_post_content(); ?>
</div><!-- .post -->
</div><!-- .shadowblock -->
</div><!-- .shadowblock_out -->
Now, for additional post formats, for example gallery, you will have to create a file named content-gallery.php and implement it. You can derive it from the default content.php, but you decide how it should look like.

PHP codes for wordpress

Hello guys so I am making a car review wordpress magazine and I am having issues with php codes as I am not a great programmer. Actually on this page Memes I would like the social plugins to be below each picture and not on the top furthermore I would like it to display the post date and the author of the post. Some formatting for the pictures size etc would be great too. Below is the code I am using
<?php /*
Template Name: ListPostsInCategoryThatHasSameNameAsPage
*/ ?>
<?php get_header(); ?>
<div id="content" class="archive <?php if(get_option('colabs_layout_settings')=='two-col-right'){echo 'right';}else{?>left<?php }?>">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class(); ?> id="post_<?php the_ID(); ?>">
<span id="map"><?php _e('Home','colabsthemes');?> » <?php the_title(); ?></span>
<h2 class="title"><?php the_title(); ?></h2>
<div class="entry" style="padding-top:15px;">
<?php the_content(__('<p>Read the rest of this page »</p>','colabsthemes')); ?>
<?php echo colabs_share();?>
<?php wp_link_pages(array('before' => __('<p><strong>Pages:</strong>','colabsthemes'), 'after' => '</p>', 'next_or_number' => 'number')); ?>
</div>
</div>
<?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>
<div id="sidebar" class="<?php if(get_option('colabs_layout_settings')=='two-col-right'){echo 'left';}else{?>right<?php }?>">
<?php get_sidebar(); ?>
</div>
<div> <?php get_footer(); ?> </div>
Finally for the review part I would like to do something like Autotest/review but I don't know which code to use to show these kind of square articles. Please help me out.
For adding the author and date of the post, you can add:
<p>Written by:
<?php get_the_author(); ?></p>
get_the_author() will display the author's name as is set in their "Display name publicly as" field in their user profile (Administration > Users > Your Profile).
To also display the date:
<p>Written by:
<?php get_the_author(); ?> on
<?php get_the_date(); ?></p>
I don't see where you're using the social sharing links on the page you linked to - did you remove them?
For more information:
http://codex.wordpress.org/Function_Reference/get_the_author
http://codex.wordpress.org/Function_Reference/get_the_date

Customizing Wordpress to show posts by id in Index page

I'm having problem in showing posts in my index page in wordpress the title and contents doesnt show. Currently i'm modifying the index.php of twenty-twelve template to show the custom post by id, my goal is to show 3 posts in my index page, here's my code below:
<?php
/**
* The main template file
*
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* For example, it puts together the home page when no home.php file exists.
*
* #link http://codex.wordpress.org/Template_Hierarchy
*
* #package WordPress
* #subpackage Twenty_Twelve
* #since Twenty Twelve 1.0
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<br><br>
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php twentytwelve_content_nav( 'nav-below' ); ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<?php if ( current_user_can( 'edit_posts' ) ) :
// Show a different message to a logged-in user who can add posts.
?>
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'No posts to display', 'twentytwelve' ); ?></h1>
</header>
<div class="entry-content">
<p><?php printf( __( 'Ready to publish your first post? Get started here.', 'twentytwelve' ), admin_url( 'post-new.php' ) ); ?></p>
</div><!-- .entry-content -->
<?php else :
// Show the default message to everyone else.
?>
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentytwelve' ); ?></h1>
</header>
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
<?php endif; // end current_user_can() check ?>
</article><!-- #post-0 -->
<?php endif; // end have_posts() check ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
The code above is the default index.php of twenty-twelve template in wordpress. I replaced this code from:
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php twentytwelve_content_nav( 'nav-below' ); ?>
To this, because i want to show only post 23 by id.
<?php $the_query = new WP_Query( 'page_id=23' ) ?>
<?php while ( $the_query->have_posts() ) : ?>
<?php $the_query->the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
So the whole code for my new index.php is:
<?php
/**
* The main template file
*
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* For example, it puts together the home page when no home.php file exists.
*
* #link http://codex.wordpress.org/Template_Hierarchy
*
* #package WordPress
* #subpackage Twenty_Twelve
* #since Twenty Twelve 1.0
*/
get_header();
?>
<div id="primary" class="site-content">
<div id="content" role="main">
<br><br>
<?php if (have_posts()) : ?>
<?php $the_query = new WP_Query('page_id=23') ?>
<?php while ($the_query->have_posts()) : ?>
<?php $the_query->the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<?php
if (current_user_can('edit_posts')) :
// Show a different message to a logged-in user who can add posts.
?>
<header class="entry-header">
<h1 class="entry-title"><?php _e('No posts to display', 'twentytwelve'); ?></h1>
</header>
<div class="entry-content">
<p><?php printf(__('Ready to publish your first post? Get started here.', 'twentytwelve'), admin_url('post-new.php')); ?></p>
</div><!-- .entry-content -->
<?php
else :
// Show the default message to everyone else.
?>
<header class="entry-header">
<h1 class="entry-title"><?php _e('Nothing Found', 'twentytwelve'); ?></h1>
</header>
<div class="entry-content">
<p><?php _e('Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve'); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
<?php endif; // end current_user_can() check ?>
</article><!-- #post-0 -->
<?php endif; // end have_posts() check ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
That's all what i have guys. Can you help me? Is there anything wrong on showing the posts? Thanks in advance guys. :)
An approach if u dont want to use Wp_query
Try this:
<div id="primary" class="site-content">
<div id="content" role="main">
<br><br>
<?php if (have_posts()) : ?>
<?php $post = get_post(23);?>
<?php echo $post->post_title; ?>
<?php echo $post->post_content; ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<?php
if (current_user_can('edit_posts')) :
// Show a different message to a logged-in user who can add posts.
?>
<header class="entry-header">
<h1 class="entry-title"><?php _e('No posts to display', 'twentytwelve'); ?></h1>
</header>
<div class="entry-content">
<p><?php printf(__('Ready to publish your first post? Get started here.', 'twentytwelve'), admin_url('post-new.php')); ?></p>
</div><!-- .entry-content -->
<?php
else :
// Show the default message to everyone else.
?>
<header class="entry-header">
<h1 class="entry-title"><?php _e('Nothing Found', 'twentytwelve'); ?></h1>
</header>
<div class="entry-content">
<p><?php _e('Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve'); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
<?php endif; // end current_user_can() check ?>
</article><!-- #post-0 -->
<?php endif; // end have_posts() check ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
You need to display post with id 23. Right?
<?php if (have_posts()) : ?>
<?php $the_query = new WP_Query('p=23') ?>
<?php while ($the_query->have_posts()) : ?>
<?php $the_query->the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
You are missing little like this :
$query = new WP_Query( 'p=7' );
ALternate you can try query_posts() for specific post in query like this:
<?php query_posts('p=23'); ?>
<?php while (have_posts()) : the_post(); ?>
<h4><?php the_title(); ?></h4>
<?php the_content(); ?>
<?php endwhile;?>
<?php get_footer(); ?>

Wordpress Page Template Not Rendering

Our blog page is supposed to look something like this: http://livedemo00.template-help.com/wordpress_33821/?page_id=174
However it ends up looking like this - completely empty!
This is despite the fact that the page theme is set correctly and the template file contains the following code:
<?php
/**
* Template Name: Blog
*/
get_header(); ?>
<div class="box clearfix color2">
<div id="content" class="three_fourth">
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('showposts=5'.'&paged='.$paged);
?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header>
<h2><?php the_title(); ?></h2>
<div class="post-meta">
<div class="fleft">Posted in: <?php the_category(', ') ?> | <time datetime="<?php the_time('Y-m-d\TH:i'); ?>"><?php the_time('F j, Y'); ?> at <?php the_time() ?></time> , by <?php the_author_posts_link() ?></div>
<div class="fright"><?php comments_popup_link('No comments', 'One comment', '% comments', 'comments-link', 'Comments are closed'); ?></div>
</div><!--.post-meta-->
</header>
<?php echo '<div class="featured-thumbnail">'; the_post_thumbnail(); echo '</div>'; ?>
<div class="post-content">
<div class="excerpt"><?php $excerpt = get_the_excerpt(); echo my_string_limit_words($excerpt,50);?>Read more</div>
</div>
</article>
<?php endwhile; ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<nav class="oldernewer">
<div class="older">
<?php next_posts_link('« Older Entries') ?>
</div><!--.older-->
<div class="newer">
<?php previous_posts_link('Newer Entries »') ?>
</div><!--.newer-->
</nav><!--.oldernewer-->
<?php endif; ?>
<?php $wp_query = null; $wp_query = $temp;?>
</div><!--#content-->
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
Unfortunately this theme doesn't have any documentation so I'm forced to find my own solution.
Actually I already faced this situation in WordPress.
Its not fault of your code. Might be WordPress Bug.
Try to change your page name once.
Like
<?php
/**
* Template Name: Blog_new
*/
?>
And login again and check if it is showing new custom page option or not.

Categories