I am attempting to utilize a plugin that uses ajax to help "ajaxify" a wordpress theme. The plugin works great on almost all the pages.
The way it works is that it replaces the content from within a container div that you specify. In my instance it was "#newwrap". That does it's job, the only issue is that on reload the javascript/jquery functions from within the content has to be called again.
Within the plugin there is a place where you can indicate what to reload. I have gotten most of the other parts to work correctly, this one is the one that is stumping me though.
I have a page in the theme that utilizes filters with php. When I click on that specific page the page looks like it renders in css etc except nothing shows and the filters do not work. I look at the html behind it with firebug and the content is there just not being displayed.
Here is the link to the site: http://nex.vyralmedia.com
Once there please click on portfolio > image portfolios
If you click on that page it will load and just show the filters, but they wont work and the content will not display. If you refresh that page you will see what it is supposed to look like without using ajax.
Here is the link to the wordpress plugin: http://wordpress.org/extend/plugins/advanced-ajax-page-loader/
So in this case I am looking for the reload code I should use, or just some way to get that portion working properly.
Any Help would be greatly appreciated.
Here is the template page code for it:
<?php
/*
The template that is used to render pages that are targeted by the multiple portfolio behavior of Prime.
*/
get_header(); ?>
<div id="newwrap">
<?php roots_content_before(); ?>
<?php roots_main_before(); ?>
<?php
global $prime_portfolio;
$portfolio_instance = get_option(PRIME_OPTIONS_KEY);
$show_filter = false;
$page = get_queried_object();
foreach ($portfolio_instance['portfolio_instance_slider'] as $p) {
if(key_exists('portfolio_show_filters', $p) && $p['portfolio_show_filters'][0] == 'Yes' && $p['portfolio_page'] == $page->ID) {
$show_filter = true;
}
}
?>
<div class="main portfolio-main <?php if($show_filter) { echo 'show-filter'; } else { echo 'no-filter'; }?>" role="main">
<div class="subheader-wrapper">
<div class="container_12">
<div class="grid_12">
<div id="subheader">
<?php
global $post;
global $prime_frontend;
$prime_frontend->prime_title_and_subtitle();
?>
<?php if($show_filter) { ?>
<div class="table select-table">
<select class="filter">
<option data-filter="*"><?php echo get_portfolio_all_filter_text(); ?></option>
<?php
global $prime_portfolio;
$prime_portfolio->render_all_filter_list_item();
$page = get_queried_object();
$portfolio_instance = get_option(PRIME_OPTIONS_KEY);
$filters = NULL;
foreach ($portfolio_instance['portfolio_instance_slider'] as $p) {
if ($p['portfolio_page'] == $page->ID) {
$filters = isset($p['portfolio_filters']) ? $p['portfolio_filters'] : NULL;
break;
}
}
if (!empty($filters)) {
foreach ($filters as $fil) {
$f = get_term($fil, 'portfolio_filter');
?>
<option data-filter='article[data-filters*="<?php echo $f->slug; ?>"]'>
<?php echo $f->name; ?>
</option>
<?php
}
}
?>
</select>
</div>
<?php } ?>
</div>
</div>
</div>
<div class="clear"></div>
</div>
<div class="clear"></div>
<div class="content-wrapper">
<div class="overlay-divider"></div>
<?php if($show_filter) { ?>
<div class="filter-wrapper">
<div class="table">
<ul id="filters">
<?php
$prime_portfolio->render_all_filter_list_item();
$page = get_queried_object();
$portfolio_instance = get_option(PRIME_OPTIONS_KEY);
$filters = NULL;
foreach ($portfolio_instance['portfolio_instance_slider'] as $p) {
if ($p['portfolio_page'] == $page->ID) {
$filters = isset($p['portfolio_filters']) ? $p['portfolio_filters'] : NULL;
break;
}
}
if (!empty($filters)) {
foreach ($filters as $fil) {
$f = get_term($fil, 'portfolio_filter');
$prime_portfolio->render_filter_list_item($f);
}
}
?>
</ul>
</div>
<div class="overlay-divider bottom"></div>
<div class="clear"></div>
</div>
<?php } ?>
<?php
$page = get_queried_object();
$page_portfolio_properties = $prime_portfolio->get_portfolio_options($page->ID);
global $wp_query;
$temp_query = $wp_query;
$orig_query_vars = $temp_query->query_vars;
$args = $prime_portfolio->get_portfolio_item_args_for($page->ID);
$posts_per_page = -1;
if (isset($page_portfolio_properties['portfolio_posts_per_page'])) {
$posts_per_page = $page_portfolio_properties['portfolio_posts_per_page'];
$posts_per_page = empty($posts_per_page) ? -1 : intval($posts_per_page);
}
$args['posts_per_page'] = $posts_per_page;
if (!empty($orig_query_vars['paged'])) {
$args['paged'] = intval($orig_query_vars['paged']);
}
else if (!empty($orig_query_vars['page'])) {
$args['paged'] = intval($orig_query_vars['page']);
}
$wp_query = new WP_Query($args);
$paginated = $wp_query->max_num_pages > 1 ? 'paginated' : '';
?>
<div class="portfolio-wrapper">
<div class="row-fluid clearfix page-container">
<div class="span12">
<!--PAGE CONTENT-->
<div class="prime-page prime-full-width prime-portfolio <?php echo $paginated; ?>">
<div id="masonry-container">
<?php get_template_part('loop', 'portfolio'); ?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
</div>
<?php roots_main_after(); ?>
<?php roots_content_after(); ?>
</div>
opacity for your article items is set to 0 in style.css line 4293 :
article.item {
opacity: 0;
}
You should remove that rule, or modify your js code to correctly set opacity after ajax loading.
Related
I have an HTML structure that I need to dynamically output.
I am using a counter within my loop to check for the first post, and applying the class headline-big and m-grid-item for the first post. Then I'm applying the second class headline-scroll for the subsequent posts.
The problem is, the 2nd, 3rd and 4th posts are not being nested inside headline-scroll they are each getting their own div.headline-scroll which is messing up site.
I need the 2nd, 3rd and 4th posts to be nested inside a single div.headline-scroll instead of each one of them being nested under a separate one.
This is the HTML for structure
<!-- / 1ST POST -->
<div class="headline-big">
<div class="m-grid-item">
...
</div>
</div>
<!-- / END OF FIRST POST -->
<!-- / 2ND, 3RD AND 4TH POST - ALL NESTED INSIDE div.headline-scroll -->
<div class="headline-scroll">
<!-- / 2ND POST -->
<div class="m-grid-item -medium">
...
</div>
<!-- / END OF 2ND POST -->
<!-- / 3RD POST -->
<div class="m-grid-item -small">
...
</div>
<!-- / END OF 3RD POST -->
<!-- / 4TH POST -->
<div class="m-grid-item -small">
...
</div>
<!-- / END OF 4TH POST -->
</div>
And this is the PHP
if ( $featured->have_posts() ) {
$i = 0;
while ( $featured->have_posts() ) {
$featured->the_post();
if ( $i == 0 ) :
?>
<div class="headline-big">
<div class="m-grid-item">
<?php endif; ?>
<?php if ( $i != 0 ) : ?>
<div class="headline-scroll">
<div class="m-grid-item -medium">
<?php endif; ?>
<?php the_title(); ?>
</div>
</div>
<?php $i++;
}
} else {
echo 'Add some posts';
}
I'm not sure if I could be able to answer your question well. But this is how I understand. If there is a question, please let me know and I will modify.
if ( $featured->have_posts() ) {
$i = 1;
while ( $featured->have_posts() )
{
$featured->the_post();
if( $i == 1)
{
?>
<div class="headline-big">
<div class="m-grid-item">
<?php the_title(); ?>
</div>
</div>
<div class="headline-scroll">
<?php
}
else
{
$small = array(3,4); //list of small classes
$class = ( in_array($i, $small)) ? '-small' : '-medium';
<div class="m-grid-item <?php echo $class; ?>">
<?php the_title(); ?>
</div>
<?php
}
$i++;
}
echo '</div><!-- end of headline-scroll -->';
} else {
echo 'Add some posts';
}
I've simplified it here with if conditions.
If it's the first post, create the headline-big div.
If it's the second post, create the headline-scroll div and the medium class div.
For all subsequent posts, just use the small div. Finally, outside the while loop, if we had more than 1 post, we need to add a closing div to close off the headline scroll.
if ( $featured->have_posts() ) {
$i = 0;
while ( $featured->have_posts() )
{
$featured->the_post();
if( $i == 0)
{
?>
<div class="headline-big">
<div class="m-grid-item">
<?php the_title(); ?>
</div>
</div>
<?php
}
else if($i == 1)
{
?>
<div class="headline-scroll">
<div class="m-grid-item -medium">
<?php the_title(); ?>
</div>
<?php
}
else
{
<div class="m-grid-item -small">
<?php the_title(); ?>
</div>
}
$i++;
}
if($i > 1){
?>
</div><!-- end of headline-scroll -->
<?php
}
} else {
echo 'Add some posts';
}
You never closed many of your DIV tags, and you were opening your div.headline-scroll inside a loop, so you were bound to get more than one. Try this instead maybe? Consistent indent and minimal PHP in your HTML will make things easier to debug, though you're hamstrung by Wordpress' awful functions.
<?php if (!$featured->have_posts()):?>
<p>Add some posts!</p>
<?php else: $i = 0; while ($featured->have_posts()): $featured->the_post();?>
<?php if (!$i):?>
<div class="headline-big">
<div class="m-grid-item">
<?php the_title(); ?>
</div>
</div>
<div class="headline-scroll">
<?php else:?>
<div class="m-grid-item -medium">
<?php endif; ?>
<?php the_title(); ?>
</div>
<?php $i++; endwhile;?>
</div>
<?php endif?>
I need to edit this code in a Joomla template so that it shows the page heading (id="jf_page_heading") only when I'm in category blog view and hide it when I'm inside the article.
<?php
$menu = JFactory::getApplication()->getMenu();
$active = $menu->getActive();
if (is_object($active)) {
$pageHeading = $active->params->get('page_heading');
$show_pageHeading = $active->params->get('show_page_heading');
// CALL
if($pageHeading != ''){ // or - if($pageHeading != '' && $show_pageHeading){
?>
<div id="jf_page_heading">
<div class="rt-container">
<div class="rt-block">
<h1><?php echo $pageHeading; ?></h1>
<?php echo $gantry->displayModules('jf-page-heading','basic','basic'); ?>
<div class="clear"></div>
</div>
</div>
</div>
<?php } } ?>
How should I edit it?
To show page heading in category blog view, you don't need to edit the code. Rather you can simply enable the show page heading parameter in your category blog menu. For hiding the page heading in article view, you need create a override for it in your template folder.
Article path: site/templates/html/com_content/article/default.php
Comment the page heading html section you want to hide.
Alternative way, if you want to do it through code as you are using gantry template in category blog view if the code is not present -
You should not check $pageheading in if condition but check the show_pageHeading variable.
Category-blog path: site/templates/html/com_content/category/blog.php
<?php $menu = JFactory::getApplication()->getMenu();
$active = $menu->getActive();
if (is_object($active)) {
$pageHeading = $active->params->get('page_heading');
$show_pageHeading = $active->params->get('show_page_heading'); // returns 1 or 0 if set to Yes or no in menu item
// check if showpageheading is set in menu item
if($show_pageHeading){ ?>
<div id="jf_page_heading">
<div class="rt-container">
<div class="rt-block">
<h1><?php echo $pageHeading; ?></h1>
<?php echo $gantry->displayModules('jf-page-heading','basic','basic'); ?>
<div class="clear"></div>
</div>
</div>
</div>
<?php } } ?>
Follow point(1) for hiding page-heading in article view.
Hope this helps.
Try something like
$input = JFactory::getApplication()->input;
if (
$input->getCmd('option') == 'com_content' &&
$input->getCmd('layout') == 'blog' &&
$input->getCmd('view') == 'category'
) {
// Show title
}
I am using Advanced custom fields extension in my wordpress project. to show some custom content on a specific page, I have about 20 custom field in one page and i called them in theme file by like this way..
<?php if(get_field('name1') != ""): ?>
<div class="row-hardware">
<div class="partner-left"><img src="<? the_field('image1'); ?>" /></div>
<div class="partner-right">
<?php the_field('description1'); ?>
</div>
</div>
<?php endif; ?>
<?php if(get_field('name2') != ""): ?>
<div class="row-hardware">
<div class="partner-left"><img src="<? the_field('images2'); ?>" /></div>
<div class="partner-right">
<?php the_field('description2'); ?>
</div>
</div>
<?php endif; ?>
I called them for every single field, I saw in Advanced Custom fields it has drag and drop sorting area in admin area, but How can i call them as like sorting on theme file frontend.
is there any good solution ?
here i have attached images
thanks
Something like this should work (Not tested)
Note the <div class="clear"></div>. Add this to CSS:
.clear {
clear: both;
}
PHP:
<?php
$fields = get_field_objects();
$i = 0;
if ($fields) {
foreach ($fields as $field_name => $field) {
if (substr($field_name, 0, 5) == 'image' || substr($field_name, 0, 11) == 'description') {
if (($i % 2) == 0) {
echo '<div class="row-hardware">';
echo '<div class="partner-left"><img src="'.$field['value'].'" /></div>';
}
else {
echo '<div class="partner-right">'.$field['value'].'</div>';
echo '<div class="clear"></div></div>';
}
$i++;
}
}
}
?>
Last but not least. It's not that dynamic, but if your number of fields change constantly you should consider to create a custom post type.
<?php for ($i = 1; $i <= 19; $i++) : ?>
<div class="row-hardware">
<div class="partner-left"><img src="<?php the_field('image'.$i); ?>" /></div>
<div class="partner-right"><?php the_field('description'.$i); ?></div>
<div class="clear"></div></div>
<?php endfor; ?>
I've searched through similar questions but to no avail, so hopefully someone can help.
I'm having an issue paginating the search results on a site I've built using the Zend Framework (1.12). I can retrieve the items and also the pagination is formed but when I click to go to the next page of pagination, all the search results are lost. The code appends ?page=2 e.t.c to the URL but the code then loses the searchitems.
I read in one question about possibly using sessions or Zend_Session in particular but I'm a little lost at present! Relatively new to PHP.
Firstly here is my search form - search-form.php (XHTML)
<?php
// Search Form
?>
<div id="search">
<h4 style="margin-bottom:20px;">Search</h4>
<form name="prodSearch" action="listing-search.php" method="post">
<input type="text" name="searchitems" id="searchitems" />
<input type="submit" name="search_items" id="search_items" value="Go" />
</form>
</div>
This is included in my other pages.
listing-search.php is then as follows
<?php
require_once('admin/scripts/library.php');
require_once('admin/scripts/db_definitions.php');
try {
?>
<!-- HTML Doc Type, Head removed e.t.c -->
<div id="listing-col-main">
<div id="all-cars">
<h4>Search Results</h4>
</div>
<!-- Listings -->
<?php
$query = $_POST['searchitems'];
$min_length = 3;
if (strlen($query) >= $min_length) {
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw = searchItems($dbread, $query);
$paginator = Zend_Paginator::factory($raw);
if (isset($_GET['page'])) {
$paginator->setCurrentPageNumber($_GET['page']);
}
$paginator->setItemCountPerPage(8);
$paginator->setPageRange(3);
$count = $paginator->getTotalItemCount();
if ($count > 0) {
foreach ($paginator as $results) { // repeat all results ?>
<?php
$item_id = $results['item_id'];
$photos = getRelatedPhotos2($dbread, $item_id);
?>
<div class="product-listing">
<div class="product-listing-image">
<?php foreach ($photos as $photo) { //repeat ?>
<img src="image_upload/<?php echo $photo['filename']; ?>" width="75" alt="" />
<?php } ?>
</div>
<div class="product-listing-title">
<h4><?php echo $results['type_name']; ?> - <?php echo $results['item_make'] . ' ' . $results['item_model']; ?> </h4>
</div>
<div class="product-listing-details">
<p>YEAR: <?php echo $results['item_year']; ?> FUEL: <?php echo $results['item_fuel']; ?> TRANS: <?php echo $results['item_transmission']; ?> MILEAGE: <?php echo $results['item_mileage']; ?> </p>
</div>
<div class="product-listing-viewmore">More Info</div>
</div>
<?php } ?>
<!-- 8 products per page -->
<div id="product-listing-pagination">
<?php
$pages = $paginator->getPages('Elastic');
if (isset($pages->previous)) {
echo 'Prev';
}
foreach ($pages->pagesInRange as $page) {
if ($page != $pages->current) {
echo " <a href='" . $_SERVER['PHP_SELF'] . "?page={$page}'>$page</a>";
} else {
echo ' ' . $page;
}
}
if (isset($pages->next)) {
echo ' Next';
}
?>
</div>
<?php } else { ?>
<div id="noresults"> <?php echo "No results found for " . $query; ?> </div>
<?php }
} ?>
</div>
<div id="col-right">
<?php include("search-usedcars.php"); ?>
<!-- End of Main Search -->
<div id="latest-news">
<h3>Latest News</h3>
<?php include("latestnews.php"); ?>
</div>
</div>
<div class="clear"></div>
<div id="footer-bar"> Designed by </div>
</div>
</body>
</html>
<?php
} catch (Exception $e) {
echo $e->getMessage();
}
?>
It is because your query is passed in $_POST, when you click your nav links away you loose the data stored in $_POST and only keep what is in $_GET. Either change your search form method to $_GET and add &searchitems="'.$query.'" to both your nav links, or store the query in $_SESSION, or you can change your nav links to buttons wrapped in forms with method post and include hidden fields for searchitems and page. I would advise changing the search form method to get as it allows the bookmarking of searches and avoids complexity.
I'm having a problem with the WordPress posts loop. I'd like to break down the post loop, to add some HTML div tags in the post. For example, I'm trying to add a div .wrap around the posts after first post. As it's to wrap the posts, so it should be only once.
The problem is that the .wrap div is being repeated because of the loop. How can I break the loop, and add the .wrap div only once and then continue the loop?
Here's my code:
while ($wp_query->have_posts()) :
$wp_query->the_post();
if($wp_query->current_post <= 1){ ?>
<div class="x">
.. post 1
</div>
<?php }
if($wp_query->current_post > 1){ ?>
<div class="wrap"> <!-- should be only once -->
<div class="y">
.. post 2
</div>
<div class="y">
.. post 3
</div>
</div><!-- should be only once -->
<?php } ?>
endwhile;
Try this
<?php
while ($wp_query->have_posts()) :
$wp_query->the_post();
if($wp_query->current_post <= 1){ ?>
<div class="x">
.. post 1
</div>
<div class="wrap"> <!-- should be only once -->
<?php
$is_wrapped = 1;
}
if($wp_query->current_post > 1){ ?>
<div class="y">
.. post 2, then post 3, ...
</div>
<?php }
endwhile;?>
<?php if (!empty($is_wrapped)){ ?>
</div><!-- should be only once -->
<?php } ?>
You can just use an iterator index, like this:
$i = 0;
while (...) {
if ($i == 1) {
// actions you need to do only once
}
...
$i++
}
<div class="x">
while ($wp_query->have_posts()) :
$wp_query->the_post();
<--print post-->
if($wp_query->current_post <= 1){
</div><div class="y">
}
endwhile;
</div>
You will get an empty <div class="x" /> if there's no post and an empty <div class="y" /> if there's only one post. But may be that's feasible in your case...
edit: example
<?php
$wp_query = new WPDummy;
echo '<div class="x">';
while ($wp_query->have_posts()) :
$wp_query->the_post();
$wp_query->the_content();
if($wp_query->current_post <= 1){
echo '</div>', "\n",'<div class="y">';
}
endwhile;
echo '</div>';
// boilerplate
class WPDummy {
public $current = null;
public $current_post = 0;
public function __construct() {
$this->posts = array( array('content'=>'A'),array('content'=>'B'),array('content'=>'C'),array('content'=>'D') );
}
public function have_posts() {
return false!=current($this->posts);
}
public function the_post() {
$this->current_post+=1;
$this->current = current($this->posts);
next($this->posts);
}
public function the_content() {
echo '<span class="content">', $this->current['content'], '</span>';
}
}
prints
<div class="x"><span class="content">A</span></div>
<div class="y"><span class="content">B</span><span class="content">C</span><span class="content">D</span></div>