Link Genres in Advanced Custom Fields - php

I am using Advanced Custom Fields. I want to link the values (eg. thriller, suspense, etc.) of Genre custom field so that when the user clicks on one of the values they will get a filtered list of posts. For eg. when they click Thriller they will get all the posts in the Thriller category.
My code so far for the ACF is as follows:
<!-- Entry Content Start -->
<article <?php post_class('entry clearfix fitvids'); ?>>
<div class="inner-post">
<div class="cover">
<div class="post-image">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
}
?>
</div>
<div class="custom-fields">
<?php the_meta(); ?>
<div class="ad">
<img src="http://lorempixel.com/160/600" alt="">
</div>
</div>
</div>
<div class="the-content">
<?php the_content(); // This is your main post content output ?>
</div>
</div><!-- /inner-post -->
</article><!-- /entry -->
Is there a solution to this?

You should create a page with custom page template. In this template you should pull posts based on the custom field passed via $_GET parameter. For example: $movies = get_posts(array('meta_key'=>'your_custom_key', 'meta_value'=>$_GET['genre'])); Then you should generate appropriate links to access this page, which should link to our custom page including genre in our $_GET variable. For example the page's slug is movies. Then our links will have the following structure: /movies/?genre=custom_field_value.

Related

Random Testimonial in Between each Blog Post on home.php - Wordpress

I have the normal WP loop for showing blog posts on home.php. Im trying to get a random div to populate after each blog post. So it will be:
BLOG POST -> RANDOM DIV -> BLOG POST -> RANDOM DIV
and so on...I've tried to create "testimonials" post type and randomize them with WP_Query, but it still will only pull one PER PAGE. I need multiple to display, but differently below each post. I am also using ACF, so I created testimonial custom field blocks, but I still cant them to randomize display multiple items.
PHP (within loop):
<a class="row blogRoll"href="<?php the_permalink(); ?>">
<div class="blogImg col-sm-3">
<?php the_post_thumbnail(); ?>
</div>
<div class="col-md-9 blogBlack">
<h2 class="entry-title"><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
</a>
<div class="testimonial">
<?php the_field('testimonial_content1', 'option');
the_field('testimonial_author1','option'); ?>
</div>
<div class="testimonial">
<?php the_field('testimonial_content2', 'option');
the_field('testimonial_author2', 'option'); ?>
</div>
<div class="testimonial">
<?php the_field('testimonial_content3', 'option');
the_field('testimonial_author3', 'option'); ?>
</div>
</div>
JS:
var elems = $(".testimonial");
if (elems.length) {
var keep = Math.floor(Math.random() * elems.length);
for (var i = 0; i < elems.length; ++i) {
if (i !== keep) {
$(elems[i]).hide();
}
}
}
Obviously, the loop is causing me the headache, because it will pull most recent posts and I just need to pull and not DUPLICATE the testimonial divs below a blog post. Any ideas will be appreciated.
Instead of shuffling and outputing the result straight away, you could shuffled an array (pool of testimonials) and then apply the first value to a first .testimonial class for example, and a second value from the shuffled array to the second .testimonial class, ... etc.
That article might be of some help, Randomly iterate through array without pulling duplicate values. You could replace numbers by testimonials... Regards.

WordPress multiple-submenu

