Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

tnoguchi on "Paginated Custom Post Type Archive: 404 Error"

$
0
0

I've been getting a 404 error on a CPT archive page, and am not sure why. I can go to the page set for the custom post type archive, but the next page /mycustomposttype/page/2 gets a 404 error.

I don't think that there's anything wrong with my code and I've flushed my permalink rules and I think that the CPT is registered correctly. But my code is below. Any insights would be greatly appreciated since I can't see why the pages are not being found.

<!-- Row for main content area -->
    <div class="full-width" role="main" >

     <section id="sketchbook-wall">

       <ul id="sketchbook-container" class="large-block-grid-4">
            <?php 

            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $args = array(
              'post_type' => 'tn_cstm_sketchbook',
              'orderby' => 'menu_order',
              'order' =>  'ASC',
              'posts_per_page' => 2,
              'paged'=> $paged
              );

              $loop = new WP_Query($args);
              while($loop->have_posts()) : $loop->the_post(); ?>
              <li>
                <figure class="sketch-thumb">

                <?php
                   if(get_field('sketch')) {
                    $sketch = get_field('sketch');
                    $large_image = wp_get_attachment_image_src( $sketch, 'full' );
                    $thumbnail = wp_get_attachment_image_src( $sketch, 'large' );
                    $attachment = get_post( get_field('sketch') );
                    $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
                  }
                ?>    

                <a href="<?php echo $large_image[0]; ?>" data-id="<?php the_ID(); ?>"  class="reveal" >

                  <img src="<?php echo $thumbnail[0]; ?>" alt="<?php echo $alt; ?>" />

                </a>
                <figcaption>

                </figcaption>

                </figure>

              </li>

            <?php endwhile; ?>

          </ul>

      <nav>
        <?php
        // Bring $wp_query into the scope of the function
        global $wp_query;

        // Backup the original property value
        $backup_page_total = $wp_query->max_num_pages;

        // Copy the custom query property to the $wp_query object
        $wp_query->max_num_pages = $loop->max_num_pages;
        ?>

        <!-- now show the paging links -->
        <div class="alignleft"><?php next_posts_link('Next Entries'); ?></div>
        <div class="alignright"><?php previous_posts_link('Previous Entries'); ?></div>

        <?php
        // Finally restore the $wp_query property to it's original value
        $wp_query->max_num_pages = $backup_page_total;
        ?>
      </nav>

     </section>

     </div>  <!-- End Content -->

    <?php

        // Register Custom Post Taxonomy
         public  function create_work_taxonomies() {
                register_taxonomy(
                    'tn_cstm_sketchbook_plugin',
                    'tn_cstm_sketchbook',
                    array(
                        'labels' => array(
                            'name' => 'Sketchbook Categories',
                            'add_new_item' => 'Add New Sketchbook Category',
                            'new_item_name' => "New Sketchbook Category"
                        ),
                        'show_ui' => true,
                        'show_in_nav_menus' => true,
                        'show_admin_column' => true, //Show custom taxonomy in admin columns
                        'show_tagcloud' => false,
                        'hierarchical' => true,
                        'args' => array( 'orderby' => 'term_order' ),
                        'rewrite' => array('slug' => 'sketchbook-categories', 'with_front' => false )
                    )
                );
            }

        // Register Custom Post Type
           public function create_sketchbook_work() {
                register_post_type( 'tn_cstm_sketchbook',
                    array(
                        'labels' => array(
                            'name' => 'Sketchbook',
                            'singular_name' => 'Sketchbook Page',
                            'add_new' => 'Add New Sketchbook Page',
                            'add_new_item' => 'Add New Sketchbook Page',
                            'edit' => 'Edit Sketchbook Page',
                            'edit_item' => 'Edit Sketchbook Page',
                            'new_item' => 'New Sketchbook Page',
                            'view' => 'View Sketchbook Page',
                            'view_item' => 'View Sketchbook Pages',
                            'search_items' => 'Search Sketchbook Pages',
                            'not_found' => 'No Sketchbook Pages found',
                            'not_found_in_trash' => 'No Sketchbook Pages Found in Trash',
                            'parent' => 'Parent Sketchbook Page'
                        ),

                        'public' => true,
                        'show_in_menu' => true,
                        'menu_position' => 29,
                        'taxonomies' => array( '' ),
                        'menu_icon' => plugins_url( 'images/sketchbook-icon.png', __FILE__ ),
                        'publicly_queryable' => true,
                        'query_var' => true,
                        'rewrite' => array( 'slug' => 'sketchbook', 'with_front' => false ),
                        'has_archive' => true,
                        'hierarchical' => false,
                        'supports' => array( 'title', 'page-attributes' )
                    )
                );
            }

    ?>

