I've inherited a project structure that uses front-page.php to render the home page. Most of the site uses the Wordpress content field, but we've switched to building new features with Advanced Custom Fields. the_content() is used throughout the codebase to render content, and I'm wondering if there is a way to include ACF layouts in the_content().
An example workaround I've had to use for the homepage is below, if I don't call the layout in this way content won't render on the page. I'm new to ACF, so if what I'm describing is a fundamental misunderstanding of how to bring ACF into an ecosystem I'd appreciate any guidance on better file structures and calling content.
<?php get_header(); ?>
<?php
if (is_page('Home')) {
?>
<div class="container">
<div class="row">
<?php
get_template_part('/layouts/home');
?>
</div>
</div>
<?php
} else {
the_content();
}
?>
<?php get_footer(); ?>
You can use ACF in addition to the original "the_content()" or "get_the_content()" functions. That content comes from the default block or WYSIWYG editor. ACF comes from additional fields that you add to your pages or posts.
<?php get_header(); ?>
<?php
if (is_page('Home')) {
$home_acf_field = get_field('field_name_from_home_acf');//this assumes that the ACF field has been added to the home page, because I'm not using the second parameter
?>
<div class="container">
<div class="row">
<?php
get_template_part('/layouts/home');
echo $home_acf_field;//this could also be placed in "layouts/home"
?>
</div>
</div>
<?php
} else {
$acf_field_from_page = get_field('field_name_from_page_acf');
the_content();
echo '<div>'.$acf_field_from_page.'</div>';//an example of where this can go
}
?>
<?php get_footer(); ?>
You can incorporate ACF in the template part, or in the page itself. You need to have the ACF field set up in the CMS to be on home or wherever, but then it's as simple as what I showed you to pull it in (my examples were assuming text fields).
You aren't asking this question, but if you are using "front-page.php" as your home page, then why do you need the if statements to show content? You can use "the_content()" in addition to your ACF fields, especially if it's the content editor from the home page. Or, you can just hide it (it's an ACF setting).
Note: I wrote this from memory, and didn't test anything, so please excuse any potential typo. :)
Related
I'm trying to create my first theme on wordpress by zero.
I add Disqus plugin to manage the comments for the post.
which is the standard function to call the plugin in post page?
my current post page looks like this:
<?php
get_header('post');
//get_template_part( 'single-post-content' );
?>
<div id="slide1">
<div class="article_content">
<h2 style="margin-bottom: 50px;"><?php the_title(); ?></h2>
<div class="content">
<?php the_post(); the_content(); ?>
</div>
</div>
</div>
<?php get_template_part('post_footer'); ?>
I'd like to display the comments box under each post
how would you do it starting by zero?
You don't need to call the plugin's function.
To display the comments, you should call the comments_template function in your template and add a comments.php in your theme folder.
In the comments.php, you should call comment_form to display the default WordPress form.
And after you activate the Disqus plugin, the plugin will replace the default WP comment form by some actions and filters.
You can refer to the default WordPress theme to know how to display the comments.
The code is in twentysixteen/single.php and twentysixteen/comments.php
update
If the plugin(Disqus WordPress) doesn't work well, you could manually install Discuz on your theme. Please refer to https://help.disqus.com/customer/en/portal/articles/1183281-manually-install-disqus-on-wordpress
I have started to learn how to make custom themes for wordpress and have problems when installing plugins that have shortcodes. I try to add a shortcode ( usually a form plugin, i have tried two different ones and also an ecwid shopping cart yet no shortcodes have worked, yes the plugins were activated) by creating a page and using the visual/html editor. When i check the page it does not show anything. here is my single.php..
<?php get_header(); ?>
<body>
<div id="maintopwrapper">
<div class="container" id="topwrapper">
<div class="row">
<div class="span8">
<?php while (have_posts()) : the_post(); ?>
<!-- Content Here -->
<div class="row"><div class="span8 greygrad round">
<div class="padding"><div class="content" style="margin-top:25px;"><?php the_content(); ?></div></div></div></div>
<div class="row margintop"><div class="span8 greygrad round">
<div class="padding">
<?php comments_template() ?>
</div></div></div>
<?php endwhile;?>
</div>
<?php get_sidebar(); ?>
</div>
</div>
</div> <!-- end of maintop wrapper-->
<?php get_footer(); ?>
It should show since the_content() is there right? Let me know if you need anything else for me to share. Plugins I tried a gravityforms, ecwid shopping cart, and quforms..all of which the shortcodes do not work. The only way I got one of them to work is by creating a custom page theme and adding hardcoded php to call the function but I rather have shortcodes working so the theme is usuable by people who dont code.
For live example: http://modernlogic.co/wp
the "contact" page in menu is actually hardcoded in the custom theme which is not using the shortcodes like I want in the "sample page" in menu
Thanks in advance
I am a idiot... I realized that I had no page.php and so when I tried adding the shortcode to a page it referred to the index.php instead of page.php(since there was none) and so it only showed the excerpt and not the content. I figured this out because I tried adding the shortcode to a post and so when it went to single.php, the shortcode worked since it has content and not just excerpt. oh well I guess trial and error.. Thanks for trying to help me anyway
For a client site that I am working on, the client wants to be able to associate certain custom post types to a given page. my supervisor has pointed me to the website of a previous client that did something similar. They used the Post Page Associator plugin (which seems to have been removed from the plugins list).
Here is a link to the plugin I am using: http://www.mediafire.com/?2dpbxac73rsn8l6
I've tried my best to modify the code inside the plugin to handle the custom post types I wanted to use (which the changes are included in the download). The main conflict comes from this piece of code (from the previous client's page.php file)
<?php
$sidebar = new WP_Query( $args ); //queries for posts
$sidebar = wp_plugin_post_page_associator::get_associated_posts ($post->ID); //looks for associated posts via the plugin, the main offending line of code
if ($sidebar!="") : while ( $sidebar->have_posts() ) : $sidebar->the_post();
?>
<div id="sidebar-content"> <!-- sidebar area -->
<h1 class="blue-text"><?php the_title(); ?></h1> <!-- the title of the associated post -->
<div class="divider"></div>
<?php the_content(); ?> <!-- the content of the associated post-->
<br/><br/>
</div>
<?php endwhile; else:?>
<br/><br/>
<?php endif; ?>
I was wondering if there was a way to determine what kind of post type the associated content is so I can change the WP_Query settings accordingly. If I comment out the second line of code with $sidebar, then all posts gets displayed in the sidebar. Is there a solution to this problem, or is there a better plugin for this?
I found a replacement plugin that does exactly what I need and shows me how to do it: http://www.cssigniter.com/ignite/custom-post-types-relationships/
I am using WordPress to put together a blog. I am using the Category Image(s) plugin to put an image for each category above the posts.
The main page is laid out as a big image and excerpt for each article and when you click on it, it takes you to the full article (I am using the 'Special Recent Posts' plugin for this). I want category image headers above each big image/excerpt.
Everything works fine for the first article but after that I get no headers. The reason is because the code I have in my header is calling the 'Category Image(s)' php function, which works. Then it calls the 'Special Recent Posts' php function which in effect runs the loop to grab the first five most recent articles. It doesn't run the category images function every time for every article, only the first time.
Here's the code:
<?php get_header(); ?>
<?php c2c_the_category_image($image_extensions='png gif jpg', $image_dir='/wp-content/images/', $use_name_if_no_image=true, $start_from='begin', $limit=999); ?>
<?php echo do_shortcode("[srp srp_number_post_option='5' srp_thumbnail_option='yes' srp_widget_title_hide_option='yes' srp_post_date_option='no' srp_wdg_excerpt_length='50' srp_wdg_excerpt_length_mode='fullexcerpt']"); ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
How can I get it to run the category images function for all the recent posts? Thanks for the help.
EDIT:
I attempting to go into the PHP of the Special Recent Posts plugin but when I attempted to enter the category images code in, it created some critical errors. I'm looking for the easiest solution if it's out there (I know this isn't a very simple question to start with). Any help? (I've placed a bounty)
Your way of doing things is extremely complicated and convoluted.
The simplest way that is proved to work is by having images that correspond with either category ID or category slug!
http://baldino.rs/collection
As you can see, this is a page that lists all the categories with their images and descriptions.
I'm having little trouble understading if you want:
To have a category image above every post
To have a category image AND post image above every post
I'll demonstrate the first solution below
Here is the order in which we will create the blog page:
Name the category images either by slug, or by ID (i recommend ID)
Upload the images to the server - prefferably to the images folder of the theme
Create our custom loop which will display our category image, category name, post title and excerpt
So the index page (blog page) should look something like this
<?php get_header();?>
<div id=:content">
<div id="posts">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<?php
$category = get_the_category();?>
<img src="<?php bloginfo('template_directory'); ?>/images/<?php echo $category[0]->term_id;?>.jpg"/>
<h3 class="cat-title"><?php echo $category[0]->cat_name;?></h3>
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_content(); ?>
</div>
</div>
<?php endwhile;endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
You should really avoid plugins for the simple stuff that is easily solved by the loop
I recommend that you start reading the WP codex - http://codex.wordpress.org
Every function, class, reference is documented in detail and it's very easy to understand.
If you have more questions, do not hesitate to ask
Im trying to make an archive page in wordpress that works. Im trying to have the archive page show all posts in a list, but i dont want a list that is 100 list items long. So im trying to figure out how to get it to make a second, third, fourth, etc... page after about 20 to 30 list items on one page.
I dont mind using the wp-paginate plug in, but im still not sure how to get that to work with wp_get_archives()
I dont think it matters, but i will have a search bar on the page and its through google custom search. So i didnt supply it, as i dont think it contributes to the actual issue.
Any help would be greatly appreciated!
<?php
/*
Template Name: Archives
*/
get_header(); ?>
<div id="main">
<div id="posts">
<?php the_post(); ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<ul>
<?php wp_get_archives( 'type=postbypost' ); ?>
</ul>
<?php wp_link_pages(); ?>
<?php rewind_posts(); ?>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
For pagination, I always use Eric Martin's emm_paginate function.
http://www.ericmmartin.com/pagination-function-for-wordpress/
In regards to your archive page, why not just use Wordpress's built in Archive page.
http://codex.wordpress.org/Creating_an_Archive_Index
With those two links, you should be able to build an Archive page that has the pagination you desire.