What's the best way to make multiply-page menu?
For example Category1 -> Article -> Full article text?
Not dropdown menu.
There's site example: http://fl.jetcode.lv/service.html
There are on page "Услуги" (Services), list with point's (Обслуживание windows, Подключение интернета, Сборка компьютеров, Чистка вирусов, ...)
When i click one of them (for example 'Обслуживание windows'('Maintenance windows')), i need to get page with points of that category like Установка Windows XP /Vista /7 /8 / W.S 2003,2008 (Installing Windows), Установка Linux (Installing Linux). And each Category have their own list of that text. So what's the best way to make that?
By steps:
1. I'm here: http://fl.jetcode.lv/index.html
2. I click on 'Обслуживание windows', and go to that page http://fl.jetcode.lv/service.html
3. Now i see a list with services on that category
4. Click on 'Полное описание', under 'Установка Windows XP /Vista /7 /8 / W.S 2003,2008'
5. And get to that page http://fl.jetcode.lv/service_inside.html
So how i can structure that's menu with WordPress ?
I've created a Posts with first categories (Category1), then i added it to Appearance->Menus, and get that list on page. Now i can manage their content in post, but it will be hard for end-user. So i trying to make list with second-category in post, and stucked. So can somebody please advice how it correctly/better to do ?
Thanks!
To put this simply,
You won't be needed to change anything to header but in category.php.
Instead of including the <section id="menu"> in the header put it on categories.php then to the usual get post contents and you are done.
The logic isn't in the menu but the flow of how you call each file/element.
This is the sample structure in category.php
<h1 class="post-title"><?php single_cat_title(); ?></h1>
<!-- Display all posts under specific Category -->
<?php while(have_posts()): the_post(); ?>
<hr />
<div id="category-post">
<!-- Display the Post Title -->
<h1><?php the_title(); ?></h1>
<!-- Display the Date & Time of Post -->
<p class="post-date">Posted on <span><?php the_time('F j, Y'); ?></span></p>
<!-- Checks if the post has Featured Image, else will load
the default thumbnail called post-thumb.jpg.
Delete ELSE CLAUSE to remove default thumbnail feature.
-->
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail( add_image_size( 'post-thumbnail'), array( 'class' => "post-thumb" ) );
}
else {
echo '<img class="post-thumb wp-post-image" src="';
echo bloginfo( 'stylesheet_directory' );
echo '/_/img/post-thumb.jpg" />';
}
?>
<!-- Display the excerpt if specified IF NOT, will display the
first 20 words in the actual content.
See functions.php for the excerpt lenght setting.
-->
<div class="category-content">
<?php the_excerpt();?>
</div>
<!-- Displays a link to the actual post -->
<a class= "category-read" href="<?php echo get_permalink() ?>">Read</a>
</div>
<?php endwhile; ?>
<!-- Displays the link for NEXT and PREVIOUS entries.
By default, only 10 posts per page can be loaded.
See [Settings > Reading] in Wordpress Panel to configure
-->
<div id='paging'>
<?php next_posts_link('« Older Entries ') ?>
|
<?php previous_posts_link(' Newer Entries »') ?>
</div>

Displaying last 3 blog posts on wordpress custom theme

I have a custom theme I am working on in wordpress, and I want to display the last 3 blog posts made onto my home page. I also want to style certain information regarding each post differently, like have the month and year be a certain font, and the day be much bolder and different font as well, along with displaying like a sentence or less of the article, followed by a "..." and "read more" type of thing.
How do I pull data from the blog? I know there are certain wordpress functions that can get me this data but I haven't been able to quite figure out how to do it, I'm not really well versed in the wordpress php functions. Right now I just have it hard coded but it's annoying to have to retype everything when I make a new post. I know you can set to show however many blog posts on the settings->reading but I want to be able to fully customize how it looks.
Let me know any suggestions on how I should go about doing this!
<div class="bottom">
<div class="wrap-2">
<h2>Blog</h2>
<div class="content-div">
<div class="bottom_box">
<div class="btm-img"><h4>April <span>25</span><br />2014</h4></div>
<div class="right_block">
<p class="highlight2">blog title 1</p>
<p class="highlight3">lksj sldkf jsl lsdkfj sdklf sd</p>
Read More >
</div>
</div>
<div class="bottom_box">
<div class="btm-img"><h4>April <span>24</span><br />2014</h4></div>
<div class="right_block">
<p class="highlight2">blog title 2</p>
<p class="highlight3">lsdkjf lsdk fjsl dkkddk lsdkfjpaskldfj;</p>
Read More >
</div>
</div>
<div class="bottom_box">
<div class="btm-img"><h4>April <span>23</span><br />2014</h4></div>
<div class="right_block">
<p class="highlight2">blog title 3</p>
<p class="highlight3">lksdjf slkdfjsldkfj;as dfklsd;j fsld;kfj</p>
Read More >
</div>
</div>
</div>
</div>
</div>
Try the snippet below. Use your custom HTML block (the one with botom_box class) instead of this used below.
<?php $posts = get_posts("numberposts=3"); ?>
<?php if($posts) : ?>
<?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
<!-- your HTML block goes here --->
<div class="post">
<h3><a href="<?php echo get_permalink($post->ID); ?>" ><?php echo $post->post_title; ?></a></h3>
<?php the_excerpt(); ?>" rel="bookmark">read more</a>
</div>
<!-- end of the HTML block -->
<?php endforeach; ?>
<?php endif; ?>

Why does a wordpress know to use a specific template and how do I customize this?