AndySpeed on "Display random recent post custom field"

$
0
0

Hi,

I am looking to display, in a random order, a custom field from any one of the five most recent posts which:

1) have something in the custom field
2) fall within the specified category

What I have come up with is the following:

<?php query_posts('showposts=5&cat=129,131,318&offset=0&order=rand'); ?><?php if (have_posts()) : while (have_posts()) : the_post(); ?><?php $mykey_values = get_post_custom_values('Quote'); foreach ( $mykey_values as $key => $value ) { echo "$value"; } ?><?php endwhile; ?><?php endif; ?>

However this isn't working. The random code isn't working. Can anyone advise as to what I may be doing wrong and what can be amended to produce the desired result?

Essentially the custom field 'Quote' contains a line of text from an article. I'd like to have this code randomly select a 'Quote' custom field from any one of the five most recent articles which have this field populated. It's key that only one quote gets displayed at a time - not all five.

Thanks,

Andy

techaddict on "How to create sub category via xml rpc ?"

$
0
0

I am using ready made code found on some blog online via it i am able to post a blog post with categories and keywords on blog via xml rpc. But i am unable to create subcategory.

Is there any way to create subcategory via xml rpc ?

mrfraz on "get last comments | with pop-up link"

$
0
0

hey,

i found a code snippet for last comments on a static page:
but i use comments only with a pop-up.

<?php comments_popup_link('0 Comments', '1 Comment',
'% Comments', 'comment-link-top', 'Comments closed.'); ?>

could anyone help me to use the pop-up-link above in the code?
that would be great :-)

<?php
$comments = get_comments('status=approve&number=5');
  foreach($comments as $comment) :?>

  <?php $my_id = $comment->comment_post_ID ; $post_id_comms = get_post($my_id); $title = $post_id_comms->post_title;?> 

    Who: <?php echo($comment->comment_author);?><br />
    About: <a href="<?php echo get_permalink($my_id) ?>#comment-<?php echo $comment->comment_post_ID?>" title="on <?php echo $title ?>"><?php echo $title ?></a><br />
    What they said: <?php echo($comment->comment_content);?><br />
    When they said it: <?php echo($comment->comment_date);?><br />

  <?php endforeach;?>

mrfraz on "order get_the_tags()"

$
0
0

Hey,

it's possible to order the tags with this code?
i have two tags, but i want to show only one.

maybe the one with the most posts, or only "this tags"... or something like this? but not sort.. alphabetical

<?php

$posttags = get_the_tags();
$count=0;
if ($posttags) {
  foreach($posttags as $tag) {
    $count++;
    if (1 == $count) {
      echo $tag->name . '';
    }
  }
}
?>

thank you very much!

Luismin on "WordPress do not create more custom fields"

$
0
0

Hi guys!

My problem is that I can not create more custom fields inside my custom meta boxes.

I have this:

function add_custom_meta_box_productos() {
    add_meta_box(
        'custom_meta_box_productos', // $id
        backend_product_metabox_title, // $title
        'show_custom_meta_box_productos', // $callback
        'products', // $page
        'normal', // $context
        'high'); // $priority
}
add_action('add_meta_boxes', 'add_custom_meta_box_productos');

    // Field Array
    $prefix_productos = 'custom_';
    $custom_meta_fields_productos = array(  

array(
'label'=> 'Label 1',
'desc'  => 'Title',
'id'    => 'label1',
'type'  => 'text'
),
array(
'label'=> 'Label 2',
'desc'  => 'Title',
'id'    => 'label2',
'type'  => 'text'
),
array(
'label'=> 'Label 3',
'desc'  => 'Title',
'id'    => 'label3',
'type'  => 'text'
),
array(
'label'=> 'Label 4',
'desc'  => 'Title',
'id'    => 'label4',
'type'  => 'text'
),
);

