I have made a wp menu that lists a bunch of posts.
I am able to list these posts' titles but not its content.
wp_nav_menu(array( 'menu' => 'Compatibility Matrix') );
How do i display the contents of each item (post title) ?
You can't list the post's content with the wp_nav_menu function, that is solely used to create a navigation menu with the post/page titles or custom title that you assign the menu item.
You need to use a loop to display the content. This is a very basic loop:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
You can modify it to suit your needs. Here are a couple resources to help you out:
http://codex.wordpress.org/The_Loop
http://wp.tutsplus.com/tutorials/theme-development/a-beginners-guide-to-the-wordpress-loop/
Related
I have three Posts in WordPress that each have the category Event.
I'm assuming that i use a WordPress codex to call those Posts to display when i want to.
What is happening is these Posts are all being displayed on index.php. I want to be able to use the WordPress codex and get the Posts for a certain category and display them. For example, display the posts in a pop up div.
How do i get Posts not to be displayed on the front page?
How do i get Posts of a specific category to display?
Or am i going about this the wrong way? I assume that Posts can be fetched from the database and be put in a popup div.
Here is my main inner html of my index.php
<div id="main">
<div id="nav">
<?php
if(!isset($_GET['page_id'])) {
wp_nav_menu( array( 'theme_location' => 'main-menu'));
}
?>
</div>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
the_content();
endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
</div>
I want it to fetch the current Page content and not the Posts.
<?php
if(!is_home() || !is_front_page) { // dont display on home page
if ( have_posts() ) : while ( have_posts() ) : the_post();
the_content();
endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif;
}
?>
look here for more conditional tags template tags
and to get posts from a particular category you can pass args in wp_query look here category args
I'd like my homepage to display my latest posts which are portfolio projects of mine. Beneath these project thumbnails I've got my static content which I'm using the Repeater add-on from Advanced Custom Fields to grab. I cant get it all to work on the same page... either get the blog to work or the ACF stuff to work. Never both because one needs to be a designated static page and one needs to be a posts page. I don't understand how to tie it together and make it appear as one page.
I've experimented with the settings in the reading panel..
I've tried using front-page.php
I've read up on the WP hierarchy etc
I've tried using templates...
I've tried wp_reset_postdata(); which I read about elsewhere on Stack Overflow.
What settings must I use in the reading panel. Do I need to use a template file?
Here's the code I'm working with, I've split the code between templates and different files already, but just for ease of reading its all together here (maybe that's the right way to do it anyway, I wouldn't know..)
<!-- The posts/portfolio items -->
<?php get_header(); ?>
<div>
<?php if(have_posts()) : ?>
<ul>
<?php while ( have_posts() ) : the_post(); ?>
<li>
<!-- Permalink,title and post thumbnail here (omitted) -->
</li>
<?php endwhile; ?>
</ul>
<?php else: ?>
<h2>No Posts found</h2>
<?php endif; ?>
</div>
<!-- Now for the ACF Stuff -->
<?php if(get_field('care_list')): ?>
<?php while(has_sub_field('care_list')): ?>
<div class="grid_2 what-i-care-about gap">
<div class="important-img-container">
<?php the_sub_field('care_list_image'); ?>
</div>
<h3><?php the_sub_field('care_list_title'); ?></h3>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php get_footer(); ?>
Please help a frustrated learner! Thanks in advance.
It looks like you're going to need to add the post id of your 'home page' (the one with the ACF repeater on it) to the get_field() function like so:
<?php $post_id = **post_id_of_your_homepage_here**; ?>
<?php if(get_field('care_list', $post_id)): ?>
<?php while(has_sub_field('care_list')): ?>
<div class="grid_2 what-i-care-about gap">
<div class="important-img-container">
<?php the_sub_field('care_list_image'); ?>
</div>
<h3><?php the_sub_field('care_list_title'); ?></h3>
</div>
<?php endwhile; ?>
This is because the $post_id parameter defaults to the current post being brought up by wordpress, which means ACF is looking for the repeater on the last Portfolio item/post you are displaying. If you set the $post_id parameter to the ID of your homepage, ACF will instead look for the repeater on that page.
Source: http://www.advancedcustomfields.com/resources/functions/get_field/#parameters
If I'm understanding correctly, you have a bunch of posts and you want to display a list of them with title and post thumbnail on your homepage, and then display a custom field you've assigned to the homepage underneath the list of posts?
Step 1: Create a new page template by copying page.php, changing the name to homepage.php and adding this to the top:
<?php
/*
Template Name: Homepage
*/ ?>
Step 2: Crete a Wordpress page called "Homepage" and in the attributes module in the right sidebar of the page creation tool, select "Homepage" as your page template.
Step 3: In your reading settings, change the front page from posts page to "Homepage." Now your homepage is your page called "Homepage."
Step 4: Make something like this the full code on your new page template homepage.php. It will output your posts list followed by your page custom field:
<?php get_header(); ?>
<?php $the_query = new WP_Query( $args );
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_post_thumbnail(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php if(get_field('repeater_field_name')): ?>
<?php while(has_sub_field('repeater_field_name')): ?>
<?php the_sub_field('sub_field_1'); ?>
<?php endwhile; ?>
<?php endif; ?>
<?php get_footer(); ?>
I have a wordpress plugin (broadstreet) which is a company directory and has list of companies. But I want to display in different style to match the rest of the website. Now all the company details are stored in the plugin. Is it possible for me to read the data stored in the plugin and display in a page and publish the same using wordpress? If so how?
Any help is greatly appreciated. Thanks
Yes you can, In this case, what I do is create a custom template page. For that you can go to theme you are refering and make a copy of page.php file and rename it. let's say it is directory-page.php.
Next go to admini panel and create a new menu item and set it is template to derectory-page.
Now you can open it and customise as you expect it.
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php //get_template_part( 'content', 'page' ); ?>
<?php// comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
If you want to remove the blog content and call your directry displaying method.
simply, comment out
<?php //get_template_part( 'content', 'page' ); ?>
<?php// comments_template( '', true ); ?>
<?php echo call_directory_display();?>
Now you have to implement call_directory_display() method in your plugin to show content in derectory-page.
If you have any questions ask in comments.
Could we hide our full content in wordpress single page ?
Normally; i want to some text for all users instead of full posts on my single.php
Like;
If you read full post Please write your opinion :)
If user commented a post i want to display full posts to commenter is that possible or not ?
any help thanks
Simple Single.php
<?php get_header();?>
<?php the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php comments_template(); ?>
<?php get_footer();?>
How can I display only the thumbnail and title of a post in WordPress like here: http://themes.premiumpixels.com/?theme=artiste
P.S. I'm not advertising anything, I just posted a question because I have no idea how to do something like that.
// From your loop just remove the_content() or the_excerpt() call
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- do stuff ... -->
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
}
post_title();// to display the post title
<?php endwhile; ?>
<?php endif; ?>
You need to do this for the image:
http://www.wpbeginner.com/wp-themes/how-to-add-post-thumbnails-in-wordpress/
And you need to do this for the little text:
Add this in function.php:
add_post_type_support( 'page', 'excerpt' );
then add this below your post_thumbnail in your template as the link demonstrate you:
<?php the_exceprt(); ?>