Hello and thanks for reading. I am a .NET developer and don't know PHP (Although I am working on learning on the job) and what I am working on was made my consultants that we dont have contact with anymore. When a news post is clicked it appears to display using a template single.php. Followed is the code for this page:
<div id="marketBanner">
<div id="banner">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/services-banner.jpg" alt="" />
</div>
<div id="breadcrumbWrap">
<div id="breadcrumbs">
<?php
if(function_exists('bcn_display'))
{
bcn_display();
}
?>
</div>
</div>
</div>
<div id="content">
<div class="left">
<h2><?php the_title(); ?></h2><br />
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="the_details">
Posted: <?php the_date(); ?> | View All News
</div>
<?php the_content(''); ?>
<?php endwhile; endif; ?>
</div>
Why does this page get used when a post is chosen? I want only a certain category of post to use this page and another category of post to use a different template. How do I achieve this?
You need to study the Wordpress Template Hierarchy # https://codex.wordpress.org/Template_Hierarchy#Single_Post_display
A template (PHP file) is looked for in this order (only on wordpress).
1 - single-{post_type}.php - If the post type were product, WordPress would look for single-
2 - product.php
3 - single.php
4 - index.php
In your case I would use single.php to create a template for the average post then specifically create a template for the one you want different using single-'post_type'.php
You can change the post type when creating a post.
Take a look at the Wordpress Template Hierarchy. It explains which templates get used and will probably be super helpful if you're just starting out with WP. You can use WP syntax to create category pages - but at the archive level - not the single post level.
To create separate pages based on post categories see here and below:
<?php
$post = $wp_query->post;
if (in_category(9)) {
include (TEMPLATEPATH.'/single-specific9.php');
return;
}
if (in_category(8)) {
include (TEMPLATEPATH.'/single-specific8.php');
return;
}
if (in_category(11)) {
include (TEMPLATEPATH.'/single-specific11.php');
return;
}

Drupal - Views - Taxonomy Term ID - custom template - anchors

Quick version: How do I output a taxonomy term ID in a views template? I just want the numeric ID value. This will be used as a link anchor.
Long version:
Scenario, I have a view which displays a list of taxonomy terms. That view has a Page and a Block. The Page view is set to display the Block view as a header. That Block view simply contains the taxonomy names. The Page view displays all of the taxonomy content.
I want the Block view list to anchor to the items in the Page view:
This view is already built, the missing part of the equation is getting the anchor links in place.
The view currently comprises 3 custom template files:
views-view-fields--categories--page.tpl.php
<article id="NEED THE TERM ID HERE">
<header>
<h2 class="flag-heading"><?php print $fields['name']->content; ?> <span>in association with <?php print $fields['field_sponsor']->content; ?> </span></h2>
</header>
<div class="table">
<div class="table-cell">
<?php print $fields['field_category_image']->content; ?>
</div>
<div class="table-cell">
<?php print $fields['description']->content; ?>
</div>
</div>
</article>
views-view-fields--categories--block.tpl.php
<li><?php print $fields['name']->content; ?></li>
views-view--categories--block.tpl.php
<ul>
<?php print $rows; ?>
</ul>
I've tried using a views contextual filter rewrite on the top block view links, with no luck.
All I need is the variable for the TERM ID - I've done a var dump of the available variables, I can see the TID in that list, but have no idea how to reference it in a views-view-fields template file and can find nothing online that answers this most simple of concepts.
Screenshots of the Page and Block view setup:
Finally won my argument that this jump list is completely redundant and stupid, so it'll be removed, however, I did manage to output the TID, which was fairly obvious, as these things often are...
views-view-fields--categories--block.tpl.php
<li>
<?php print $fields['name']->content; ?>
</li>
views-view-fields--categories--page.tpl.php
<article id="cat<?php print($view->result[$view->row_index]->tid); ?>">
<header>
<h2 class="flag-heading"><?php print $fields['name']->content; ?> <span>in association with <?php print $fields['field_sponsor']->content; ?> </span></h2>
</header>
<div class="table">
<div class="table-cell">
<?php print $fields['field_category_image']->content; ?>
</div>
<div class="table-cell">
<?php print $fields['description']->content; ?>
</div>
</div>
</article>
The variable is obviously in the view array, it was just a case of getting the index of the current view item.
Adding
<?php print $fields['tid']->content; ?>
should give you the TID in views-view-fields--xxx--page.tpl.php and --block.tpl.php
Make sure the fields are set to remove any default wrappers and you should be good to go.

Categories