// The Callback
function show_custom_meta_box_productos() {
global $custom_meta_fields_productos, $post;
// Use nonce for verification
echo '<input type="hidden" name="custom_meta_box_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />';  

    // Begin the field table and loop
    echo '<table class="form-table">';
    foreach ($custom_meta_fields_productos as $field_producto) {
        // get value of this field if it exists for this post
        $meta_producto = get_post_meta($post->ID, $field_producto['id'], true);
        // begin a table row with
        echo '<tr>
                <th><label for="'.$field_producto['id'].'">'.$field_producto['label'].'</label></th>
                <td>';
switch($field_producto['type']) {

// text
					case 'text':
						echo '<input type="text" name="'.$field_producto['id'].'" id="'.$field_producto['id'].'" value="'.$meta_producto.'" size="30" />
							<br /><span class="description">'.$field_producto['desc'].'</span>';
					break;
                } //end switch
        echo '</td></tr>';
    } // end foreach
    echo '</table>'; // end table
}

// Save the Data
function save_custom_meta_producto($post_id) {
    global $custom_meta_fields_productos;  

    // verify nonce
    if (!wp_verify_nonce($_POST['custom_meta_box_nonce'], basename(__FILE__)))
        return $post_id;
    // check autosave
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
        return $post_id;
    // check permissions
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id))
            return $post_id;
        } elseif (!current_user_can('edit_post', $post_id)) {
            return $post_id;
    }  

    // loop through fields and save the data
    foreach ($custom_meta_fields_producto as $field_producto) {
        $old = get_post_meta($post_id, $field_producto['id'], true);
        $new = $_POST[$field_producto['id']];
        if ($new && $new != $old) {
            update_post_meta($post_id, $field_producto['id'], $new);
        } elseif ('' == $new && $old) {
            delete_post_meta($post_id, $field_producto['id'], $old);
        }
    } // end foreach
}
add_action('save_post', 'save_custom_meta_producto');

First, I create the metabox and create an array with 4 different input text. But when I introduce information and clic in publish, they do not save nothing. The problem is that WordPress does not create the id custom field for each input text. This is a piece of code but I have more fields in this metabox and save the information properly. But, If I create new fields, these fields do not save the information. Any idea?

Thanks!

RoyBoy on "tag page"

$
0
0

Hi
my tag page isn't working with wp_query()

I decided to get the tag from the querystirng:
$tag = basename($_SERVER['REQUEST_URI']);

and then query by taxonomy:
$args = array('post_type' => 'post','tax_query' => array(array('taxonomy' => 'tag','field' => 'slug','terms' => $tag)));

Have searched the forums but can't seem to find anything

Any suggestions?

Cheers

freakable on "How to mass edit post date publish?"

$
0
0

I want to export about 1000 post to my wordpress blog. How can i mass edit them, to publish from:
2013-06-24
to
2014-06-24

I want to publish posts about 3 per day, not 1000 per. It's even possible to do?


stiwdio on "comment form"

$
0
0

Hi

I'm trying to input an initial value and clear it when clicked;

here is the code taken from the includes comment-template.php

'author' => '<p class="comment-form-author">' . '<label for="author">' . __( '' ) . ( $req ? ' <span class="required"></span>' : '' ) . '</label> ' .
		            '<input id="author" name="author" type="text" size="24" /></p>',

however if i add - onclick="this.value=''" i get the parse error below;

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting '

Any help gratefully appreciated;

wesww on "Custom admin panel based on user roles"

$
0
0

I solved my own problem which might be useful for others. Building on hacks like this (10-wordpress-dashboard-hacks) I needed to customize the admin panel. However, I needed to be able to have different admin panels based on user roles (without using any deprecated code). Here is my solution!

I added this to my functions.php in my theme:

// Want to pare down your admin panel for authors?
// Using these functions we make this possible!
//this customization is basically for authors
//START CUSTOM ADMIN PANEL CODE:
//First we remove some widgets
function adminpanel_based_on_role()
{
	if (current_user_can('publish_posts') && !current_user_can('install_plugins')){
		global$wp_meta_boxes;
  		unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
  		unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
  		unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
  		unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
  		unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
  		unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
	}
}
add_action( 'wp_dashboard_setup', 'adminpanel_based_on_role' );
//Next we remove menu items
function remove_menu_items() {
	if (current_user_can('publish_posts') && !current_user_can('install_plugins')){
		global $menu;
			$restricted = array(__('Links'), __('Comments'), __('Media'),
			__('Plugins'), __('Tools'), __('Users'));
			end ($menu);
		while (prev($menu)){
			$value = explode(' ',$menu[key($menu)][0]);
			if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){
			unset($menu[key($menu)]);}
		}
	}
}
add_action('admin_menu', 'remove_menu_items');
//END CUSTOM ADMIN PANEL CODE

dad2four on "How do I add linked custom PHP page to plugin"

$
0
0

I am attempting to build my first plugin.

I have a form that collects the infon necessary to create a post. Before I allow the post to go into the Database I need to force the user to accept my TOS.

I have a checkbox and a link. The link will go to the TOS page (my custom PHP page) and once the user accepts the TOS the user can come back to the FORM which is populated with their data and the checkbox is checked.

The user can also just check the box and submit their post.

My question is how do I wrap my TOS page so that it matches the existing website. I want my PHP page to be wrapped to use whatever theme the user has selected for their website. In addition I want to come back to the form with it wrapped in the users theme just like it was originally.

I open my form using a hook so all is good up to there.

I want to understand how to do this the right way not the cheap and easy way.

Thanks in advance for any assistance you can offer.

scrol on "Change the default state of media library"

$
0
0

If your site contains thousands of files, media library try to load All of them, but not Uploaded to this post first. This cause hanging of interface.

After long excavations of library i've find the way to change the default-view of the Media-Library from "All media items" to "Uploaded to this post". But i had to edit core library file media-view.min.js.

You can download the solution for wordpress 3.5 and 3.5.1 on this page. Don't forget to backup old file.

If there are another ways to do it, please tell me how -).

Oaksey on "Custom insert/edit link in WYSIWYG"

$
0
0

Hi All - I wonder if anyone can help with this request or possible hack?

As everyone knows, when using the WYSIWYG editor in a page or post, you can highlight and piece of text and you click the 'insert/edit link' and from there you get 2 options. A custom link, 'Enter the destination URL' and 'Title' and also you get the second option to link to an existing page or post that you have created.

Is there a way that you could insert or specify a 3rd option that can link to a FTP folder on my server where have have a series of folders in which I have put a number of PDFs? Ideally I would like to see the folders and files in this folder to make linking to them much quicker and easier?

Any ideas, links to plugins or general help would be great, really appreciate it!
Oaksey

rekkette on "Basic PHP question (If Or Else)"

$
0
0

Hi! I'm trying to apply some basic styling, but I'm having a problem figuring out the proper syntax for my PHP statement.

It should more or less read

"If !is_front_page OR !is_posts_page
DO THIS
else
Do THAT
end if"

Right now it's breaking my site:

<!-- Content -->
                <?php if ( !is_front_page() && !is_posts_page() ) : ?>
                <div id="content" style="background-color:#faf2da; padding:0 20px 20px 0;">
                <?php else : ?>
				<div id="content">
				<?php endif; ?>

shazdeh on "using conditional tags before "wp" hook"

$
0
0

As the codex page explains, "wp" is the earliest hook that conditional tags can work. I'm in a situation where i need to run these on 'plugins_loaded' hook and so these functions don't work anymore. Is there any way to force WP to build the query on that hook?


huynguoidacbiet on "how to put in if clause ?"

$
0
0

i use this code to echo thumbnail for first post in loop.

[ Moderator Note: Code backticks fixed. ]

<?php $count = 0; $loop_baihoccuocsong1 = new WP_Query('cat=3&showposts=1'); // Them category 2
while($loop_baihoccuocsong1->have_posts()) : $loop_baihoccuocsong1->the_post(); ?>

    <a>" rel="bookmark" title="<?php the_title_attribute(); ?>">
        <?php
            if($counter==0)
                {
                echo '<img src="<?php echo get_post_meta($post->ID, "thumbnail", true);?>;$counter++;"/>' ;
                }
        ?>
    </a>

    <div class="h_bai-hoc-cuoc-song-1">
        <a>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
        <?php the_content(); ?>
    </div>

<?php endwhile; ?>
<?php wp_reset_postdata(); // Reset the query ?>

There are any error in if clause.
Browser cannot echo url thumbnail.
Please help me fix it.
Thank you !

Tinwetari on "Mobile: horizontal swiping for category queries"

$
0
0

Hi everyone,

Knowledge background: I'm well versed in HTML/CSS, and quickly growing proficient in PHP within the past year. I've been working with Wordpress for a year now.

Problem: I have a page that queries posts from a specific category. This page will only be used as a web view in the mobile app we are creating. This page displays our magazine archive, where each post in the category is a published issue.

Example:
Post 1: January 2013 issue
Post 2: February 2013 issue
Post 3: March 2013 issue

Instead of listing them in a standard vertical list, I want only one magazine issue to appear on the screen at a time until the user decides to swipe sideways.

Is there coding out there that can help me create these swiping capabilities? I want to avoid installing another plugin.

groncali on "appointment booking plugin with a credit system"

$
0
0

Hi Matt,

you could use Bookeo online bookings (http://www.bookeo.com), where you can assign credits from the back end, that can be redeemed against online bookings.

We do have a wordpress plugin.

Feel free to visit our website or send us an email at help@bookeo.com if you have any question.

Giovanna Roncali
Bookeo online bookings

sammies on "custom static front page with posts"

$
0
0

Hi all I really need some help here. Can anybody direct me in the right direction?
I would be really grateful the problem I am having is the following;

I have a static front page on which I would like to have one area where I just have two columns with specific posts which is working.For this to work I have made a template with the code but the problem is that it will not post on the page but just below with other posts which are normally visible on the front page. How can this be avoided? I have been offered the solution to delete the code in page.php but then I lose the posts which normally would be filling the page so that is not really an option.

So to be clear I would like to have the following set up for my page:

Header - slider - custom posts - posts .

Many thanks in advance

<? /* Template Name: news */ ?>
    <?php
    /**
 * Template for news on the front page
 */

get_header(); ?>

    <?php
    /* Run the loop to output the pages.
     * If you want to overload this in a child theme then include a file
     * called loop-page.php and that will be used instead.
    */
    the_post();
    get_template_part( 'loop', 'page' );
   ?>
<div style="float:left;width:50%;">
<div style="padding-right:5px;">
LEFT CONTENT HERE

<?php
global $more;
$more = 0;
query_posts('cat=58&posts_per_page=1');
if(have_posts()) :
while(have_posts()) :the_post();
?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title();?></a></h2>
<div><?php the_excerpt(); ?></div>
<?php
endwhile;
endif;
wp_reset_query();?>
</div></div>
<div style="float:right;width:50%;">
<div style="padding-left:5px;">
LEFT CONTENT HERE

lonchbox on "wp_nav_menu exclude post or page by ID"

$
0
0

Hi,

I know there is any mention to exclude parameter for wp_nav_menu in the codex, but also found some posts saying this is posible, I try many of it and don´t work.

In my case I´m creating a custom widget for my theme, and this widget shows custom menu, what I want is if is in a page which are listed in the menu the item of this page was remove form the menu, so first I get the ID and I use this variable in the exclude.

<?php
			global $wp_query;
			$page_id = $wp_query->post->ID;
		?>
		<!--BEGIN #joinn-us-->
			<aside id="related-content" class="widget panel">
				<h4 class="widget-title"><?php _e('Related Content','udla'); ?></h4>

				<?php wp_nav_menu( array(
					'theme_location'=> 'related-menu',
					'menu_class'	=> 'side-nav',
					'container'		=> '',
					'container_class'	=> '',
					'exclude' => $page_id
				) ); ?>
			</aside>
		<!--END #join-us-->

Should I use the fallback_cb parameter?
Or do I need to set a function to use this parameter?

Thanx for any help.

Viewing all 8245 articles
Browse latest View live




Latest Images